Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to define a max array count value 1

Status
Not open for further replies.

TheFitz

Programmer
Dec 18, 2003
140
GB
Hi All,

I'm guessing there is a really easy solution to this . . .

Assuming I've got a multidimentional array as below:

Code:
Dim arrData(1, 10) As String

where x is variable and defined by a load process in a separate function. I could pass the total through to the child sub routine, however, that feels messy and I believe there should be an internal function to do this. I have tried the following

Code:
Dim arrData(1, 10) As String
MsgBox arrData.getLength(1)

But it's erroring with "Invalid Qualifier"

Thanks for any help in advance,

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
Are you using VB.NET or wanting to use VB.NET??? As arrays in VB6.0 do not have any sub items as such as you are trying to show...

[tt]
Option Explicit

Private Sub Form_Load()
Dim MyArray(1, 10) As String
MsgBox LBound(MyArray) & " to " & UBound(MyArray)
End Sub
[/tt]


Good Luck

 
perfect thanks

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
and
* Those who Don't!!
 
getlength is a .NET method, so that's exactly the error message I'd expect to see in VB6, which is not a .NET language.

You may want to be asking this in forum796

VB6 does not have a native method for determining the dimension count. I've posted methods in this forum for accesing this sort of low-level info about VB arrays, although I don't recall any example of directly returning the number of elements in a specific dimension. This info is available and, rather than reinvent the wheel, let me point you at this example:
 
I suspect that you may have meant to post that in thread222-1592506 ...
 
Yeah!!! What happened??? Then again right after that I lost internet connection because of the winds (ISP went down or something???) I'm so confused...
 
If the array is relatively small, a very basic way would be to read each element in turn until you get an error that you trap. (Measures only up to the number you choose. Takes less than 1 milisecond)
Code:
Sub MeasureArray()
'gives the size of the 2 elements or MyArray(#,#)
On Error Goto ArrayEnd1
For a=0 to 5000(or whatever maximum you think it is)
  b=MyArray(a,0)
Next
Element1=a-1
EndArray1:

On Error Goto ArrayEnd2
For a=0 to 5000
  b=MyArray(0,a)
Next
Element2=a-1
EndArray2:
On Error Goto 0
Exit Sub

ArrayEnd1:
'exits loop when it gets to the end
Element1=a-1
Resume EndArray1

ArrayEnd2:
Element2=a-1
Resume EndArray2

Exit sub
 
I'm confused. Are we trying to determine the size(s) of a multi-dimensioned array? Am I mis-understanding the question?

Code:
Private Sub Command1_Click()
    
    Dim BigArray(9 To 10, 3 To 5, 0 To 2, 2 To 7) As Long
    
    Debug.Print LBound(BigArray, 1), UBound(BigArray, 1)
    Debug.Print LBound(BigArray, 2), UBound(BigArray, 2)
    Debug.Print LBound(BigArray, 3), UBound(BigArray, 3)
    Debug.Print LBound(BigArray, 4), UBound(BigArray, 4)
    
End Sub

There is an optional 2nd argument to the ubound and lbound functions.



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
I always forget that second argument; you are quie right, that'd would be the cleanest way to do this.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top