Electro-Team: Interesting Education Visual Basic 2010
Electro-Team: Interesting Education Visual Basic 2010
Functions
Accept input and return a value. There are two types
MsgBox ( ) Function
Produce a pop-up message box and prompt the user to click on a command button. Format:
MsgBox(Prompt, Style Value, Title)
Prompt: the message itself. Style Value: determine what type of command buttons appear.
Styles Value
Style Value
0
Named Constant
vbOkOnly
Buttons Displayed
Ok button
1
2 3 4 5
vbOkCancel
vbAbortRetryIgnore vbYesNoCancel vbYesNo vbRetryCancel
Example
MsgBox("Hello World", vbOKCancel, "HW-Program")
Return Values
Value
1 2 3 4 5 6 7
Named Constant
vbOk vbCancel vbAbort vbRetry vbIgnore vbYes vbNo
Button Clicked
Ok button Cancel button Abort button Retry button Ignore button Yes button No button
MessageBox.Show("OK button")
Else MessageBox.Show("Cancel button") End If
32
48 64
vbQuestion
vbExclamation vbInformation
Ex: InputBox
Dim txt As String txt = Microsoft.VisualBasic.InputBox("What is your name?", "Names") If txt <> "" Then
MessageBox.Show(txt)
Else MessageBox.Show("No Message") End If
Example
Dim txt As String txt = Microsoft.VisualBasic.InputBox("Enter your phrase") MsgBox(Mid(txt, 2, 6))
Format:
Chr(ASCII code)
Chr(65)=A
Asc(Character)
Asc("B")=66