Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27329

Vending Machine

$
0
0
I'm creating a vending machine App to vend chips. I've used 3 labels, 2 buttons, and 2 text boxes however I can't get the app to work correctly or do anything for that matter. I don't see where I've gone wrong... Maybe another set of eyes could identify the culprit.. Thanks

Public Class ChipsVend

Dim ChipsCount As Integer
Dim TotalCost As Decimal = 0

Private Sub ChipsVend_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

ChipsCount = 50
Label1.Text = "Crisps Remaining = " & ChipsCount.ToString
If ChipsCount = 0 Then
MessageBox.Show("Item Not Avaliable For Purchase")
Button1.Enabled = False
End If
Label2.Text = ""
Label3.Text = "Enter amount paid:"
Label3.Visible = False
txtAmtRemove.Visible = False
btnPay.Enabled = False
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
If txtAmtRemove.Text <> "" AndAlso CInt(txtAmtRemove.Text) > 0 Then
If ChipsCount - CInt(txtAmtRemove.Text) < 0 Then
MessageBox.Show("you may only remove up to " & ChipsCount.ToString & " Chips")
txtAmtRemove.Focus()
txtAmtRemove.Text = ChipsCount.ToString
txtAmtRemove.SelectAll()
Else
ChipsCount -= CInt(txtAmtRemove.Text)
If ChipsCount = 0 Then
Button1.Enabled = False
End If
Label1.Text = "Chips Remaining = " & ChipsCount.ToString
TotalCost = CDec(CInt(txtAmtRemove.Text) * 1.25)
Label2.Text = "Cost for " & txtAmtRemove.Text & " Chips = " & FormatCurrency(TotalCost)
txtAmtRemove.Text = ""
Label3.Visible = True
txtAmtRemove.Visible = True
txtAmtRemove.Focus()
btnPay.Enabled = True
End If
Else
MessageBox.Show("Enter Quantity of Items")
txtAmtRemove.Focus()
txtAmtRemove.SelectAll()
End If
End Sub

Private Sub btnPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim AmtPaid As Decimal = 0

AmtPaid = CDec(txtAmtRemove.Text)

If AmtPaid >= TotalCost Then
MessageBox.Show("your change = " & FormatCurrency(AmtPaid - TotalCost))
txtAmtRemove.Text = ""
txtAmtRemove.Visible = False
Label3.Visible = False
btnPay.Enabled = False
Else
MessageBox.Show("Please Deposit More Money For Purchase")
txtAmtRemove.Focus()
txtAmtRemove.SelectAll()
End If
txtAmtRemove.Focus()


End Sub
End Class

Viewing all articles
Browse latest Browse all 27329

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>