I’m trying to assemble a multidimensional array At the top of the method, It is a global property Dimmed to (-1, -1). After I have the results of a command, I then try to ReDim it in the method to (theDeviceCount, 4) with theDeviceCount being the number of devices in the list returned. The code is:
// scanResults is a string array containing an even multiple of 5 lines for each device
Dim theDeviceCount As Integer = scanResults.Ubound \\ 5
Redim DeviceList(theDeviceCount, 4)
But, that always ends up in a compile error telling me that the size of an array must be a constant or a number.
Since I don’t know how many instances I will have until I’m running, how can I set a constant or number?
I would explain in more detail but I’m viewing this on my phone.[/quote]
Thanks, Nick, but that assumes we know what the value for the Dim/ReDim would be. In this case, I don’t until the app is running.
I have tried every combo I can think of and cannot duplicate that error
except when a variable is used during the initial DIM statement
DIM must have constants as Roger mentioned
DIM a(10,10) as integer // this is fine
dim x as integer=10
dim a(x,x) as integer // this will produce said error
dim x as integer=10
dim a(-1,-1) as integer
redim a(x,x) /// this works
No matter how I sort it, I continue to get this error. Here is the exact code again:
Dim theDriverCount As Integer
theDriverCount = scanResults.Ubound \\ 5
Dim DeviceDrivers(-1, -1) As String
Redim DeviceDrivers(theDriverCount, 4) As String
The difference between my code and all of the examples that you are providing is that I’m doing an integer division to get the value of theDriverCount. Other than that, I see no difference in the logic in my code and all of your examples.
Dim scanResults(25) As String
Dim theDriverCount As Integer
theDriverCount = scanResults.Ubound \\ 5
Dim DeviceDrivers(-1, -1) As String
Redim DeviceDrivers(theDriverCount, 4)
All I’ve done is add an array to get a ubound for the calculation.
DIM must specifiy the datatype, and must have literal values (not variables) for the bounds
REDIM should not (and can not), and can either variables or literals for the bounds
REDIM cannot be used unless DIM was used FIRST
Okay - I take it back - the Xojo error is exact - my frustration with battling the original issue just had me seeing the error and not what it actually said when it changed from the type error to the syntax error.