In Put Out Put Dialog Boxes
In Put Out Put Dialog Boxes
Use of
MsgBox function to display information and
MsgBox
Used to output information to the user
Syntax:
(3)
Dim str as String
str = MsgBox ( Proceed?, vbQuestion + vbYesNo )
If str = vbYes Then
' Take action(s) to proceed
End If
' This displays a message box with the prompt proceed? ,
' a question mark icon (vbQuestion) and two command buttons
' labeled Yes and No (vbYesNo ).
' The answer is placed in variable str.
(4)
Msgbox ( " Result is " & FtoC( f ) )
(5)
MsgBox ( " Hours worked = " & Hours & "Rate of pay = " & Rate & _
vbNewLine & "Wages = " & Wage )
' Underscore ( _ ) allows statement to be continued to next line. vbNewLine moves cursor to next line.
B. Reinhardt, Computing, Faculty of Engineering, DIT, Bolton St.
InputBox
Used to get input from the user.
Syntax:
Prompt is the required message in the input box, title is the title for the input box and
default is the default value to be displayed in the input box. Both title and default are
optional.
Example:
(1)
Dim sName as String
sName = InputBox( "Enter your name > ", "Name", "Joe" )
Enter your name is the prompt, Name is the inputbox title and Joe is the default
value.
InputBox returns a string value, here placed in variable sName.
Inputting numbers
To get the user to input a number instead of text, you must convert the string value into a
number using the Val function.
Example:
Dim hh as String, hours as Integer
hh = InputBox ( " Enter hours worked > ", "Hours worked", 40 )
hours = Val(hh)
'Converts string number into a real number. Example "45" is converted into 45.
Or
hh = val( InputBox ( " Enter hours worked > ", "Hours worked", 40 ) )
Note to convert a number to a string use the Str() function. Example Str( 456) returns
"456"
B. Reinhardt, Computing, Faculty of Engineering, DIT, Bolton St.