By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

redimensioning a multidimensional array

P: 88
i get a "subscript out of range" on the following code the second time it runs. the first time it's ok... (error on the last line)

Expand|Select|Wrap|Line Numbers
  1. Dim arrFAB() As Variant
  2. Dim rows As Integer
  3.  
  4. Private Sub cmdAdd_Click()
  5.     rows = rows + 1
  6.     ReDim Preserve arrFAB(1 To rows, 1 To 5)
Sep 20 '07 #1
Share this Question
Share on Google+
2 Replies


QVeen72
Expert 100+
P: 1,445
Hi,

In VB6, When using "Preserve" with arrays , Only the upper bound of the last dimension in a multidimensional array can be changed.
If u change any of the other dimensions, or the lower bound of the last dimension, you will get this run-time error .
Instead Use one more array .

Read This

REgards
Veena
Sep 20 '07 #2

P: 88
Hi,

In VB6, When using "Preserve" with arrays , Only the upper bound of the last dimension in a multidimensional array can be changed.
If u change any of the other dimensions, or the lower bound of the last dimension, you will get this run-time error .
Instead Use one more array .

Read This

REgards
Veena
ok, i used a dummie array to turn everything around, and it worked. this is how i did it:
Expand|Select|Wrap|Line Numbers
  1. Dim arrFAB() As Variant
  2. Dim rows As Integer
  3.  
  4. Private Sub cmdAdd_Click()
  5.     ' This sub adds one more item to a list box of items to purchase
  6.     Dim arrDummie() As Variant
  7.     Dim i, j As Integer
  8.     Dim totalprice As Double
  9.  
  10.     rows = rows + 1
  11.  
  12.     ReDim Preserve arrFAB(1 To 5, 1 To rows)
  13.     ReDim arrDummie(1 To rows, 1 To 5)
  14.  
  15.     arrFAB(1, rows) = txtFAB.Text
  16.     arrFAB(2, rows) = txtDescription.Text
  17.     arrFAB(3, rows) = txtQty.Text
  18.     arrFAB(4, rows) = txtUnitPrice.Text
  19.     arrFAB(5, rows) = CInt(txtQty.Text) * CInt(txtUnitPrice.Text)
  20.  
  21.  
  22.     For i = 1 To rows
  23.         For j = 1 To 5
  24.             arrDummie(i, j) = arrFAB(j, i)
  25.         Next
  26.         totalprice = totalprice + arrFAB(5, i)
  27.     Next
  28.  
  29.     lstItems.List = arrDummie()
  30.     txtTotalPrice.Text = totalprice
  31.     cmdCreate.Enabled = True
  32. End Sub
Sep 20 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.