473,395 Members | 1,571 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

redimensioning a multidimensional array

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
2 2032
QVeen72
1,445 Expert 1GB
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
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

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

Similar topics

5
by: TLOlczyk | last post by:
I have a brain cramp and I need some help. I have a chunk of code below which demonstrates a problem I have with multidimensional arrays. I want to keep it simple but something specific is...
13
by: Kevin | last post by:
Help! Why are none of these valid? var arrayName = new Array(); arrayName = new Array('alpha_val', 1); arrayName = ; I'm creating/writing the array on the server side from Perl, but I
9
by: Charles Banas | last post by:
i've got an interesting peice of code i'm maintaining, and i'd like to get some opinions and comments on it, hopefully so i can gain some sort of insight as to why this works. at the top of the...
1
by: Mark Smith | last post by:
I'm trying to copy data from a 1D array to a 2D array. The obvious thing doesn't work: int twoDee = new int; int oneDee = new int { 1, 2 }; Array.Copy(oneDee, 2, twoDee, 2, 2); This causes a...
2
by: chris | last post by:
Hi there, I created a Multidimensional array of labels Label lblMultiArray = new Label { {Label3, LblThuTotal}, {Label4,LblFriTotal} }; Now I would like to compare the values in the array,...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
1
by: Chuy08 | last post by:
If I have a multidimensional array like the following: Array $records =Array 0 = 30 year, 6.0; 1 = 30 year, 6.0; 2 = Pay Option, 1.0; 3 = Pay Option, 1.0; How could I flatten this to...
5
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30...
4
Jezternz
by: Jezternz | last post by:
First of all I am open to any suggestions and advice. If a javscript multidimensional array is a bad way to do this please say so. I considered XML but I wondered if this would be a bad idea as it...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.