d0ctorworm
Member
Hi everyone,
I've joined this forum in the hope that I can get some help with part of my code. It's very straightforward but I cannot seem to get the hang of arrays. I'm doing this as part of an electronic engineering course but I'm very new to programming and so my code is flaky...
I have to make a programme for a DVD shop where I enter the following in textboxes: ID Code, Title, Price and Quantity. Depending on the quantity there can be discounts if the DVDs are bought in bulk:
0-4 DVDs = No discount
5-9 DVDs = 12% discount
10-14 DVDs = 17% discount
Over 15 DVDs = 25% discount
The section of code below is supposed to create a dynamic array with 6 columns (textboxes, discounts and subtotals) and display it in a console (for testing). Later I plan to save the array to a .txt file.
Anyway, the array appears in the console but the discounts are wrong so I must have the array programmed incorrectly. Can anyone help me with this???
Sorry for the long post. I don't use forums very often and hope I haven't broken any rules on the first post.
Take it easy...
Jake
I've joined this forum in the hope that I can get some help with part of my code. It's very straightforward but I cannot seem to get the hang of arrays. I'm doing this as part of an electronic engineering course but I'm very new to programming and so my code is flaky...
I have to make a programme for a DVD shop where I enter the following in textboxes: ID Code, Title, Price and Quantity. Depending on the quantity there can be discounts if the DVDs are bought in bulk:
0-4 DVDs = No discount
5-9 DVDs = 12% discount
10-14 DVDs = 17% discount
Over 15 DVDs = 25% discount
The section of code below is supposed to create a dynamic array with 6 columns (textboxes, discounts and subtotals) and display it in a console (for testing). Later I plan to save the array to a .txt file.
Anyway, the array appears in the console but the discounts are wrong so I must have the array programmed incorrectly. Can anyone help me with this???
VB.NET:
Private Sub Results_Array()
'Dynamic two-dimensional array initialised as object to show different data types
Dim Results_Array(0 To 5, 0 To 0) As Object
ReDim Results_Array(0 To 5, 0 To 0)
Results_Array(0, 0) = TextBox1.Text
Results_Array(1, 0) = TextBox2.Text
Results_Array(2, 0) = TextBox3.Text
Results_Array(3, 0) = TextBox4.Text
Dim IDCode As String = CStr(Results_Array(0, 0))
Dim Title As String = CStr(Results_Array(1, 0))
Dim Price As Single = CSng(Results_Array(2, 0))
Dim QTY As Integer = CInt(Results_Array(3, 0))
Dim Discount As Single = CSng(Results_Array(4, 0))
Dim Subtotal As Single = CSng(Results_Array(5, 0))
ReDim Preserve Results_Array(0 To 5, 0 To Results_Array.GetUpperBound(0))
'Applying percentage discounts to entries
If QTY >= 5 Then
Discount = Price * QTY * 0.12
ElseIf QTY >= 10 Then
Discount = Price * QTY * 0.17
ElseIf QTY >= 15 Then
Discount = Price * QTY * 0.25
Else : Discount = 0
End If
Subtotal = (Price * QTY) - Discount
'Display Array in Console
For i = 0 To 5
For j = 0 To Results_Array.GetUpperBound(0)
System.Console.Write(Results_Array(i, j) & " ")
Next j
Next i
System.Console.Write(Discount & " ")
System.Console.Write(Subtotal & vbNewLine)
'Clear textboxes
TextBox1.Text = Nothing
TextBox2.Text = Nothing
TextBox3.Text = Nothing
TextBox4.Text = Nothing
End Sub
Sorry for the long post. I don't use forums very often and hope I haven't broken any rules on the first post.
Take it easy...
Jake
Last edited: