darnold


Im trying to do the following:

I created some command buttons that has the number 1, 2, 3, 4 on it, like a keypad or a calculator. When I press the button I want it to give a value (variable) of 1, 2, 3, 4, etc. At the same time if I press 1 and 4 on the keypad, Id like it to indicate 14 or 9 and 8 I would get 98.

What I'm trying to do is:
Button 1 = 10 * (number pad system stated above) + Enter button = 0
and/or
Button 2 = 20 * (number pad system stated above) + Enter button = 0
and/or
Button 3 = 30 * (number pad system stated above) + Enter button = 0
= Total
Thanks!



Re: New to Visual Basic

TilakGopi


Hi,

Making use of textbox or string in this scenario will make your job,i suppose.

Use a text box, when ever a button pressed , do

TextBox1.Text = NumberofTheButton.ToString() & TextBox1.Text

or

numberstring = NumberOfTheButton.ToString() + numberString

when you want the value ,convert the textbox value or sting to integer or long or what ever want.

Hope this works out for your requirement.

Thanks,

Ch.T.Gopi Kumar.







Re: New to Visual Basic

Muhammad Akhtar Shiekh

Hi Dear,

The simplest way to perform this task will be to save the each button value in a single string and whenever you want its integer or float representation cast it into the integer.

eg.

Code Snippet

Dim str As String

Dim Number As Integer

str = ""

str = str + "1" ' On Button 1 Press

str = str + "2" ' On Button 2 Press

'and when u want integer representation of the string cast the string into integer

Number = CInt(str)

Happy Programming!







Re: New to Visual Basic

darnold

Thanks for the help... Im not to sure on what you mean and where to put it though... This is what I have now!

Option Compare Database

Dim str As String
Dim Number As Integer

Private Sub cmdOne_Click()
str = ""
str = str + "1"
Number = CInt(str)
End Sub


Private Sub cmdTwo_Click()
str = ""
str = str + "2"
Number = CInt(str)
End Sub


Private Sub cmdThree_Click()
str = ""
str = str + "3"
Number = CInt(str)
End Sub

Private Sub cmdEnter_Click()

End Sub


Private Sub cmdStdBurger_Click()
StdBurger = 1.99
End Sub

Private Sub cmdDlxBurger_Click()
DlxBurger = 2.99
End Sub

Private Sub cmdSmFries_Click()
SmFries = 0.99
End Sub

Private Sub cmdSubTotal_Click()
txtSubTotal =
End Sub

Private Sub cmdTotal_Click()
txtTax = txtSubTotal * 0.05
txtTotal = (txtSubTotal * 0.05) + txtSubTotal
End Sub





Re: New to Visual Basic

TilakGopi

Hi darnold,

I'm posting the modified code of yours, to achieve what you wanted.Check this,let me know if any issues with this.


Dim str As String

Dim Number As Integer

Private Sub Form1_Load()
str =
""

End Sub

Private Sub cmdOne_Click()
str = str +
"1"

Number = CInt(str)
End Sub

Private Sub cmdTwo_Click()
str = str +
"2"

Number = CInt(str)
End Sub

Private Sub cmdThree_Click()
str = str +
"3"

Number = CInt(str)
End Sub

Private Sub cmdEnter_Click()
End Sub

Private Sub cmdStdBurger_Click()
StdBurger = 1.99
End Sub

Private Sub cmdDlxBurger_Click()
DlxBurger = 2.99
End Sub

Private Sub cmdSmFries_Click()
SmFries = 0.99
End Sub

Private Sub cmdSubTotal_Click()
'You didn't post this line completely
txtSubTotal =
End Sub

Private Sub cmdTotal_Click()
txtTax = txtSubTotal * 0.05
txtTotal = (txtSubTotal * 0.05) + txtSubTotal
End Sub


If you have any issues with the above code,please post the complete code without missing any line.

Thanks,

Ch.T.Gopi Kumar.






Re: New to Visual Basic

darnold

Thanks for the help... I think I figured it out before you posted back... but I appreciate you getting back to me.

Here is what I got going now.

Option Compare Database

Dim str As String
Dim Number As Integer

Private Sub cmdCashOut_Click()
txtChange = txtAmountRcvd - txtTotal
If Val(txtAmountRcvd) < Val(txtTotal) Then
MsgBox ("CUSTOMER STILL OWES: Please collect the correct amount.")
End If
txtAmountRcvd = ""
str = ""
End Sub

Private Sub cmdD10_Click()
str = str + "10"
txtAmountRcvd = str
End Sub

Private Sub cmdD20_Click()
str = str + "20"
txtAmountRcvd = str
End Sub

Private Sub cmdD5_Click()
str = str + "5"
txtAmountRcvd = str
End Sub

Private Sub cmdOne_Click()
str = str + "1"
txtAmountRcvd = str
End Sub

Private Sub cmdTwo_Click()
str = str + "2"
txtAmountRcvd = str
End Sub

Private Sub cmdThree_Click()
str = str + "3"
txtAmountRcvd = str
End Sub

Private Sub cmdFour_Click()
str = str + "4"
txtAmountRcvd = str
End Sub

Private Sub cmdFive_Click()
str = str + "5"
txtAmountRcvd = str
End Sub

Private Sub cmdSix_Click()
str = str + "6"
txtAmountRcvd = str
End Sub

Private Sub cmdSeven_Click()
str = str + "7"
txtAmountRcvd = str
End Sub

Private Sub cmdEight_Click()
str = str + "8"
txtAmountRcvd = str
End Sub

Private Sub cmdNine_Click()
str = str + "9"
txtAmountRcvd = str
End Sub

Private Sub cmdZero_Click()
str = str + "0"
txtAmountRcvd = str
End Sub

Private Sub cmdDecimal_Click()
str = str + "."
txtAmountRcvd = str
End Sub

Private Sub cmdEnter_Click()
txtTax = txtSubTotal * 0.05
txtTotal = (txtSubTotal * 0.05) + txtSubTotal
End Sub

Private Sub cmdStdBurger_Click()
If IsNull(txtSubTotal) Then
txtSubTotal = 1.99
Else
txtSubTotal = txtSubTotal + 1.99
End If
End Sub

Private Sub cmdDlxBurger_Click()
If IsNull(txtSubTotal) Then
txtSubTotal = 2.99
Else
txtSubTotal = txtSubTotal + 2.99
End If
End Sub

Private Sub cmdSmFries_Click()
If IsNull(txtSubTotal) Then
txtSubTotal = 0.99
Else
txtSubTotal = txtSubTotal + 0.99
End If
End Sub

Private Sub cmdLrgFries_Click()
If IsNull(txtSubTotal) Then
txtSubTotal = 1.49
Else
txtSubTotal = txtSubTotal + 1.49
End If
End Sub

Private Sub cmdSmSoda_Click()
If IsNull(txtSubTotal) Then
txtSubTotal = 1.25
Else
txtSubTotal = txtSubTotal + 1.25
End If
End Sub

Private Sub cmdLrgSoda_Click()
If IsNull(txtSubTotal) Then
txtSubTotal = 1.75
Else
txtSubTotal = txtSubTotal + 1.75
End If
End Sub

Private Sub cmdClrAll_Click()
txtSubTotal = "$0.00 "
txtTax = "$0.00 "
txtTotal = "$0.00 "
txtAmountRcvd = "$0.00 "
txtChange = "$0.00 "
str = ""
End Sub

Private Sub cmdExit_Click()
DoCmd.Close acForm, "frmBurgerBarn"
End Sub