TravisJRyan
New member
- Joined
- Apr 4, 2005
- Messages
- 2
- Programming Experience
- Beginner
Dynamic Array Problems - Array of created Class Objects
I am in a VB.NET class in college and I am being stumped on this dynamic array attempt.
I figured out the way to redim the array when a new item is added. So that all works, but my array is a place holder for my "pet" object that I have created a class for. It has the properties, Name, Qty, Type, and Price.
My code doesnt work and I am not sure why, it all seems logical to me. . can anyone deciper my code and tell me why it doesnt?
When it adds a new item it just changes the first item in the array and if its a like item then it just changes the qty like it should. . .but the new item part wont work. . .sigh
I am in a VB.NET class in college and I am being stumped on this dynamic array attempt.
I figured out the way to redim the array when a new item is added. So that all works, but my array is a place holder for my "pet" object that I have created a class for. It has the properties, Name, Qty, Type, and Price.
My code doesnt work and I am not sure why, it all seems logical to me. . can anyone deciper my code and tell me why it doesnt?
When it adds a new item it just changes the first item in the array and if its a like item then it just changes the qty like it should. . .but the new item part wont work. . .sigh
VB.NET:
#Region " Entry Compile "
Private Sub Compile_Entry()
Dim loopIndex As Integer
Dim itemFound As Boolean
With Item
.Name = nameBox.Text
.Price = Decimal.Parse(priceBox.Text)
.Qty = Integer.Parse(qtyBox.Text)
.Type = itemTypeBox.SelectedIndex
End With
If ItemIndex = 0 Then
Inventory(0) = Item
ItemIndex += 1
Else
Do While itemFound = False And loopIndex < ItemIndex
If Item.Name = Inventory(loopIndex).Name And Item.Price = Inventory(loopIndex).Price And Item.Type = Inventory(loopIndex).Type Then
itemFound = True
Else
loopIndex += 1
End If
Loop
If itemFound Then
existingItemADD(loopIndex)
Else
newItem()
End If
End If
End Sub
Private Sub existingItemADD(ByVal index)
Inventory(index).Qty = Item.Qty
End Sub
Private Sub newItem()
ItemIndex += 1
ReDim Preserve Inventory(ItemIndex)
Inventory(ItemIndex) = Item
End Sub
#End Region
Last edited: