Learning new languages is always fun....lol
I am having an issue with a two-dimensional array. I have the following code:
'array for intervals params of OutputCaptureEX
Dim intervals (1 To 2, 1 To 2, 1 To 2, 1 To 2, 1 To 2) As UnsignedInteger
How do I go about populating each individual index within the internal arrays? I tried the following, but get an error.
intervals(0,1) = 37500
intervals(0,2) = 38250
etc......
Here is the error:
Error: array "intervals" requires 5 index expressions
It seems I am being forced to put in a single value for each index of the intervals array, instead of being able to put values into the internal arrays indices.
Thanks.
dimentional array
-
- Posts: 15
- Joined: 22 February 2007, 12:05 PM
dimentional array
Last edited by hacktorious on 09 March 2007, 21:14 PM, edited 1 time in total.
Re: dimentional array
You've defined a 5-dimension array which requires 5 indices to access an individual element. If you wanted a 2-dimension array, the definitions would look something like this:hacktorious wrote:I am having an issue with a two-dimensional array.Code: Select all
Dim intervals (1 To 2, 1 To 2, 1 To 2, 1 To 2, 1 To 2) As UnsignedInteger
Code: Select all
Dim intervals (1 To 2, 1 To 2) As UnsignedInteger
- Don Kinzer
-
- Posts: 15
- Joined: 22 February 2007, 12:05 PM
Oops..... No, I do want a 5 dimensional array. Two was a typo.
I need a 5 dimensional array, which contains five arrays. Each array within the 5-dimensional array must hold two values.
Dim intervals (1 To 2, 1 To 2, 1 To 2, 1 To 2, 1 To 2) As UnsignedInteger
How can I put values into the internal arrays?
Hmmmm, now that I think about it maybe a two-dimensional will work, but like this:
Dim intervals(1 To 5, 1 To 5) , I have to think about it more....getting sleepy...lol
OK, let's suppose the two-dimensional will work, how can I fill the internal arrays indices with some UnsignedIntegers?
I need a 5 dimensional array, which contains five arrays. Each array within the 5-dimensional array must hold two values.
Dim intervals (1 To 2, 1 To 2, 1 To 2, 1 To 2, 1 To 2) As UnsignedInteger
How can I put values into the internal arrays?
Hmmmm, now that I think about it maybe a two-dimensional will work, but like this:
Dim intervals(1 To 5, 1 To 5) , I have to think about it more....getting sleepy...lol
OK, let's suppose the two-dimensional will work, how can I fill the internal arrays indices with some UnsignedIntegers?
You simply assign values to each element of the array. In any event, you must supply an index for each dimension of the array - two if it is 2-dimension, three if it is 3-dimension, etc. The compiler error that you mentioned in the original post was informing you that you hadn't supplied the correct number of indices.hacktorious wrote:OK, let's suppose the two-dimensional will work, how can I fill the internal arrays indices with some UnsignedIntegers?
You may want to read section 3.17 of the ZBasic Reference Manual. It describes how arrays are laid out in memory.
- Don Kinzer
hacktorious wrote:How can I put values into the internal arrays?
Well, you could do it by nested for-next loops
Code: Select all
Dim Intervals (1 To 2, 1 To 2, 1 To 2, 1 To 2, 1 To 2) As UnsignedInteger
Dim Index_A as byte
Dim Index_B as Byte
Dim Index_C as byte
Dim Index_D as byte
Dim Index_E as byte
For Index_A = 1 to 2
For Index_B = 1 to 2
For Index_C = 1 to 2
For Index_D = 1 to 2
For Index_E = 1 to 2
Intervals(Index_A, Index_B, Index_C, Index_D, Index_E) = 0
Next
Next
Next
Next
Next
You would do it the same way as above, just fewer indices would be used.Hmmmm, now that I think about it maybe a two-dimensional will work, but like this:
Dim intervals(1 To 5, 1 To 5) , I have to think about it more....getting sleepy...lol
OK, let's suppose the two-dimensional will work, how can I fill the internal arrays indices with some UnsignedIntegers?