I'm new at Visual Basic, doing an assignment right now. This is the code I have
Sub Main()
Console.Write("Please let me know your nickname: ")
Dim name As String = Console.ReadLine()
Console.WriteLine("Thank you " + name + "!")
Console.WriteLine()
Console.Write("How many litres " + name + "<only whole litres please>? ")
Dim litres As Integer = Console.ReadLine()
Console.Write("Premium quality? <y/n>: ")
Dim ans As Char = Console.ReadLine()
Dim prem As Boolean
If ans = "y" Then
prem = True
ElseIf ans = "n" Then
prem = False
End If
Console.WriteLine()
Console.WriteLine("WELCOME TO APU'S GAS STATION")
Console.Write("Quality: ")
If prem = True Then
Console.Write("Premium")
Else : Console.Write("Regular")
End If
Dim price As Double = 12.44
Console.WriteLine("Quantity <l>: " + litres)
Console.WriteLine("Price per l: " + price)
Console.WriteLine("Sum to pay: " + litres * price)
Console.ReadLine()
End Sub
At runtime I can input all data no problem, but then I get an error that I can roughly translate to "invalid cast of the string "Quantity : " to type 'Double'.
I'm not so sure what is going on, would appreciate pointers.
to avoid this problem you can use
Console.WriteLine("Quantity <l>: " + litres.ToString)
Or you can use
Console.WriteLine("Quantity <l>: " + CStr(price))
I fixed your code, this should work :
Sub Main()
Console.Write("Please let me know your nickname: ")
Dim name As String = Console.ReadLine()
Console.WriteLine("Thank you " & name & "!")
Console.WriteLine()
Console.Write("How many litres " & name & "<only whole litres please>? ")
Dim litres As Integer = Console.ReadLine()
Console.Write("Premium quality? <y/n>: ")
Dim ans As Char = Console.ReadLine()
Dim prem As Boolean
If ans = "y" Then
prem = True
ElseIf ans = "n" Then
prem = False
End If
Console.WriteLine()
Console.WriteLine("WELCOME TO APU'S GAS STATION")
Console.Write("Quality: ")
If prem = True Then
Console.Write("Premium")
Else : Console.Write("Regular")
End If
Dim price As Double = 12.44
Console.WriteLine("Quantity <l>: " & litres)
Console.WriteLine("Price per l: " & price)
Console.WriteLine("Sum to pay: " & (litres * price))
Console.ReadLine()
End Sub
Related
My calculations work but every time I run the program my output will be the "negative, does not exceed" result. I'm very new to all this so please any suggestions will help.
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim foodname As String = MaskedTextBox1.Text
Dim calories As Integer = MaskedTextBox2.Text
Dim fat As Integer = MaskedTextBox3.Text
Dim calculation As Double = (fat * 9) / calories
Dim positive As String = "which exceeds AHA recommendation"
Dim negative As String = "which does not exceed AHA recommendation"
ListBox1.Items.Clear()
If ((fat * 9) / calories) > (0.3 * 100) Then
ListBox1.Items.Add(foodname & " contains " & FormatPercent(calculation) & " calories from fat, " & positive)
ElseIf ((fat * 9) / calories) < (0.29 * 100) Then
ListBox1.Items.Add(foodname & " contains " & FormatPercent(calculation) & " calories from fat, " & negative)
End If
End Sub
End Class
would this help?
If ((fat * 9) / calories) > (0.3 * 100) Then
ListBox1.Items.Add(foodname & " contains " & FormatPercent(calculation) & " calories from fat, " & positive)
Else
ListBox1.Items.Add(foodname & " contains " & FormatPercent(calculation) & " calories from fat, " & negative)
End If
you have only two options here, no need for 2 conditions. either the first one is true, or it must be the second one
Console.WriteLine("Welcome to the game noughts and crosses")
While game = 1
While gameplay = 0
Console.WriteLine("Please choose a square to place X")
move = Console.ReadLine
If row(move - 1) = " " Then
row(move - 1) = row(move - 1).Replace(CChar(" "), CChar("X"))
gameplay = 1
count = count + 1
Else
Console.WriteLine("That space has already been taken")
Console.ReadLine()
End If
Console.WriteLine(row(0) & row(1) & row(2))
Console.WriteLine(row(3) & row(4) & row(5))
Console.WriteLine(row(6) & row(7) & row(8))
Console.ReadLine()
End While
While gameplay = 1
npcmove = (10 * Rnd())
If row(npcmove - 1) = " " Then
row(npcmove - 1) = row(npcmove - 1).Replace(CChar(" "), CChar("O"))
gameplay = 0
count = count + 1
Console.WriteLine("The CPU has chosen to place O in space " & npcmove)
Else
Console.WriteLine("That space has already been taken")
Console.ReadLine()
End If
Console.WriteLine(row(0) & row(1) & row(2))
Console.WriteLine(row(3) & row(4) & row(5))
Console.WriteLine(row(6) & row(7) & row(8))
Console.ReadLine()
End While
End While
End Sub
Sub endgame()
If count = 9 Then
Console.WriteLine("The game was a tie")
Console.ReadLine()
FileClose()
End If
End Sub
Sub VicRoy()
If (row(0).Contains("X") & row(1).Contains("X") & row(2).Contains("X")) Then
Console.WriteLine("Congratulations on the epic Victory Royale")
Console.ReadLine()
FileClose()
End If
The code runs a noughts and crosses game with a random ai using while loops. The board is represented via a new list of strings. However once I meet the condition of the if statement, where all the values are X the if statement will not be executed and the game will continue
replace & with And, the & in vb.net mean you just will Merage strings
At the start of the program I define a new Public Structure 'Data':
Public Structure Data
Dim car, grid, points As String
Dim driver, team, fastestlap, racetime As String
End Structure
I then have the user input data and it is added to array displayData(5) of data type 'Data'.
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim displayData(5) As Data
Dim accepted As Boolean = False
Dim temp As String
Dim tempNum As Integer
Dim output As String = ""
Dim arraysize As Integer = 0
For x = 0 To 5
displayData(x).driver = InputBox("Please enter the name of driver number " & x + 1)
temp = InputBox("Please enter the car number of driver number " & x + 1)
While accepted = False
If IsNumeric(temp) Then
accepted = True
displayData(x).car = temp
Else
accepted = False
temp = InputBox("Error: integer not entered. Please enter the car number of driver number " & x + 1)
End If
End While
accepted = False
displayData(x).team = InputBox("Please enter the team name of driver number " & x + 1)
temp = InputBox("Please enter the grid number of driver number " & x + 1)
tempNum = Convert.ToInt32(temp)
While accepted = False
If IsNumeric(tempNum) Then
accepted = True
displayData(x).grid = temp
Else
accepted = False
temp = InputBox("Error: integer not entered. Please enter the grid number of driver number " & x + 1)
tempNum = Convert.ToInt32(temp)
End If
End While
accepted = False
displayData(x).fastestlap = InputBox("Please enter the fastest lap of driver number " & x + 1)
displayData(x).racetime = InputBox("Please enter the race time of driver number " & x + 1)
temp = InputBox("Please enter the points of driver number " & x + 1)
While accepted = False
If IsNumeric(temp) Then
accepted = True
displayData(x).points = temp
Else
accepted = False
temp = InputBox("Error: integer not entered. Please enter the points of driver number " & x + 1)
End If
End While
accepted = False
output = output & displayData(x).driver & "," & displayData(x).car & "," & displayData(x).team & "," & displayData(x).grid & "," & displayData(x).fastestlap & "," & displayData(x).racetime & "," & displayData(x).points & vbCrLf
Next
Dim filename As String = "U:\Subjects\Computing\AH Computing\Project Files\Leaderboard.csv"
My.Computer.FileSystem.WriteAllText(filename, output, True)
bubbleSort(arraysize, displayData(6))
End Sub
Above is the main bulk of my code. I am getting an error from typing in displayData(6) into bubblesort, which is defined here:
Public Sub bubbleSort(ByVal arraysize As Integer, ByVal displayData() As Data)
Dim counter As Integer
Dim outerloop As Integer
For outerloop = (arraysize - 2) To 0 Step -1
For counter = 0 To outerloop
If displayData(counter).racetime > displayData(counter + 1).racetime Then
swap(displayData(counter).racetime, displayData(counter + 1).racetime)
swap(displayData(counter).car, displayData(counter + 1).car)
swap(displayData(counter).driver, displayData(counter + 1).driver)
swap(displayData(counter).points, displayData(counter + 1).points)
swap(displayData(counter).team, displayData(counter + 1).team)
swap(displayData(counter).fastestlap, displayData(counter + 1).fastestlap)
swap(displayData(counter).grid, displayData(counter + 1).grid)
End If
Next
Next
End Sub
And apparently I need more normal text in order to save this. The bubble sort uses a swap algorithm that I defined in another part of the program, but it is incredibly simple and is 100% not the cause of the error so it seems unproductive to include it.
So I get this error when trying to run my code "System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'" I am not exactly sure what the issue is. The user should be able to enter 3 assignment grades and then see the averages
I marked the line where I get the error with 'THIS IS THE ERROR'
Public Class GradeBook
Dim grade(9, 2) As Integer 'Store 10 student grades on 3 tests'
Dim studentCount As Integer = 0 'Number of students entered'
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
GradeListBox.Items.Add(vbTab & vbTab & "Test 1" & vbTab & "Test 2" & vbTab & "Test 3" & vbTab & "Average")
End Sub
Private Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click
grade(studentCount, 0) = Convert.ToInt32(Assignment1TextBox.Text)
grade(studentCount, 1) = Convert.ToInt32(Assignment2TextBox.Text)
grade(studentCount, 2) = Convert.ToInt32(Assignment3TextBox.Text)
Dim output As String = "Student " & studentCount & vbTab
For column = 0 To grade.GetUpperBound(1)
If LetterRadioButton.Checked = True Then
output &= vbTab & LetterGrade(grade(studentCount, column))
Else
output &= vbTab & grade(studentCount, column)
End If
Next
output &= vbTab & CalculateStudentAverage(studentCount)
GradeListBox.Items.Add(output)
studentCount += 1
AverageLabel.Text = CalculateClassAverage()
displayBarChart()
End Sub
Function LetterGrade(ByVal grade As Double) As String
Dim output As String = ""
Select Case grade
Case Is >= 90
output = "A"
Case Is >= 80
output = "B"
Case Is >= 70
output = "C"
Case Is >= 60
output = "D"
Case Is >= 50
output = "E"
End Select
Return output
End Function
Function CalculateStudentAverage(ByVal row As Integer) As String
Dim gradeTotal As Integer = 0
For column = 0 To grade.GetUpperBound(1)
gradeTotal += grade(row, column) 'THIS IS THE ERROR'
Next
Dim studentAverage As String = String.Empty
If LetterRadioButton.Checked = True Then
studentAverage = LetterGrade(gradeTotal / (grade.GetUpperBound(1) + 1))
Else
studentAverage = String.Format("{0:F}", (gradeTotal / grade.GetUpperBound(1) + 1))
End If
Return studentAverage
End Function
Function CalculateClassAverage() As String
Dim classTotal As Integer = 0
For row = 0 To studentCount - 1
For column = 0 To grade.GetUpperBound(1)
classTotal += grade(row, column)
Next
Next
Dim classAverage As String = String.Empty
If LetterRadioButton.Checked = True Then
classAverage = LetterGrade(classTotal / (studentCount * (grade.GetUpperBound(1) + 1)))
Else
classAverage = String.Format("{0:F}", (classTotal / (studentCount * (grade.GetUpperBound(1) + 1))))
End If
Return classAverage
End Function
Sub displayBarChart()
GradeListBox.Items.Clear()
GradeListBox.Items.Add(vbTab & vbTab & "Test 1" & vbTab & "Test 2" & vbTab & "Test 3" & vbTab & "Average")
For row = 0 To studentCount - 1
Dim output As String = "Student " & row & vbTab
For column = 0 To grade.GetUpperBound(1)
If LetterRadioButton.Checked = True Then
output &= vbTab & LetterGrade(grade(row, column))
Else
output &= vbTab & (grade(row, column))
End If
Next
output &= vbTab & CalculateStudentAverage(studentCount)
GradeListBox.Items.Add(output)
studentCount += 1
AverageLabel.Text = CalculateClassAverage()
displayBarChart()
Assignment1TextBox.Clear()
Assignment2TextBox.Clear()
Assignment3TextBox.Clear()
If studentCount = grade.GetUpperBound(0) + 1 Then
InputGradeGroupBox.Enabled = False
End If
Next
End Sub
End Class
To be honest, I suspect you're going about it in a way not suited to OOP. Using arrays for multiple peices of data is prone to error and harder to maintain later.
Lets have a think about how you want to represent your data. You have a bunch of students. In a more complete example each student would have a name, personal details such as address, a list of the courses they're taking and for each course, a list of assignments and scores for each assignment which can also be represented as a grade.
So in essence you have a class called Student and the various bits of information are properties of that student.
Finally you have a list of these students
In your code, you simply have a student number and three assignment scores.
Your basic student class should have the properties of Number, Test1Score, Test2Score and Test3Score. You would also want to be able to get the grade from each score, the average of all the scores and the average of all the grades.
The code below defines the Student class with that information in mind
Friend Class Student
Public Property Number As Integer
Public Property Test1Score As Integer
Public Property Test2Score As Integer
Public Property Test3Score As Integer
Public Function Test1Grade() As String
Return LetterGrade(Test1Score)
End Function
Public Function Test2Grade() As String
Return LetterGrade(Test2Score)
End Function
Public Function Test3Grade() As String
Return LetterGrade(Test3Score)
End Function
Friend Shared Function LetterGrade(ByVal grade As Double) As String
Dim output As String = ""
Select Case grade
Case Is >= 90
output = "A"
Case Is >= 80
output = "B"
Case Is >= 70
output = "C"
Case Is >= 60
output = "D"
Case Is >= 50
output = "E"
Case Else
output = "F"
End Select
Return output
End Function
Friend Function AverageScore() As Double
Return (Test1Score + Test2Score + Test3Score) / 3
End Function
Friend Function AverageGrade() As String
Dim avgscore As Double = AverageScore()
Return LetterGrade(avgscore)
End Function
End Class
The function LetterGrade is Shared so that it can be used in your main form to calculate the average grade for the entire class.
OK Next think about how you want your program to work. You'll need a list of students, so at the beginning of your form class , you'll need this..
Public Class Form1
Private Students As New List(Of Student)
This way, instead of trying to keep track of your variable studentCount you can just use the .Count property of the List e.g Students.Count. You wont need to any adding to it as the Students list keeps track of it automatically.
Next, you'll want the function that calculates the average score/grade of the class..
Function CalculateClassAverage() As String
Dim classTotal As Integer = 0
For Each tmpStudent As Student In Students
With tmpStudent
classTotal += .Test1Score + .Test2Score + .Test3Score
End With
Next
Dim classAverage As String = String.Empty
If LetterRadioButton.Checked = True Then
classAverage = Student.LetterGrade((classTotal / Students.Count) / 3)
Else
classAverage = String.Format("{0:F}", (classTotal / (Students.Count)) / 3)
End If
Return classAverage
End Function
As you can see, there are a number of differences here because of the way your data is stored, but you should be able to follow it. One difference is the With statement, this allows you to save on typing. inside the With.. End With block, instead of typing tmpstudent.Test1Score etc, you can just type .Test1Score
The other thing of note is this line ..
classAverage = Student.LetterGrade( ... etc
You may think that there has been no declaration of a variable called Student. There IS a class, but not a variable. What this is actually doing is calling the LetterGrade function that is shared in the Student class definition.. Have a look at shared functions.
Next is the code to display the information in the ListBox. I haven't changed the name even though it is misleading btw.
Sub displayBarChart()
GradeListBox.Items.Clear()
GradeListBox.Items.Add(vbTab & vbTab & "Test 1" & vbTab & "Test 2" & vbTab & "Test 3" & vbTab & "Average")
For Each tmpstudent As Student In Students
Dim output As String = "Student " & tmpstudent.Number & vbTab
With tmpstudent
If LetterRadioButton.Checked = True Then
output &= .Test1Grade & vbTab & .Test2Grade & vbTab & .Test3Grade & vbTab & .AverageGrade
Else
output &= .Test1Score & vbTab & .Test2Score & vbTab & .Test3Score & vbTab & .AverageScore
End If
End With
GradeListBox.Items.Add(output)
AverageLabel.Text = CalculateClassAverage()
Next
If Students.Count = 10 Then
InputGradeGroupBox.Enabled = False
End If
End Sub
More use of the With..End With statements again, but the rest should be straighforward to follow.
A little extra bit of code.. When you click on the LetterRadioButton, the data in the listBox and ClassAveragelabel are refreshed with the appropriate letters/grades
Private Sub LetterRadioButton_CheckedChanged(sender As Object, e As EventArgs) Handles LetterRadioButton.CheckedChanged
AverageLabel.Text = CalculateClassAverage()
displayBarChart()
End Sub
Finally, to bring it all together, you have the code for the button click..
Private Sub SubmitButton_Click(sender As Object, e As EventArgs) Handles SubmitButton.Click
Dim tmpStudent As New Student With {.Number = Students.Count + 1,
.Test1Score = Convert.ToDouble(Assignment1TextBox.Text),
.Test2Score = Convert.ToDouble(Assignment2TextBox.Text),
.Test3Score = Convert.ToDouble(Assignment3TextBox.Text)}
Dim output As String = "Student " & tmpStudent.Number & vbTab
With tmpStudent
If LetterRadioButton.Checked = True Then
output &= vbTab & .Test1Grade & vbTab & .Test2Grade & vbTab & .Test3Grade
Else
output &= vbTab & .Test1Score & vbTab & .Test2Score & vbTab & .Test3Score
End If
End With
Students.Add(tmpStudent)
If LetterRadioButton.Checked Then
output &= vbTab & tmpStudent.AverageGrade
Else
output &= vbTab & tmpStudent.AverageScore
End If
GradeListBox.Items.Add(output)
AverageLabel.Text = CalculateClassAverage()
displayBarChart()
Assignment1TextBox.Clear()
Assignment2TextBox.Clear()
Assignment3TextBox.Clear()
End Sub
Hopefully in addition to my comment to your question, this provides a slightly better insight of OOP.
I am not too sure why, but the current stock for all the items now appears as zero when it shows up in a listbox/on the 'receipt'. Also, I am struggling to get it to update back up from zero when it becomes zero.
Public Class Form1
Dim GTIN As String
Dim LineContaining As String
Dim quantity As String
Dim description As String
Dim singleamount As String
Dim singleprice As Double
Dim totalprices As Double
Dim correctcode As Boolean
Dim stocklevel As String
Dim requiredstock As Integer
Dim remainingstock As Integer
Dim stock As Integer
'declare variables
Private Sub btnEnterGTIN_Click(sender As Object, e As EventArgs) Handles btnEnterGTIN.Click
GTIN = getValidGTIN()
Call itemfinder(GTIN)
End Sub
Function getValidGTIN()
Dim GTIN, ValidGTINAmountCharacters As String
Dim GTINOK As Boolean
'Declaring variables.
GTINOK = False
Do
GTIN = InputBox("Enter the full GTIN Number (it should be 8 digits long)")
'Prompts the user to enter the GTIN.
ValidGTINAmountCharacters = Len(GTIN)
'Makes it so that the amount of characters of the GTIN is stored in the variable ValidGTINAmountCharacters.
If ValidGTINAmountCharacters = 8 Then GTINOK = True
'Makes it so the program will only accept an input if it was 8 characters long.
If Not IsNumeric(GTIN) Then GTINOK = False
'Makes it so that if any other character typed in apart from a number is not valid.
If Not GTINOK Then MsgBox("The GTIN Number isn't valid. It should be a 8 digit number. (Should not contain letters or symbols).")
'Makes it so that if the GTIN is not valid according to the above, a message appears saying it is invalid.
Loop Until GTINOK
Return GTIN
End Function
Private Sub itemfinder(ByVal GTIN As String)
Using reader As New IO.StreamReader("receipt_orders.txt")
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
If line.Contains(GTIN) Then
LineContaining = line
Exit While
End If
End While
End Using
'reads the textfile to find the entered GTIN
description = Mid$(LineContaining, 10, 17)
singleamount = Mid$(LineContaining, 38, 4)
stocklevel = Mid$(LineContaining, 43, 2)
quantity = InputBox("Enter the quantity you require?")
'prompts user to input the quantity
Dim QuantityOK As Boolean
QuantityOK = False
If quantity <= stocklevel Then
QuantityOK = True
End If
Dim GTINOK As Boolean
GTINOK = False
Using reader As New IO.StreamReader("receipt_orders.txt")
While Not reader.EndOfStream
Dim line As String = reader.ReadLine()
If line.Contains(GTIN) Then
GTINOK = True
Exit While
End If
End While
End Using
stocklevel = stock
If QuantityOK = False And stock > 0 Then
MsgBox("There is not enough of this item in stock, restocking item to extra stock needed. You will not get " _
& quantity & " items, but we can give you " & stocklevel & " and restock the remaining amount.")
requiredstock = quantity - stocklevel
totalprices = stocklevel * singleamount
lstGTIN.Items.Add(GTIN)
lstName.Items.Add(description)
lstQuantity.Items.Add(quantity)
lstInStock.Items.Add(stocklevel)
lstAdditionalStock.Items.Add(requiredstock)
lstSinglePrice.Items.Add(FormatCurrency(singleamount))
lstTotal.Items.Add(FormatCurrency(totalprices))
lstTotals.Items.Add(totalprices)
lstReceipt.Items.Add("GTIN Code: " & GTIN)
lstReceipt.Items.Add("Item: " & description)
lstReceipt.Items.Add("Quantity wanted: " & quantity)
lstReceipt.Items.Add("Quantity available: " & stocklevel)
lstReceipt.Items.Add("Required restock amount: " & requiredstock)
lstReceipt.Items.Add("Price per unit: " & FormatCurrency(singleamount))
lstReceipt.Items.Add("Subtotal cost: " & FormatCurrency(totalprices))
End If
If QuantityOK = False And stock = 0 Then
MsgBox("This item is out of stock. We will register this item for restock in time for your next purchase.")
requiredstock = quantity
totalprices = 0
lstGTIN.Items.Add(GTIN)
description = Mid$(LineContaining, 10, 17)
lstName.Items.Add(description)
lstQuantity.Items.Add(quantity)
lstInStock.Items.Add(stocklevel)
lstAdditionalStock.Items.Add(requiredstock)
lstSinglePrice.Items.Add(FormatCurrency(0))
lstTotal.Items.Add(FormatCurrency(totalprices))
lstTotals.Items.Add(totalprices)
lstReceipt.Items.Add("GTIN Code: " & GTIN)
lstReceipt.Items.Add("Item: " & description)
lstReceipt.Items.Add("Quantity wanted: " & quantity)
lstReceipt.Items.Add("Quantity available: " & stocklevel)
lstReceipt.Items.Add("Required restock amount: " & requiredstock)
lstReceipt.Items.Add("Price per unit: " & FormatCurrency(0))
lstReceipt.Items.Add("Subtotal cost: " & FormatCurrency(totalprices))
End If
'if the GTIN is found in the textfile it is valid.
'if the GTIN code was incorrect then put the listboxes as product not found or zero.
If QuantityOK = True Then
MsgBox("No restock of item needed.")
totalprices = quantity * singleamount
remainingstock = stocklevel - quantity
lstGTIN.Items.Add(GTIN)
lstName.Items.Add(description)
lstQuantity.Items.Add(quantity)
lstInStock.Items.Add(stocklevel)
lstAdditionalStock.Items.Add(requiredstock)
lstSinglePrice.Items.Add(FormatCurrency(singleamount))
lstTotal.Items.Add(FormatCurrency(totalprices))
lstTotals.Items.Add(totalprices)
'if the GTIN code was correct, calculate the subtotal amount and put information in listboxes.
lstReceipt.Items.Add("GTIN Code: " & GTIN)
lstReceipt.Items.Add("Item: " & description)
lstReceipt.Items.Add("Quantity: " & quantity)
lstReceipt.Items.Add("Quantity in stock: " & stocklevel)
lstReceipt.Items.Add("Required restock amount: " & requiredstock)
lstReceipt.Items.Add("Price per unit: " & FormatCurrency(singleamount))
lstReceipt.Items.Add("Subtotal cost: " & FormatCurrency(totalprices))
'adds all the information onto a receipt - updates after every purchase.
Dim contents As String = IO.File.ReadAllText("receipt_orders.txt")
If GTINOK = False Then
lstReceipt.Items.Add("GTIN Code: " & GTIN)
lstReceipt.Items.Add("Item: Product not found")
lstGTIN.Items.Add(GTIN)
lstName.Items.Add("Product not found!")
lstQuantity.Items.Add(0)
lstSinglePrice.Items.Add(FormatCurrency(0))
lstInStock.Items.Add(0)
lstAdditionalStock.Items.Add(0)
lstTotal.Items.Add(FormatCurrency(0))
lstTotals.Items.Add(0)
End If
contents = contents.Replace(stocklevel, remainingstock)
IO.File.WriteAllText("items_to_restock", contents)
End If
Dim totalprice As Double
For x As Integer = 0 To lstTotals.Items.Count - 1
totalprice += Val(lstTotals.Items.Item(x).ToString)
Next
'adds up the numbers in the total list box and puts in the text box TotalPrice.
txtTotalPrice.Text = FormatCurrency(totalprice.ToString)
'formats the total as a currency.
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'clears all listboxes
lstGTIN.Items.Clear()
lstName.Items.Clear()
lstQuantity.Items.Clear()
lstSinglePrice.Items.Clear()
lstTotal.Items.Clear()
lstTotals.Items.Clear()
lstReceipt.Items.Clear()
lstInStock.Items.Clear()
lstAdditionalStock.Items.Clear()
'clears the total text box
txtTotalPrice.Text = ""
End Sub
Private Sub btnShowCodes_Click(sender As Object, e As EventArgs) Handles btnShowCodes.Click
Process.Start("receipt_orders.txt")
End Sub
End Class