Board index » Visual Studio » Finding the dimensions of an array
|
casperHghost
|
|
casperHghost
|
Finding the dimensions of an array
Visual Studio88
Hi, Is it possible to find out if an array has one, two, three etc dimensions ? like arrtmp(0), arrtmp(0,1), arrtmp(1,1,1) David - |
| Ken
Registered User |
Mon Jul 24 14:18:13 CDT 2006
Re:Finding the dimensions of an array
"David DB" <er_fortsatt@hotmail.com>wrote in message
QuoteHi, -- Ken Halter - MS-MVP-VB - Please keep all discussions in the groups.. DLL Hell problems? Try ComGuard - www.vbsight.com/ComGuard.htm">www.vbsight.com/ComGuard.htm In Loving Memory - www.vbsight.com/Remembrance.htm">www.vbsight.com/Remembrance.htm - |
| expvb
Registered User |
Mon Jul 24 14:22:16 CDT 2006
Re:Finding the dimensions of an array
"David DB" <er_fortsatt@hotmail.com>wrote in message
QuoteHi, pointer to a SAFEARRAY structure. Look in newsgroups for "vb SAFEARRAY dimensions" - |
| David
Registered User |
Mon Jul 24 14:30:05 CDT 2006
Re:Finding the dimensions of an array
Hi Ken,
This only says how many rows there are in an column. One of the most irritating thing about VB array is that they are in the form of y,x insted of x,y thats normal. I cannot count the number of times I have made a mistake there :-) David "Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com>wrote in message Quote"David DB" <er_fortsatt@hotmail.com>wrote in message - |
| Ralph
Registered User |
Mon Jul 24 14:50:14 CDT 2006
Re:Finding the dimensions of an array"David DB" <er_fortsatt@hotmail.com>wrote in message QuoteHi Ken, Just cycle through and capture the error when you go one too far. As for what's "normal" that is a matter of debate. VB's array's are what they are because they started out as full blown active objects. If you think about how you might create such an object "on-the-fly" you will see VB's presentation makes sense. What you are calling 'normal' comes from C where arrays were not true objects, but a statically defined contiguous memory blocks, who's size and dimensions where known up front. It this case the "x,y" presentation makes sense. When C thru the STL offered true array objects, the older syntax was maintain. So what you call 'normal' might more properly called 'common'. <g> -ralph - |
| Rick
Registered User |
Mon Jul 24 15:04:13 CDT 2006
Re:Finding the dimensions of an arrayQuoteIs it possible to find out if an array has one, two, three etc dimensions The following function will tell you how many dimensions there are in the array passed to it (using an error checking routine which preserves the global error object). Function GetArrayDimensions(AnArray As Variant) As Long Dim Count As Long, X As Long Dim ErrObj As Variant If IsArray(AnArray) Then With Err 'Store Global Err Object ErrObj = Array(.Number, .Source, .Description, _ .HelpFile, .HelpContext) On Error Resume Next Do Count = Count + 1 X = UBound(AnArray, Count) If .Number Then Exit Do ElseIf X = -1 Then Count = 1 Exit Do End If Loop 'Restore Global Err Object .Raise ErrObj(0), ErrObj(1), ErrObj(2), ErrObj(3), ErrObj(4) End With End If GetArrayDimensions = Count - 1 End Function Note that if you pass it a non-array, it returns a value of -1; if you pass it a Dynamic array that hasn't yet been dimensioned, it returns zero; and it returns the number of dimensions in the array otherwise. If you Erase a dynamic array, it will respond as if it hasn't been dimensioned yet; hence this function would return zero. (There doesn't seem to be a way of differentiating between an array that was never dimensioned and one that was but was subsequently Erase'd.) Rick - |
| David
Registered User |
Mon Jul 24 15:30:16 CDT 2006
Re:Finding the dimensions of an array
I was thinking of normal Basic, Pascal etc convention.
I agree with you that it might make more sense, but human thinking is normally x,y... David "Ralph" <nt_consulting64@yahoo.com>wrote in message Quote
- |
| David
Registered User |
Mon Jul 24 15:31:35 CDT 2006
Re:Finding the dimensions of an array
BTW: trapping error conditions like that is a huge pain in the neck when
running in IDE and you want to debug code when error and not let your code error handler take care of it... David "Ralph" <nt_consulting64@yahoo.com>wrote in message Quote
- |
| RB
Registered User |
Mon Jul 24 15:49:07 CDT 2006
Re:Finding the dimensions of an array
If it matters, this is by far the fastest way to get the number of array
dimensions: www.devx.com/vb2themax/Tip/18265">www.devx.com/vb2themax/Tip/18265 RBS "David DB" <er_fortsatt@hotmail.com>wrote in message QuoteHi, |
| MikeD
Registered User |
Tue Jul 25 18:28:22 CDT 2006
Re:Finding the dimensions of an array"David DB" <er_fortsatt@hotmail.com>wrote in message QuoteBTW: trapping error conditions like that is a huge pain in the neck when "handle" errors: 1. Break on all errors 2. Break on unhandled errors 3. Break in class module Read up on these options. From what you stated above, it sounds like #1 is the option you're looking for (with that setting, you'll enter into break mode on every error, even if it would normally be handled by your error handler routine). Besides thoses, you can set break points and/or watchpoints (which you can set to enter into break mode), change the current line to execute, step into procedures, step over procedures, step out of procedures, etc. One of VB's biggest strong points has ALWAYS been its debugging features. -- Mike Microsoft MVP Visual Basic - |
| Randy
Registered User |
Sun Jul 30 11:13:27 CDT 2006
Re:Finding the dimensions of an array
vbnet.mvps.org/code/helpers/getarraydims.htm">vbnet.mvps.org/code/helpers/getarraydims.htm
-- Randy Birch MS MVP Visual Basic vbnet.mvps.org/">vbnet.mvps.org/ Please reply to the newsgroups so all can participate. "David DB" <er_fortsatt@hotmail.com>wrote in message Hi, Is it possible to find out if an array has one, two, three etc dimensions ? like arrtmp(0), arrtmp(0,1), arrtmp(1,1,1) David - |
