Link to home
Start Free TrialLog in
Avatar of CxD
CxD

asked on

How do you call in a variable in a MsgBox?

I know this isn't a hard question but I'm a new at VB. This is my code:

Private Sub Command1_Click()
Dim answer As Integer
Dim milesover As Integer
Dim basefine As Integer
Dim mphfine As Integer

Text1.Text = milesover
basefine = 125
mphfine = 8
answer = basefine + (milesover * mphfine)

MsgBox "The violator owes: answer", vbCritical + vbOKOnly + vbInformation, "Promp"
End Sub

I'm trying to call in 'answer' so it says the violator owes: (X amount of money). I've tryed moving the quotation marks to before it but that didn't seem to work. I'm a newb at VB but I know some stuff about c++. Thanks for any help.
Avatar of appari
appari
Flag of India image

chang
MsgBox "The violator owes:" &  answer & ", vbCritical + vbOKOnly + vbInformation, "Promp"
to

MsgBox "The violator owes: answer", vbCritical + vbOKOnly + vbInformation, "Promp"
ASKER CERTIFIED SOLUTION
Avatar of appari
appari
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SylvainPouliot
SylvainPouliot

You were on the right track... but I suppose you had an error with Datatype Conversion...
Try


MsgBox "The violator owes: " + str(answer), vbCritical + vbOKOnly + vbInformation, "Promp"
Avatar of CxD

ASKER

Thanks for the help and fast responce! I know it was a easy question but I'm new at this :)
one extra double quote in my previous post
change to

MsgBox "The violator owes:" &  answer , vbCritical + vbOKOnly + vbInformation, "Promp"