Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arrays----

Status
Not open for further replies.

AFK1

IS-IT--Management
Aug 26, 2005
38
US
I need to use array to store 10 elements. I am not showing them on any grid or text boxes, I need to hold the values in memory and use them when I need. Here is my code what I am doing

--Arrays2 declarations( I have same declaration for Array1)
Private Count As Integer
Private Array2 () As String
Private MaxRows As Long
Private MaxCols As Integer
Private Const item = 0
Private Const qty= 1
Private Const Number= 2
Private Const money= 3

---Check if the shipment has more than one distinct items
--if yes then load them in array
For i = 0 To (MaxRows)
If Array1(Ship, i) = oShip Then
If Array1 (item, i) <> oitem Then
Array2 (item, Count) = Array1 (item_COL, i)
Array2 (qty, Count) = Array1 (qty_COL, i)
Array2 (Number, Count) = Array1 (qty_COL, i)/ Array1 (qty_COL, i)
Array2 (money, Count) = Array1 (money_COL, i)
Count = Count + 1
oitem = Array1 (item, i)
End If
End If
Next

---check if the items are less than 10 than use Null
If Count < 10 Then
For i = Count To 10
ReDim Preserve Array2(MaxCols, Count + 1)
Array2 (item, Count) = “”
Array2 (qty, Count) = “”
Array2 (Number, Count) = “”
Array2 (money, Count) = “”
Count = Count + 1
Next
End If
 
What is the problem?

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
The problem is it boms and doesn't work. It says subscript out of range.
 
On which line? Unless you want to post all of your code so others can recreate the identical situation, a little help in defining the problem will go a long way.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
Suppose an array with 10 rows. You reference them with integer indices 0 to 9. (Total is still 10)

For i = 0 To MaxRows - 1
-> Could it be this?


Hope i'm right
 
You haven't done a ReDim on Array2 before you use it in the first loop. It is therefore an empty array and any reference to a subscripted value will blow up with subscript out of range.

Neither MaxRows nor MaxCols are initialized which means that both are zero.

This

Array2 (Number, Count) = Array1 (qty_COL, i)/ Array1 (qty_COL, i)

looks like it is equivalent to

Array2 (Number, Count) = 1

Is that what you intend?

 
Instead of using these codes to check the if the items is less than 10 try my code:

--Arrays2 declarations( I have same declaration for Array1)
Private Count As Integer
'----declare a multi dimensional array with initial value
Private Array2 () As String
Private MaxRows As Long
Private MaxCols As Integer
Private Const item = 0
Private Const qty= 1
Private Const Number= 2
Private Const money= 3

---Check if the shipment has more than one distinct items
--if yes then load them in array

count = 0
Redim Array2(MaxCols,count)


For i = 0 To (MaxRows)
If Array1(Ship, i) = oShip Then
If Array1 (item, i) <> oitem Then
ReDim Preserve Array2(MaxCols, count)
Array2 (item, count) = Array1 (item_COL, i)
Array2 (qty, count) = Array1 (qty_COL, i)
Array2 (Number, count) = Array1 (qty_COL, i)/ Array1 (qty_COL, i)
Array2 (money, count) = Array1 (money_COL, i)
count = count + 1
oitem = Array1 (item, i)
End If
End If
Next

-------note: i used 9 because the array is base 0 -----
---check if the items are less than 10 than use Null
If count < 9 Then
For i = count To 9
ReDim Preserve Array2(MaxCols, i)

Array2 (item, i) = “”
Array2 (qty, i) = “”
Array2 (Number, i) = “”
Array2 (money, i) = “”
Next
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top