Click to See Complete Forum and Search --> : can't calculate


kazooie21
October 19th, 1999, 09:11 PM
I have the following code:
[vbcode]Private Sub cmdCalc_Click()
Const strMsg As String = "The number of pennies was "
Dim sngDollars As Single, sngQuarters As Integer, sngDimes As Integer, sngNickels As Integer, sngNPennies As Integer
Dim intPennies As Integer
'assign values to variables
intPennies = Val(txtPennies.Text)
sngDollars = Val(lblNdollars.Caption)
sngQuarters = Val(lblNquarters.Caption)
sngDimes = Val(lblNdimes.Caption)
sngNickels = Val(lblNnickels.Caption)
sngNPennies = Val(lblNpennies.Caption)
'perform calculations
sngDollars = Val(intPennies) / 100
sngQuarters = Val(lblNdollars.Caption) - intPennies / 25
sngDimes = Val(lblNquarters.Caption) - intPennies / 10
sngNickels = Val(lblNdimes.Caption intPennies / 5
sngNPennies = Val(intPennies)
lblMsg.Caption = strMsg & Format(intPennies, "Number of Pennies")
End Sub

Private Sub Form_Load()
Const conPrompt As String = "Enter the number of pennies"
Const conTitle As String = "Number of Pennies"
Dim intPennies As Integer
intPennies = Val(InputBox("Enter the number of pennies", "Number of Pennies"))
'center the form
frmJpennies.Top = (Screen.Height - frmJpennies.Height) / 2
frmJpennies.Left = (Screen.Width - frmJpennies.Width) / 2
End Sub

I unable to calculate the number of pennies. AM I doing something wrong? I KNOW this is the right formula. Furthermore, when I enter the number of pennies into the input box, it doesn't show up on the form.

kazooie21

Vlad Chapranov
October 20th, 1999, 07:33 AM
Use CInt, CSng and so on instead of Val, like this:
intPennies = CInt(txtPennies.Text)
sngDollars = CSng(lblNdollars.Caption)
Vlad