Thread: How do I know number of COLUMN of two-dimensional Array

1. How do I know number of COLUMN of two-dimensional Array

Why I am not getting error, when I run the below code?
Is there a way I can verify number of columns are equal in both array?

dim sArray1(0, 1)
dim sArray2(0, 0)

' First Array
sArray1(0, 0) = "India,Gujarat"
sArray1(0, 1) = "India,Gujarat22222"
' Second Array
sArray2(0, 0) = "India,Gujarat"

For i =0 to ubound(sArray1)
For j = 0 to ubound(sArray2)
If sArray1(i, j) &lt;&gt; sArray2(i, j) Then
MsgBox sArray1(i, j) & " &lt;&gt; " & sArray2(i, j), vbCritical, "NOT EQUAL"
Else
MsgBox sArray1(i, j) & " == " & sArray2(i, j), vbCritical, "EQUAL"

End If
Next
Next

2. Re: How do I know number of COLUMN of two-dimensional Array

I found the answer and I like to share.
Array(row,column)
Array1(3,4)
To find Number of row:-----&gt; ubound(Array1,1)
To find Number of Column:--&gt; ubound(Array1,2)

So in order for me to verify number of rows and columns in both arrays, I would do following.
Lets assume I have two arrays.
Array1(3,4)
Array4(2,4)

if ubound(Array1,1) &lt;&gt; ubound(Array2,1) then
msgbox("Number of rows are not equal")
end if

Lets assume I have two arrays.
Array1(3,4)
Array4(3,5)

if ubound(Array1,2) &lt;&gt; ubound(Array2,2) then
msgbox("Number of columns are not equal")
end if

Regards,
Prashant Patel

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 04:07 PM.