Syntax to show message

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like to show you the syntax for VBA I debugged successfully:

Dim strHours As String, strRate As String
Dim hours As Single, rate As Single, gross As Single

strHours = InputBox("Enter the hours")
strRate = InputBox("Enter the rate")

hours = Val(strHours) 'converts a string to a number
rate = Val(strRate)

gross = hours * rate

MsgBox ("The gross pay is " & Str(gross)) 'Str(gross) converts a number to
a string

Tax = Val(25 / 100 * gross)

NetPay = Val(gross - Tax)

Dim FirstName As String
FirstName = InputBox("Enter the First Name")
MsgBox "The First Name is John"

Dim LastName As String
LastName = InputBox("Enter the Last Name")
MsgBox "The Last Name is Smith"

Dim FullName As String
FullName = InputBox("Enter the First Name" + "Enter the Last Name")
MsgBox "The Full Name is John Smith"

The following syntax that was supposed to display the MsgBox "Pay details
for John Smith are Gross = 400, Tax = 100, Net = 300" is incorrect:

Gross = "Gross = (gross)" + Tax = "Tax = (Tax)" + NetPay = "NetPay =
(NetPay)"")

Yours Sincerely
 
Craig,

Here's how I would do it...

---------------------
Dim hours As Currency
Dim rate As Currency
Dim gross As Currency
Dim Tax As Currency
Dim NetPay As Currency
Dim FirstName As String
Dim LastName As String
Dim FullName As String

hours = InputBox("Enter the hours")
rate = InputBox("Enter the rate")

gross = hours * rate
MsgBox "The gross pay is " & gross
Tax = .25 * gross
NetPay = .75 * gross

FirstName = InputBox("Enter the First Name")
MsgBox "The First Name is " & FirstName
LastName = InputBox("Enter the Last Name")
MsgBox "The Last Name is " & LastName
FullName = FirstName & " " & LastName
MsgBox "The Full Name is " & FullName

MsgBox "Pay details for " & FullName & " are Gross = " & gross & ",
Tax = " & Tax & ", Net = " & NetPay
 
Craig,

You did use the Str() function, in your original example... but your
original example is unnecessarily complicated. Why do you want to use
the Str() function if there is no need to?
 
Back
Top