.vb keeps giving 0 as total amount you need to pay - vb.net

So i had to make a program where you can buy stuff when clicking on the buttons, when the amount totals more than 1k you can roll for a discount. This all goes well until I have to use a label to indicate the total amount you need to pay minus the discount. This label keeps staying 0, no matter what. Could anyone help?
Form1 for the "shop":
Public Class Form1
Dim i As Integer = 1
Dim totaalbedrag As Double
Public Sub Actie()
If Val(TextBox3.Text) > 1000 And i = 1 Then
If MsgBox("Wil je strijden voor korting? Zo niet zal deze pop-up niet meer komen dus maak je keuze!", vbYesNo) = vbYes Then
Me.Hide()
Form2.Show()
Else
i = 0
End If
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label6.Text = Val(Label6.Text) + 1
TextBox1.Text = Val(TextBox1.Text) + 250
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
Actie()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Label7.Text = Val(Label7.Text) + 1
TextBox2.Text = Val(TextBox2.Text) + 300
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
Actie()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TextBox4.Text = korting & " procent"
totaalbedrag = totaalbedrag - totaalbedrag * korting / 100
TextBox5.Text = Val(totaalbedrag)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
MsgBox("Gefeliciteerd met de aankoop van totaal " & totaalbedrag & " euro!!", vbCritical)
End
End Sub
End Class
Form2 for the gambling:
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
korting = Label1.Text
MsgBox("Gefeliciteerd, je hebt " & korting & " procent korting gekregen!", vbCritical)
Me.Hide()
Form1.Show()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.Text = Int(Rnd() * 10)
End Sub
End Class
Module to have a value as a public one:
Module Module1
Public korting As Integer = 0
End Module
You basically should pay attention to this code of line since I think this is where all goes wrong:
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TextBox4.Text = korting & " procent"
totaalbedrag = totaalbedrag - totaalbedrag * korting / 100
TextBox5.Text = Val(totaalbedrag)
End Sub

I am not at all sure of the timer event in Form1. Every time it ticks the discount is reapplied. If the program runs long enouth totaalbedrag will be very small.
I used .ToString("C") or "c" to display the result as currency. Some of displays are probably not currency. Change to the appropriate format string. https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings
For Random numbers please switch to the .net Random class.
Public Class Form1
Dim i As Integer = 1
Dim totaalbedrag As Decimal
Public Sub Actie()
Dim tb3Dec As Decimal
If Decimal.TryParse(TextBox3.Text, tb3Dec) AndAlso tb3Dec > 1000 AndAlso i = 1 Then
If MsgBox("Do you want to compete for a discount? If not, this pop-up will not come again so make your choice!", vbYesNo) = vbYes Then
Me.Hide()
Form2.Show()
Else
i = 0
End If
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
TextBox4.Text = korting & " procent"
totaalbedrag = totaalbedrag - totaalbedrag * korting / 100
TextBox5.Text = totaalbedrag.ToString("C")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim tb1Dec As Decimal
If Not Decimal.TryParse(TextBox1.Text, tb1Dec) Then
MessageBox.Show("Please enter a valid number in TextBox1.")
Exit Sub
End If
Dim tb2Dec As Decimal
If Not Decimal.TryParse(TextBox2.Text, tb2Dec) Then
MessageBox.Show("Please enter a valid number in TextBox2")
Exit Sub
End If
Label6.Text = (CDec(Label6.Text) + 1).ToString
TextBox3.Text = (tb1Dec + tb2Dec).ToString("c")
TextBox1.Text = (tb1Dec + 250).ToString("C")
Actie()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Label7.Text = (CDec(Label7.Text) + 1).ToString("c")
Dim tb2Dec As Decimal
If Not Decimal.TryParse(TextBox2.Text, tb2Dec) Then
MessageBox.Show("Please enter a valid number in TextBox2")
Exit Sub
End If
Dim tb1Dec As Decimal
If Not Decimal.TryParse(TextBox1.Text, tb1Dec) Then
MessageBox.Show("Please enter a valid number in TextBox1")
Exit Sub
End If
TextBox2.Text = (tb2Dec + 300).ToString("C")
TextBox3.Text = (tb1Dec + tb2Dec).ToString("C")
Actie()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
MsgBox("Gefeliciteerd met de aankoop van totaal " & totaalbedrag & " euro!!", vbCritical)
End
End Sub
End Class
Public Class Form2
Private rand As New Random
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
korting = CInt(Label1.Text)
MsgBox("Gefeliciteerd, je hebt " & korting & " procent korting gekregen!", vbCritical)
Me.Hide()
Form1.Show()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Label1.Text = rand.Next(0, 101).ToString 'returns an integer 0 to 100
End Sub
End Class
This fixes the Option Strict violations but I have no idea it this works for you. Let us know which label is showing 0.

Related

How can I make a VB.NET MDAS Calculator?

I already have a code but I do not know how to add the MDAS function. Here is my code:
Public Class Form1
'variables-----------------------------------------------------------------------------
Dim inp As Double = 0
Dim oprtn As String
Dim expr As Boolean = False
'numbers and decimal input-----------------------------------------------------------------------------
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Number1.Click, Number9.Click, Number8.Click, Number7.Click, Number6.Click, Number5.Click, Number4.Click, Number3.Click, Number2.Click, Number0.Click, Period.Click
Dim num As Button = sender
If ((TextBox1.Text = "0") Or (expr)) Then
TextBox1.Clear()
TextBox1.Text = num.Text
expr = False
ElseIf (num.Text = ".") Then
If (Not TextBox1.Text.Contains(".")) Then
TextBox1.Text = TextBox1.Text + num.Text
End If
Else
TextBox1.Text = TextBox1.Text + num.Text
End If
End Sub
'operators button-----------------------------------------------------------------------------
Private Sub oprtrs(sender As Object, e As EventArgs) Handles PlusSign.Click, MinusSign.Click, MultiplySign.Click, DivideSign.Click
Dim operations As Button = sender
If (inp <> 0) Then
Equals.PerformClick()
expr = True
oprtn = operations.Text
Label1.Text = inp & " " & oprtn
Else
oprtn = operations.Text
inp = Double.Parse(TextBox1.Text)
expr = True
Label1.Text = inp & " " & oprtn
End If
End Sub
'equals button-----------------------------------------------------------------------------
Private Sub Equal_Click(sender As Object, e As EventArgs) Handles Equals.Click
Label1.Text = ""
Select Case oprtn
Case "+"
TextBox1.Text = (inp + Double.Parse(TextBox1.Text)).ToString()
Case "-"
TextBox1.Text = (inp - Double.Parse(TextBox1.Text)).ToString()
Case "*"
TextBox1.Text = (inp * Double.Parse(TextBox1.Text)).ToString()
Case "/"
TextBox1.Text = (inp / Double.Parse(TextBox1.Text)).ToString()
End Select
inp = Double.Parse(TextBox1.Text)
oprtn = ""
End Sub
'other buttons-----------------------------------------------------------------------------
Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Backspace.Click
If TextBox1.Text < " " Then
TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1 + 1)
Else
TextBox1.Text = Mid(TextBox1.Text, 1, Len(TextBox1.Text) - 1)
End If
End Sub
Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Clear.Click
TextBox1.Text = "0"
End Sub
Private Sub Button15_Click(sender As Object, e As EventArgs) Handles ClearEverything.Click
TextBox1.Text = "0"
Label1.Text = ""
End Sub
Private Sub Button20_Click(sender As Object, e As EventArgs) Handles Prcent.Click
Dim percent As Double
percent = Convert.ToDouble(TextBox1.Text) / Convert.ToDouble(100)
TextBox1.Text = System.Convert.ToString(percent)
End Sub
Private Sub Button21_Click(sender As Object, e As EventArgs) Handles SqrRoot.Click
Dim squared As Double
squared = Math.Sqrt(TextBox1.Text)
TextBox1.Text = System.Convert.ToString(squared)
Label1.Text = "Sqr(" & System.Convert.ToString(squared) & ")"
End Sub
Private Sub Button22_Click(sender As Object, e As EventArgs) Handles RaiseTwo.Click
Dim expo2 As Double
expo2 = Convert.ToDouble(TextBox1.Text) * Convert.ToDouble(TextBox1.Text)
TextBox1.Text = System.Convert.ToString(expo2)
End Sub
Private Sub Button23_Click(sender As Object, e As EventArgs) Handles RaiseThree.Click
Dim expo3 As Double
expo3 = Convert.ToDouble(TextBox1.Text) * Convert.ToDouble(TextBox1.Text) * Convert.ToDouble(TextBox1.Text)
TextBox1.Text = System.Convert.ToString(expo3)
End Sub
Private Sub Button24_Click(sender As Object, e As EventArgs) Handles OneOver.Click
Dim ov1 As Double
ov1 = Convert.ToDouble(1.0 / Convert.ToDouble(TextBox1.Text))
TextBox1.Text = System.Convert.ToString(ov1)
End Sub
End Class
Thats pretty much all I have done, it works as intended, BUT it does not follow MDAS which prioritizes Multiplication first followed by Division then Addition then Subtraction. My design goes like this:
I started with the interface first then code, I haven't really designed it yet. This is just to give you an idea what is already coded or included in the code. Every button functions as should be.
This is what David is talking about.
There is very little code needed.
Public Class ExpressionCalculator
Private Sub Buttons_Click(sender As Object, e As EventArgs) Handles ButtonPlus.Click, ButtonMultiply.Click, ButtonMinus.Click, ButtonDot.Click, ButtonDivide.Click, Button9.Click, Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, Button2.Click, Button10.Click, Button1.Click
Dim tb = DirectCast(sender, Button)
TextBox1.Text &= tb.Text
End Sub
Private Sub ButtonCalculate_Click(sender As Object, e As EventArgs) Handles ButtonCalculate.Click
Dim table = New DataTable()
Dim result = table.Compute(TextBox1.Text, Nothing)
TextBox1.Text = result.ToString
End Sub
End Class

Handles clause requires a WithEvents variable defined in the containing type or one of its base type

So I'm very new to coding and especially Visual Basic, and after fidgeting around for a bit with open source code I only seem to have one recurring problem in my current Form1.vb file; Handles clause requires a WithEvents variable defined in the containing type or one of its base type. This is what is looks like:
Public Class Form1
Dim Firstnum As Decimal
Dim Secondnum As Decimal
Dim Operations As Integer
Dim Operator_selector As Boolean = False
Private lblHold As Object
Public Property TextBox1 As Object
WithEvents Btn1_click As Button
Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "1"
Else
TextBox1.Text = "1"
End If
End Sub
Private Sub Btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "2"
Else
TextBox1.Text = "2"
End If
End Sub
Private Sub Btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "3"
Else
TextBox1.Text = "3"
End If
End Sub
Private Sub Btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "4"
Else
TextBox1.Text = "4"
End If
End Sub
Private Sub Btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "5"
Else
TextBox1.Text = "5"
End If
End Sub
Private Sub Btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "6"
Else
TextBox1.Text = "6"
End If
End Sub
Private Sub Btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "7"
Else
TextBox1.Text = "7"
End If
End Sub
Private Sub Btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "8"
Else
TextBox1.Text = "8"
End If
End Sub
Private Sub Btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "9"
Else
TextBox1.Text = "9"
End If
End Sub
Private Sub Btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click
If TextBox1.Text <> "0" Then
TextBox1.Text += "0"
End If
End Sub
Private Sub BtnPoint_Click(sender As Object, e As EventArgs) Handles btnPoint.Click
If Not (TextBox1.Text.Contains(".")) Then
TextBox1.Text += "."
End If
End Sub
Private Sub BtnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
TextBox1.Text = "0"
End Sub
Private Sub BtnPlus_Click(sender As Object, e As EventArgs) Handles btnPlus.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_selector = True
Operations = 1 'For addition
lblHold.Text = Firstnum.ToString + "+"
End Sub
Private Sub BtnMinus_Click(sender As Object, e As EventArgs) Handles btnMinus.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_selector = True
Operations = 2 'For subtraction
lblHold.Text = Firstnum.ToString + "-"
End Sub
Private Sub BtnMult_Click(sender As Object, e As EventArgs) Handles btnMult.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_selector = True
Operations = 3 'For multiplication
lblHold.Text = Firstnum.ToString + "*"
End Sub
Private Sub BtnDiv_Click(sender As Object, e As EventArgs) Handles btnDiv.Click
Firstnum = TextBox1.Text
TextBox1.Text = "0"
Operator_selector = True
Operations = 4 'For division
lblHold.Text = Firstnum.ToString + "+"
End Sub
Private Sub BtnEqual_Click(sender As Object, e As EventArgs) Handles btnEqual.Click
If Operator_selector = True Then
Secondnum = TextBox1.Text
If Operations = 1 Then
TextBox1.Text = Firstnum + Secondnum
ElseIf Operations = 2 Then
TextBox1.Text = Firstnum - Secondnum
ElseIf Operations = 3 Then
TextBox1.Text = Firstnum * Secondnum
Else
If Secondnum = 0 Then
TextBox1.Text = "Error!"
Else
TextBox1.Text = Firstnum / Secondnum
End If
Operator_selector = False
End If
lblHold.Text = ""
End If
End Sub
End Class
Now I'm wondering what I have to do to get it right and make this error disappear. I tried using something around the lines of "WithEvents Btn1_click As Button" but it doesn't do anything. It also says "Btn1_click is already declared as 'Private WithEvents Btn1_click As Button' in this class." I'm truly a noob, so please don't throw hardcore coding terms at me but just the simple stuff :P
Many thanks in advance!
The Handles clause you see on those methods indicates that that method will be executed when the specified event of the object currently assigned to the specified variable is raised. For example:
Private Sub Btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click
means that the Btn2_Click method will be executed when the object assigned to the btn2 variable raises its Click event. The error message flags this line:
Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
and it's telling you that you have no btn1 variable declared WithEvents.
When you add a control to your form in the designer, it automatically adds a variable with the specified name and declares it WithEvents. You can see that variable if you open the designer code file, which you can access via the Solution Explorer if you click the Show All Files button first. You can declare your own variables WithEvents but this:
WithEvents Btn1_click As Button
is not using the correct name for a start and it is also useless because it doesn;t have anything assigned to it. You'd need to create a Button object, assign it to the variable and add it to the form, which you haven't done.
The solution would be to simply add a Button to the form with that name.

Vb.net navigation

I'm, trying to navigate through my records but when I press the buttons, nothing happens. I'm using Jet 4.0 and an Access DB.
I'm not sure what I'm doing wrong but if anyone can help me in the right direction, it would be appreciated.
Code:
Private Sub showData(ByVal CurrentRow)
CurrentRow = 0
Dad.Fill(dst, "patrolDB")
TextBox27.Text = dst.Tables("patrolDB").Rows(CurrentRow)("ID").ToString.ToUpper
DateTimePicker1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroldate").ToString.ToUpper
TextBox2.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroltime").ToString.ToUpper
ComboBox1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patroltype").ToString.ToUpper
ComboBox2.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolsite").ToString.ToUpper
ComboBox4.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolloc").ToString.ToUpper
ComboBox3.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolofficer").ToString.ToUpper
RichTextBox1.Text = dst.Tables("patrolDB").Rows(CurrentRow)("patrolnotes").ToString.ToUpper
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If CurrentRow <> dst.Tables("patrolDB").Rows.Count - 1 Then
CurrentRow += 1
showData(CurrentRow)
End If
MsgBox("You've reached the last record.")
End Sub
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
index = 0
showData(CurrentRow)
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
If CurrentRow <> 0 Then
CurrentRow -= 1
showData(CurrentRow)
End If
MsgBox("You've reached the first record.")
End Sub
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
CurrentRow = dst.Tables("patrolDB").Rows.Count - 1
showData(CurrentRow)
End Sub
Dim table As DataTable
Private Sub LoadData()
CurrentRow = 0
Dad.Fill(dst, "patrolDB")
table = dst.Tables("patrolDB") 'for the comfort
ShowCurrentRow()
End Sub
Private Sub ShowCurrentRow()
TextBox27.Text = table.Rows(CurrentRow)("ID").ToString.ToUpper
DateTimePicker1.Text = table.Rows(CurrentRow)("patroldate").ToString.ToUpper
TextBox2.Text = table.Rows(CurrentRow)("patroltime").ToString.ToUpper
ComboBox1.Text = table.Rows(CurrentRow)("patroltype").ToString.ToUpper
ComboBox2.Text = table.Rows(CurrentRow)("patrolsite").ToString.ToUpper
ComboBox4.Text = table.Rows(CurrentRow)("patrolloc").ToString.ToUpper
ComboBox3.Text = table.Rows(CurrentRow)("patrolofficer").ToString.ToUpper
RichTextBox1.Text = table.Rows(CurrentRow)("patrolnotes").ToString.ToUpper
End Sub
'go to next
Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If CurrentRow <> table.Rows.Count - 1 Then
CurrentRow += 1
ShowCurrentRow()
Else MsgBox("You've reached the last record.")
End If
End Sub
'go to prev
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
If CurrentRow <> 0 Then
CurrentRow -= 1
ShowCurrentRow()
Else MsgBox("You've reached the first record.")
End If
End Sub
'go to start
Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
index = 0
ShowCurrentRow()
End Sub
'go to last
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
CurrentRow = table.Rows.Count - 1
ShowCurrentRow()
End Sub

calculation is only performed once on food ordering form (VB)

I am making a food ordering form, and I am having trouble with the calculations. Every time a hotdog is ordered the form is supposed to add the cost to the total amount, so one hotdog is 2 dollars, add another and it says 4 dollars, etc. But it only performs the calculation once, so no matter how many items I add to the order the price stays the same, as if I had only ordered one.
I don't get any errors at runtime so it must be a logical error. Here is the full code. I don't know what other information I should give at this moment. All help is appreciated.
Public Class DroneDogs
Dim DogChoice As String
Dim condiment1 As String
Dim condiment2 As String
Dim condiment3 As String
Const DBL_TAX_RATE As Double = 0.07
Const DBL_DRONE_DOG As Double = 1.99
Dim intNumDog As Integer
Dim dblSubTotal As Double
Dim dblSalesTax As Double
Dim dblTotalCost As Double
Private Sub btnAddCustomer_Click(sender As Object, e As EventArgs) Handles btnAddCustomer.Click
cboCurrentCustomers.Items.Add(txtAddCustomer.Text)
End Sub
Private Sub optBeef_CheckedChanged(sender As Object, e As EventArgs) Handles optBeef.CheckedChanged
If (optBeef.Checked) Then
DogChoice = "Beef Dog"
End If
End Sub
Private Sub optPork_CheckedChanged(sender As Object, e As EventArgs) Handles optPork.CheckedChanged
If (optPork.Checked) Then
DogChoice = "Pork Dog"
End If
End Sub
Private Sub optTurkey_CheckedChanged(sender As Object, e As EventArgs) Handles optTurkey.CheckedChanged
If (optTurkey.Checked) Then
DogChoice = "Turkey Dog"
End If
End Sub
Private Sub chkKetchup_CheckedChanged(sender As Object, e As EventArgs) Handles chkKetchup.CheckedChanged
If (chkKetchup.Checked) Then
condiment1 = " + Ketchup"
Else
condiment1 = Nothing
End If
End Sub
Private Sub chkMustard_CheckedChanged(sender As Object, e As EventArgs) Handles chkMustard.CheckedChanged
If (chkMustard.Checked) Then
condiment2 = " + Mustard"
Else
condiment2 = Nothing
End If
End Sub
Private Sub chkRelish_CheckedChanged(sender As Object, e As EventArgs) Handles chkRelish.CheckedChanged
If (chkRelish.Checked) Then
condiment3 = " + Relish"
Else
condiment3 = Nothing
End If
End Sub
Private Sub btnAddDog_Click(sender As Object, e As EventArgs) Handles btnAddDog.Click
intNumDog = +1
dblSubTotal = intNumDog * DBL_DRONE_DOG
dblSalesTax = dblSubTotal * DBL_TAX_RATE
dblTotalCost = dblSubTotal + dblSalesTax
txtSub.Text = dblSubTotal.ToString("c2")
txtTax.Text = dblSalesTax.ToString("c2")
txtTotal.Text = dblTotalCost.ToString("c2")
Dim addCondiment As String = condiment1 + condiment2 + condiment3
If (DogChoice = "Beef Dog") Or
(DogChoice = "Pork Dog") Or
(DogChoice = "Turkey Dog") Then
lstOrder.Items.Add(DogChoice + addCondiment + ": " + txtTotal.Text)
Else
MsgBox("Please select a Hot Dog type.")
End If
End Sub
Private Sub btnClearOrder_Click(sender As Object, e As EventArgs) Handles btnClearOrder.Click
lstOrder.Items.Clear()
txtSub.Clear()
txtTax.Clear()
txtTotal.Clear()
chkKetchup.Checked = 0
chkMustard.Checked = 0
chkRelish.Checked = 0
optBeef.Checked = 0
optPork.Checked = 0
optTurkey.Checked = 0
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Exits the program
If MessageBox.Show("Do you want to exit the DroneDogs application?", "DroneDogs",
MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
= DialogResult.Yes Then
Application.Exit()
End If
End Sub
Private Sub btnOrderComplete_Click(sender As Object, e As EventArgs) Handles btnOrderComplete.Click
Receipt.Show()
End Sub
Private Sub btnRemoveDog_Click(sender As Object, e As EventArgs) Handles btnRemoveDog.Click
lstOrder.Items.Remove(lstOrder.SelectedItem)
End Sub
End Class
I think the problem is with the line
intNumDog = +1
In this line, you always set intNumDog to the value of +1. This is the same as:
intNumDog = 1
You want to add one to the value of intNumDog:
intNumDog += 1

How to store last button clicked and add to listbox

So I'm doing this calculator program and need the numbers, the operator used and the "=" sign to show up in the listbox so "1 + 1 = 2" should show up. I have the calculator working and can move items to the listbox, but can't figure out how to remember the button that was clicked to get the outcome and move it over also.
Option Explicit On
Option Strict On
Option Infer Off
Public Class Form1
Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click
Result.Text = CStr(Val(NumOne.Text) + Val(NumTwo.Text))
End Sub
Private Sub ButtonSub_Click(sender As Object, e As EventArgs) Handles ButtonSub.Click
Result.Text = CStr(Val(NumOne.Text) - Val(NumTwo.Text))
End Sub
Private Sub ButtonMul_Click(sender As Object, e As EventArgs) Handles ButtonMul.Click
Result.Text = CStr(Val(NumOne.Text) * Val(NumTwo.Text))
End Sub
Private Sub ButtonDiv_Click(sender As Object, e As EventArgs) Handles ButtonDiv.Click
Result.Text = CStr(Val(NumOne.Text) / Val(NumTwo.Text))
'outputs a message box telling the user to correct the division by 0, also displays a blank result box instead of NaN
If CDbl(NumTwo.Text) = Val(0) Then
Result.Text = ""
MessageBox.Show("You cannot divide by 0, please input another number")
End If
End Sub
Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
Me.Close()
End Sub
Private Sub ButtonSave_Click(sender As Object, e As EventArgs) Handles ButtonSave.Click
ListBox1.Items.Add(NumOne.Text & NumTwo.Text & Result.Text)
End Sub
End Class
As far as you just need to store one character, you can rely on the Tag property of ListBox1 (basically, a black box where you can store anything you want). Sample code:
Private Sub ButtonAdd_Click(sender As Object, e As EventArgs) Handles ButtonAdd.Click
Result.Text = CStr(Val(NumOne.Text) + Val(NumTwo.Text))
ListBox1.Tag = "+"
End Sub
Private Sub ButtonSub_Click(sender As Object, e As EventArgs) Handles ButtonSub.Click
Result.Text = CStr(Val(NumOne.Text) - Val(NumTwo.Text))
ListBox1.Tag = "-"
End Sub
Private Sub ButtonMul_Click(sender As Object, e As EventArgs) Handles ButtonMul.Click
Result.Text = CStr(Val(NumOne.Text) * Val(NumTwo.Text))
ListBox1.Tag = "x"
End Sub
Private Sub ButtonDiv_Click(sender As Object, e As EventArgs) Handles ButtonDiv.Click
Result.Text = CStr(Val(NumOne.Text) / Val(NumTwo.Text))
'outputs a message box telling the user to correct the division by 0, also displays a blank result box instead of NaN
If CDbl(NumTwo.Text) = Val(0) Then
Result.Text = ""
MessageBox.Show("You cannot divide by 0, please input another number")
End If
ListBox1.Tag = "/"
End Sub
Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
Me.Close()
End Sub
Private Sub ButtonSave_Click(sender As Object, e As EventArgs) Handles ButtonSave.Click
ListBox1.Items.Add(NumOne.Text & ListBox1.Tag.ToString() & NumTwo.Text & "=" & Result.Text)
End Sub