BASIC| How to calculate elements of 2-dimensional array

From the code:

Sub LearningArray	

    Dim MyArrayVar1(5) As String
	Dim MyArrayVar2$(5)
		t = t & "Dim MyArrayVar1(5) As String or Dim MyArrayVar2$(5) = " & (Ubound(MyArrayVar1)) - (Lbound(MyArrayVar1)) + 1 & " element(s)."  & Chr(13)
	Dim MyArrayVar3(1 To 5) As String
		t = t & "Dim MyArrayVar3(1 To 5) As String = " & (Ubound(MyArrayVar3)) - (Lbound(MyArrayVar3)) + 1 & " element(s)."  & Chr(13)
	Dim MyArrayVar4(5,5) As String
		t = t & "Dim MyArrayVar4(5,5) As String = " & "36" & " element(s)."  & Chr(13)
	Dim MyArrayVar5$(-4 To 5, -4 To 5)
		t = t & "Dim MyArrayVar5$(-4 To 5, -4 To 5) = " & "100" & " element(s)."  & Chr(13)
	Dim MyArrayVar6()
		t = t & "Dim MyArrayVar6() = " & (Ubound(MyArrayVar6)) - (Lbound(MyArrayVar6)) + 1 & " element(s)."  & Chr(13)
	MsgBox "All about array:" & Chr(13) & t

End Sub

What should be the calculation for the result “36” and “100” of those 2-dimensional arrays respectively ?

Do you mean “How to use UBound() and LBound() for multidimensial arrays?”

Try this:

   ...
    Dim MyArrayVar4(5,5) As String
    Dim iRows&, iColumns&, iSize&
    	iRows = (Ubound(MyArrayVar4, 1)) - (Lbound(MyArrayVar4, 1)) + 1
    	iColumns = (Ubound(MyArrayVar4, 2)) - (Lbound(MyArrayVar4, 2)) + 1
    	iSize = iRows * iColumns
        t = t & "Dim MyArrayVar4(5,5) As String = " & iSize & " element(s)."  & Chr(13)
    Dim MyArrayVar5$(-4 To 5, -4 To 5)
    	iRows = (Ubound(MyArrayVar5, 1)) - (Lbound(MyArrayVar5, 1)) + 1
    	iColumns = (Ubound(MyArrayVar5, 2)) - (Lbound(MyArrayVar5, 2)) + 1
    	iSize = iRows * iColumns
        t = t & "Dim MyArrayVar5$(-4 To 5, -4 To 5) = " & iSize & " element(s)."  & Chr(13)
   ...

Dear @JohnSUN,

Thank you so much.

And are there any more ways to do without using LBound() and UBound() ?

No, StarBASIC does not have other means to determine the size of the array. But they are not needed, these two functions are enough for any necessary actions

In everyday tasks, you rarely need the size of the array, usually you work with the indices of the first and last element

Dear @JohnSUN,

Noted with great thanks.