I have to program a t-shirt warehouse type of application. This programs allows the user to open a form with 5 UPC text boxes and 5 quantity text boxes. Once the user input all fields then I must validate that they are numeric and store them in a structure or array( I chose 2 arrays). The instructions came with a text file of that the form load reads from and I stored in an instance of an class. Once the user clicks the add button it searches the upc that the user inputted to the file which was read and calculates the quantity to the price found in the text if matched, if false return messagebox error. Next is a view report form that displays the name of the product,total quantity, items sold, and grand total of all items sold. I am lost with the searching loop. Just need a little bit of guidance as I feel that I am doing it the long way or perhaps the wrong way. Thanks in advance
Text File
Attachment 93915
Main Form
Attachment 93911
Report Form
Attachment 93913
Text File
Attachment 93915
Main Form
Attachment 93911
Report Form
Attachment 93913
Code:
Imports System.IO
Public Class frmOrderSheet
Dim Order(-1) As clsInventory
Structure Report
Dim Product As String
Dim ItemsSold As String
Dim Sales As String
Dim Total As Double
End Structure
Private Sub btnAdd_Click(sender As System.Object, e As System.EventArgs) Handles btnAdd.Click
Dim strUpc(5) As String 'string array for UPC entry from textboxes
Dim strQuant(5) As String 'string array for Quantity entry from textboxes
Dim decTotal As Decimal 'Total variable
'Validate if text boxes are numeric
If Not IsNumeric(txtUPC1.Text) Or Not IsNumeric(txtUPC2.Text) Or Not IsNumeric(txtUPC3.Text) Or Not IsNumeric(txtUPC4.Text) Or Not IsNumeric(txtUPC5.Text) Or Not IsNumeric(txtQuant1.Text) Or Not IsNumeric(txtQuant2.Text) Or Not IsNumeric(txtQuant3.Text) Or Not IsNumeric(txtQuant4.Text) Or Not IsNumeric(txtQuant5.Text) Then
MessageBox.Show("Please enter only numeric digits.")
Clear()
Else
'storing into arrays
strUpc(0) = txtUPC1.Text
strUpc(1) = txtUPC2.Text
strUpc(2) = txtUPC3.Text
strUpc(3) = txtUPC4.Text
strUpc(4) = txtUPC5.Text
strQuant(0) = txtQuant1.Text
strQuant(1) = txtQuant2.Text
strQuant(2) = txtQuant3.Text
strQuant(3) = txtQuant4.Text
strQuant(4) = txtQuant5.Text
Clear() ' calls clear sub
End If
'loops the upc array through the class upc for matches and calculates if true
For i = 0 To (strUpc.Length - 1)
If strUpc(0) = Order(i).UPC Then
MessageBox.Show("Item found")
decTotal += strQuant(0) * Order(i).Price
Else
MessageBox.Show(strUpc(0) & " not found")
End If
Next
For i = 0 To (strUpc.Length - 1)
If strUpc(1) = Order(i).UPC Then
MessageBox.Show("Item found")
decTotal += strQuant(1) * Order(i).Price
Else
MessageBox.Show(strUpc(1) & "not found")
End If
Next
For i = 0 To (strUpc.Length - 1)
If strUpc(2) = Order(i).UPC Then
MessageBox.Show("Item found")
decTotal += strQuant(2) * Order(i).Price
Else
MessageBox.Show(strUpc(2) & " not found")
End If
Next
For i = 0 To (strUpc.Length - 1)
If strUpc(3) = Order(i).UPC Then
MessageBox.Show("Item found")
decTotal += strQuant(3) * Order(i).Price
Else
MessageBox.Show(strUpc(3) & " not found")
End If
Next
For i = 0 To (strUpc.Length - 1)
If strUpc(4) = Order(i).UPC Then
MessageBox.Show("Item found")
decTotal += strQuant(4) * Order(i).Price
Else
MessageBox.Show(strUpc(4) & " not found")
End If
Next
End Sub
Private Sub frmOrderSheet_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'clear out array
ReDim Order(-1)
'check if file exists
If File.Exists("Order.txt") = True Then
'read from file
Dim myfile As StreamReader
myfile = File.OpenText("Order.txt")
Do Until myfile.Peek = -1
ReDim Preserve Order(Order.Length)
Order(Order.Length - 1) = New clsInventory 'establish New instance Address Of class
With Order(Order.Length - 1)
.UPC = myfile.ReadLine
.Item = myfile.ReadLine
.Price = myfile.ReadLine
End With
Loop
'close the data file
myfile.Close()
End If
End Sub
Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
'Closes the form
Me.Close()
End Sub
Public Sub Clear()
'Clears out the OrderSheet form and sets focus
txtQuant1.Clear()
txtQuant2.Clear()
txtQuant3.Clear()
txtQuant4.Clear()
txtQuant5.Clear()
txtUPC1.Clear()
txtUPC2.Clear()
txtUPC3.Clear()
txtUPC4.Clear()
txtUPC5.Clear()
txtUPC1.Focus()
End Sub
Private Sub btnView_Click(sender As System.Object, e As System.EventArgs) Handles btnView.Click
Me.Hide()
frmReport.ShowDialog()
Me.Show()
End Sub
End Class