3D array help

g3jimha

Member
Joined
Jun 23, 2011
Messages
8
Programming Experience
1-3
Hi was wondering if anyone could help. ive got a jagged multi dimensional array and I was wondering if you could help me find how to work out the length of a single row of the array so;

my array is ;

cols(0) = New String() {"CSCSAccreditation", "CSCSExpiryDate", "CSCSAccreditation2", "CSCSExpiryDate2", "CSCSAccreditation3", "CSCSExpiryDate3"}
cols(1) = New String() {"A40SlingSignaller", "TeleHandler", "MEPWSPBoom1", "MEWPScissor1", "A14Forklift", "A16CounterbalanceFLT", "A60MobileCranes", "A66CompactCranes", "A02CrawlerCrane", "APCranes", "CraneSPVR", "CPCSCardExpiryDate"}
cols(2) = New String() {"A40SlingSignaller", "TeleHandler", "MEPWSPBoom1", "MEWPScissor1", "A14Forklift", "A16CounterbalanceFLT", "A60MobileCranes", "A66CompactCranes", "A02CrawlerCrane", "APCranes", "CraneSPVR", "CPCSCardExpiryDate"}
cols(3) = New String() {"CCNSGExpiryDate"}
cols(4) = New String() {"ExpiryDate"}
cols(5) = New String() {"IOSHCompletionDate"}
cols(6) = New String() {"licenceNo", "ScissorLift", "SelfPropelledBoom", "SPBExpiry", "StaticBoom", "StaticBoomExpiry"}
cols(7) = New String() {"RescueFromHeightExpires"}
cols(8) = New String() {"AbrasiveWheels", "PASMAExpires", "WorkAtHeight", "ConfineSpace", "FireSaftey", "HILTIDX", "HarnessTrainingDate"}
cols(9) = New String() {"SMSTSExpiryDate"}
cols(10) = New String() {"SSSTSExpiryDate"}

and i wish how to find the length of this;

cols(0) = New String() {"CSCSAccreditation", "CSCSExpiryDate", "CSCSAccreditation2", "CSCSExpiryDate2", "CSCSAccreditation3", "CSCSExpiryDate3"}

any help would be much appreciated.
Regards, Jim
 
First up, your title says "3D array" but there's nothing in your code to suggest that. Also, your post says "a jagged multi dimensional array" but that's not possible because they are two different things. It looks to me like you have a simple jagged array, i.e. an array of String arrays. A jagged array is just multiple 1D arrays inside another 1D array. As such, each one gets treated just ike any other 1D array.
'Get the first inner array from the outer array.
Dim innerArray = outerArray(0)

'Get the length of the inner array.
Dim length = innerArray.Length
That can be compressed into a single line:
'Get the length of the inner array.
Dim length = outerArray(0).Length
 
Thanks for the feedback I have no idea how to change the thread name so i apologize for this. I tried this, but it still returns a value of 17 for that array with 6 items in it :S.
Can you see anything out of place with this?

Dim inner = cols(intCount)(i)
Dim length = inner.Length
Dim lrd As SqlDataReader = cmd.ExecuteReader()
While lrd.Read()
For i = 0 To (length)
If ((lrd(cols(intCount)(i))) Is DBNull.Value = True) Then
CV = CV
Else
CV = CV & vbTab & (cols(intCount)(i)) & " : " & (lrd(cols(intCount)(i))) & vbCrLf
End If
Next
i = 0

when i step through it, it say the value of length at "For i = 0 To (length)" is equal to 17, dunno where its going wrong, because the final answer it outputs is all correct when it displays after all the error messages.

Regards, Jim
 
Dim inner = cols(intCount)(i)
inner variable here should according to previous information be a string value, one of the items in the array, for example "CSCSAccreditation".
If you hover the inner variable at designtime you will see compiler infers the type to "Dim inner As String", and if you put a breakpoint after the assignment you can at runtime hover the variable and see the current value.
 
ah right, thanks very much john, i didnt even think what it was doing. for future reference if anyones using this I used
"inner = cols(intcount).length"
 
Back
Top