|
-
Jun 11th, 2004, 03:23 PM
#1
Thread Starter
Frenzied Member
Array Bounds
This should be simple, but it's not working.
The code below should show (to my mind) the values in the first dimension of the array, i.e., 12, 12, 13,...20.
Instead it shows 12, 12, then stops. This must be something obvious, but I can't see what the problem is. Any ideas? Thanks.
VB Code:
Dim i, j, l As Integer
Static x As Integer
Dim arrQuNumbers(,) = {{"12", "12", "13", "14", "15", "15", "15", "16", "17", "18", "20"}, _
{"16.1", "16.2", "17", "18", "19.1", "19.2", "19.3", "20", "21", "22", "24"}}
For i = arrQuNumbers.GetLowerBound(0) To arrQuNumbers.GetUpperBound(0)
l = arrQuNumbers(0, i)
MessageBox.Show(l)
Next
-
Jun 11th, 2004, 03:33 PM
#2
Frenzied Member
Maybe change it to:
l = arrQuNumbers(i, 0)
Is it row column, or column row, I don't remember offhand...
EDIT: Looking at that closer, you have an 11 columned array with two records in it? Is that what you wanted? Ugh, it's too late on Friday to have to think....
Last edited by SeanGrebey; Jun 11th, 2004 at 03:39 PM.
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 11th, 2004, 03:50 PM
#3
Thread Starter
Frenzied Member
No, arrQuNumbers(i, 0) shows 12, 16 and stops.
What this should be is a two dimensioned array in 2 x 11 size.
-
Jun 11th, 2004, 03:56 PM
#4
Frenzied Member
Well, change it to
For i = arrQuNumbers.GetLowerBound(1) To arrQuNumbers.GetUpperBound(1) and it works. Maybe it is 0 is number of columns and 1 is number of rows? I can't say I ever do much with multiple dimension arrays, so it's all just speculation, but I tried it and it works that way
Sean
Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.
-
Jun 11th, 2004, 07:57 PM
#5
PowerPoster
Originally posted by SeanGrebey
Well, change it to
For i = arrQuNumbers.GetLowerBound(1) To arrQuNumbers.GetUpperBound(1) and it works. Maybe it is 0 is number of columns and 1 is number of rows? I can't say I ever do much with multiple dimension arrays, so it's all just speculation, but I tried it and it works that way
It is misleading to look upon two dimensional arrays as Rows & Columns as in a table. Values are only stored in the elements of the final dimension of a multi-dimension array. No matter how many dimensions you have, all dimensions are represented by numbers which together identify the unique location at which a value can be stored. Whereas in a table you can have data stored in any row of any column
Also, you must be working with Option Strict Off to code like you have, which is not recommended.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 11th, 2004, 09:37 PM
#6
Thread Starter
Frenzied Member
Sorry taxes, but that doesn't help. I could do it with two different arrays; that's how I did it with the Access VBA program I'm trying to replace.
I'd try to do more now, but too much of Reagan stuff is going on.
-
Jun 11th, 2004, 10:14 PM
#7
VB Code:
'First Of All Lets Format the Array so that it is easy to see the mistake
Dim arrQuNumbers(,) = { _
{"12", "12", "13", "14", "15", "15", "15", "16", "17", "18", "20"}, _ ' Row 1 (index 0)
{"16.1", "16.2", "17", "18", "19.1", "19.2", "19.3", "20", "21", "22", "24"} _ ' Row 2 (index 1)
}
'Now I am going to explain this a little deeper w/ code
MsgBox("The First Array Bound (0) has a Upperbound of: " & arrQuNumbers.GetUpperBound(0))
MsgBox("The Second Array Bound (1) has a Upperbound of: " & arrQuNumbers.GetUpperBound(1))
'Here is a simple table of your values and how it corrisponds to the array bounds
'Assume the first bound is the column index(x) and the second bound is the row index(y)
'Table
' | 0 1 2 3 4 5 6 7 8 9 10
'---------------------------------------------------------
'0 | 12, 12, 13, 14, 15, 15, 15, 16, 17, 18, 20
'1 | 16.1, 16.2, 17, 18, 19.1, 19.2, 19.3, 20, 21, 22, 24
'So Now that you understand that (1,1) Refers to value 16.2 Then
MsgBox("This Value: arrQuNumbers(1, 1) is also " & arrQuNumbers(1, 1))
'So to do what you orginally wanted to do ....
For I As Integer = 0 To arrQuNumbers.GetUpperBound(1)
MsgBox(arrQuNumbers(0, I))
Next
'Now to display both rows....
For x As Integer = 0 To arrQuNumbers.GetUpperBound(0)
For j As Integer = 0 To arrQuNumbers.GetUpperBound(1)
MsgBox(arrQuNumbers(x, j))
Next
Next
Edit: Missed a 15 in first row ;(
Last edited by <ABX; Jun 12th, 2004 at 01:55 PM.
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Jun 11th, 2004, 10:21 PM
#8
How come you don't have Option Explicit on?
Here, try this code:
VB Code:
Dim i, j As Integer
Dim l As Double
Static x As Integer
Dim arrQuNumbers(,) As Decimal = {{12, 12, 13, 14, 15, 15, 15, 16, 17, 18, 20}, _
{CDec("16.1"), CDec("16.2"), 17, 18, CDec("19.1"), CDec("19.2"), CDec("19.3"), 20, 21, 22, 24}}
For i = 0 To UBound(arrQuNumbers, 2)
l = arrQuNumbers(0, i)
MessageBox.Show(l.ToString)
Next
The only difficulty I faced was placing the decimal values into the array. I think I have done it correctly.
-
Jun 11th, 2004, 10:22 PM
#9
I wasn't aware of ABX's post, dangnabbit.
Oh, and leave the dead white guy alone. Write your programs.
-
Jun 11th, 2004, 10:25 PM
#10
yeah.... i was surpirised that someone else didnt catch the mistake....
Those kind of mistakes cost me hours and hours of screwing around ;(
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Jun 11th, 2004, 10:26 PM
#11
Hey, at least it isn't a case sensitive language.
-
Jun 12th, 2004, 06:40 AM
#12
PowerPoster
Originally posted by salvelinus
Sorry taxes, but that doesn't help. I could do it with two different arrays; that's how I did it with the Access VBA program I'm trying to replace.
I'd try to do more now, but too much of Reagan stuff is going on.
I obviously have not made myself clear.
In your first post you said
"The code below should show (to my mind) the values in the first dimension of the array, i.e., 12, 12, 13"
That is the point to which I was referring. All values were stored in the Second Dimension. Your second post clearly indicates you knew the array was of 2 dimensions with 2 elements in the first dimension and 11 elements in the second dimension.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jun 12th, 2004, 09:30 AM
#13
Thread Starter
Frenzied Member
Thanks, guys, I'll try those out at work Monday.
The Option question isn't up to me, but I'll bring it up to those whom it is.
I've tried different ways. I'll try these. May be getting confused between the different vb versions I work with. Rarely use multidimension arrays. What this should eventually do is loop through some text, adding the value in the second dimension to the text after the occurence of the first dimension in the text (not replace it).
I did this in Access VBA with two separate arrays, and could do the same here. But I'm trying to write optimized code. Sometimes bugs the boss, who wants it Now, but I want it the best I can do.
I'm not sure where the mistake that <abx> says occurs. I know that arrQuNumbers(1, 1) refers to 16.2. So arrQuNumbers(0, i) should loop through the elements in the first dimension. But that didn't work either.
Needless to say, this is just test code to see how it works.
-
Jun 12th, 2004, 09:36 AM
#14
Thread Starter
Frenzied Member
Originally posted by taxes
I obviously have not made myself clear.
In your first post you said
"The code below should show (to my mind) the values in the first dimension of the array, i.e., 12, 12, 13"
That is the point to which I was referring. All values were stored in the Second Dimension. Your second post clearly indicates you knew the array was of 2 dimensions with 2 elements in the first dimension and 11 elements in the second dimension.
Uh, no, I thought there were 11 elements in both dimensions. I thought the array was 2 rows, 11 columns each. Used an example from a book. Where was my mistake in the first dimension? Thanks, I really appreciate the help. This has got to be a brain fart issue.
-
Jun 12th, 2004, 02:02 PM
#15
your mistake was:
VB Code:
For i = arrQuNumbers.GetLowerBound(0) To [b]arrQuNumbers.GetUpperBound(0)[/b]
l = arrQuNumbers(0, i)
MessageBox.Show(l)
Next
This should be GetUpperbound(1) because
GetUpperbound(0) will return the value 1 because it is refering to the row index
thats why you get 12,12 because the first two numbers are both 12's
arrQuNumbers(0,0) = 12
arrQuNumbers(0,1) = 12
the second index is the value that refers to the column
now the other value refers to the row index so you are saying that you want to access values (0,0), (0,1)
btw: GetLowerBound isn't required any more because arrays must have a base of 0
Tips:
- Google is your friend! Search before posting!
- Name your thread appropriately... "I Need Help" doesn't cut it!
- Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
- Allways Include the Name and Line of the Exception (if one is occuring!)
- If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)
If you think I was helpful, rate my post  IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous
-
Jun 12th, 2004, 04:25 PM
#16
PowerPoster
Originally posted by salvelinus
What this should eventually do is loop through some text, adding the value in the second dimension to the text after the occurence of the first dimension in the text (not replace it).
I did this in Access VBA with two separate arrays, and could do the same here. But I'm trying to write optimized code. Sometimes bugs the boss, who wants it Now, but I want it the best I can do.
I'm not sure where the mistake that <abx> says occurs. I know that arrQuNumbers(1, 1) refers to 16.2. So arrQuNumbers(0, i) should loop through the elements in the first dimension. But that didn't work either.
Needless to say, this is just test code to see how it works.
Referring to the above and ABX's last post, you can ONLY use the reference to Rows & Columns in Two dimensional arrays. But, even then, THEY DO NOT FUNCTION LIKE ROWS & COLUMNS. There are no values at all stored in the Row number. The values are stored only in the elements held in the last dimension. The values of the first dimension are solely the Row numbers, normally starting at 0 ( but in VB.NET you can create dimensions based on other numbers - with great difficulty and it is not CLS compliant so you will have difficulty if you ever want to share them with other .Net languages and don't even think about it for a single dimension array (also called Vectors)).
If you want to store two separate values relating to a common unifier then you will HAVE to use two separate 2 dimension arrays, using the first (and second if necessary) dimension numbers to link those values. In it's simplest form arrTest1(3,0) carries values which you want to which you want to relate in arrTest2(3,0). Most people never have any need to go beyond a two dimensional array. I suppose you could design a two dimension array where the first dimension denotes the class of data involved and then expand the second dimension to a point where if could hold sufficient data to achieve your objective, but there is insufficient information on your objective to determine this.
With regard to ABX's last post, in GetUpperBound(0) the 0 gets the upperbound of the FIRST dimension and that is NOT where the values are stored. GetUpperBound(1) gets the upperbound of the SECOND dimension, where the values ARE stored. You do, of course, need to know the upperbounds of all the dimensions(in your case both dimensions) in order to extract all the values
Boy, I'm glad you are not working in 5 dimension arrays
Last edited by taxes; Jun 12th, 2004 at 06:52 PM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|