Hi, Im doing a project in my class where i have to make code. i have to make a spread sheet that will control the sales that are taking place. The cash till has to add up the total cost of the items being bought, take in the input of how much the customer is paying with, then give the amount of change that should be returned down to the penny. I feel like i have most of the information that is needed but i cant get it to add up the total cost of the items being bought, and it won't give me the change i need.
This is what i have so far:

Dim Cost As Currency

Private Sub CommandButton12_Click()
'assume Burger and Pop = 3.00
Cost = 3
TextBox1.Value = TextBox1.Value & vbNewLine & "Burger and Pop $" & Cost
TextBox3.Value = Cost
End Sub

Private Sub CommandButton13_Click()
 TextBox1.Text = ""
 TextBox2.Text = ""
 TextBox3.Text = ""
End Sub

Private Sub CommandButton14_Click()
'assume chocolate bar = .90
Cost = 0.9
TextBox1.Value = TextBox1.Value & vbNewLine & "Chocolate Bar $" & Cost
TextBox3.Value = Cost
End Sub

Private Sub CommandButton15_Click()
'assume hot dog = 1.25'
Cost = 1.25
TextBox1.Value = TextBox1.Value & vbNewLine & "Hot Dog $" & Cost
TextBox3.Value = Cost
End Sub

Private Sub CommandButton2_Click()
'assume burger = 2.25'
Cost = 2.25
TextBox1.Value = TextBox1.Value & vbNewLine & "Burger $" & Cost
TextBox3.Value = Cost
End Sub

Private Sub CommandButton3_Click()
'assume HotDog And Pop = 2.00
Cost = 2
TextBox1.Value = TextBox1.Value & vbNewLine & "HotDog and Pop $" & Cost
TextBox3.Value = Cost
End Sub

Private Sub CommandButton5_Click()
'assume cheese = .30
Dim cheese As Currency

cheese = MsgBox("Customer must have a burger or hotdog")
Cost = 0.3
TextBox1.Value = TextBox1.Value & vbNewLine & "cheese $" & Cost
TextBox3.Value = Cost
End Sub

Private Sub CommandButton6_Click()
'assume Pop = .99'
Cost = 0.99

TextBox1.Value = TextBox1.Value & vbNewLine & "Pop $" & Cost
TextBox3.Value = Cost
End Sub

Private Sub CommandButton9_Click()
Dim AmtRec As Currency
Dim EndVal As String
Dim Change As Currency
Dim Saletotal As Currency

AmtRec = InputBox("Money Recieved From Customer")
TextBox3.Value = Saletotal

'Find out how much is owed to customer

Change = AmtRec - Saletotal

Do While Change > 0
    If Change >= 10 Then
        EndVal = vbNewLine + (10 - Saletotal)
        End If
     If Change >= 5 Then
        EndVal = vbNewLine + (5 - Saletotal)
        End If
       If Change >= 2 Then
        EndVal = vbNewLine + (2 - Saletotal)
        End If
         If Change >= 1 Then
        EndVal = vbNewLine + (1 - Saletotal)
        End If
         If Change >= 0.25 Then
        EndVal = vbNewLine + (0.25 - Saletotal)
        End If
         If Change >= 0.1 Then
       EndVal = vbNewLine + (0.1 - Saletotal)
        End If
         If Change >= 0.05 Then
        EndVal = vbNewLine + (0.05 - Saletotal)
        End If
         If Change >= 0.01 Then
        EndVal = vbNewLine + (0.01 - Saletotal)
        End If
Loop
End

TextBox2.Value = TextBox2.Value & vbNewLine & "Amount Recieved: $" & AmtRec
TextBox2.Value = TextBox2.Value & vbNewLine & "Change Due: $" & Change
TextBox2.Value = TextBox2.Value & vbNewLine & "Change to Give Customer: $" & EndVal
End Sub

Are you using VBA as your language or VB6?

Also, make use of the format function -

Cost = Format("3", "###.00")

This will give you a decimal value to obtain the cents value as well.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.