|
| Introduction to VB Function |
|
VB Functions
|
|
The main purpose of the functions is to accept certain inputs and pass them on to the main program to finish the execution and also are similar to normal procedures but. They are two types of function, the functions created by the programmers and the built-in functions(or internal functions).
The general format of a function is
|
|
|
|
where arguments are values that are passed on to functions.
In this lesson, we are going to learn two very basic but useful internal functions, i.e. InputBox ( ) function and sthe MsgBox( ).
|
|
1.MsgBox ( ) Function
|
|
The objective of MsgBox is to prompt the user to click on a command button before he /she can continues and produce a pop-up message box.
This message box format is as follows:
|
|
yourMsg=MsgBox(Prompt, Style Value, Title)
|
|
|
The first argument in the above format, Prompt, will display the message in the message box and the Style Value will determine what type of command buttons appear on the message box, please refer to table which is given below for types of command button displayed.
The Title argument will display title of the message board.
|
| Style Value |
Named Constant |
Buttons Displayed |
| 0 |
vbOkOnly |
Ok button |
| 1 |
vbOkCancel |
Ok and Cancel buttons |
| 2 |
vbAbortRetryIgnore |
Abort, Retry and Ignore buttons. |
| 3 |
vbYesNoCancel |
Yes, No and Cancel buttons |
| 4 |
vbYesNo |
Yes and No buttons |
| 5 |
vbRetryCancel |
Retry and Cancel buttons |
|
|
Table below shows the values, the corresponding named constant and buttons.
|
| Value |
Named Constant |
Button Clicked |
| 1 |
vbOk |
Ok button |
| 2 |
vbCancel |
Cancel button |
| 3 |
vbAbort |
Abort button |
| 4 |
vbRetry |
Retry button |
| 5 |
vbIgnore |
Ignore button |
| 6 |
vbYes |
Yes button |
| 7 |
vbNo |
No button |
|
|
The following example shows the use of MsgBox ( ) Function in VB
|
Private Sub Test_Click()
Dim testmsg As Integer
testmsg = MsgBox("Click to test", 1, "Test message")
If testmsg = 1 Then
Display.Caption = "Testing Successful"
Else
Display.Caption = "Testing fail"
End If
End Sub
|
|
|
O/P:
|
|
|
|
The following example shows the use of VB Icons
|
Private Sub test2_Click()
Dim testMsg2 As Integer
testMsg2 = MsgBox("Click to Test", vbYesNoCancel + vbExclamation, "Test Message")
If testMsg2 = 6 Then
display2.Caption = "Testing successful"
ElseIf testMsg2 = 7 Then
display2.Caption = "Are you sure?"
Else
display2.Caption = "Testing fail"
End If
End Sub
|
|
|
O/P:
|
|
|
2.The InputBox( ) Function
|
|
An InputBox( ) function will display a message box where the user can enter a message in the form of text or a value. The format is as follows:
myMessage=InputBox(Prompt, Title, default_text, x-position, y-position)
myMessage is a variant data type but typically it is declared as string and this accept the message input by the users. The arguments are explained as follows:
follows:
- Prompt - The message displayed normally as the question asked.
- Title - The title of Input Box.
- default-text - The default text that appears in the input field where
users may change to the message he
wish to key in and he can use it as his intended input.
- x-position and y-position - the coordinate or the position of the input
box.
|
|
The following example shows the use of InputBox( ) Function in VB
|
Private Sub OK_Click()
Dim userMsg As String
userMsg = InputBox("What is your message?", "Message Entry Form", "Enter your messge here", 500, 700)
If userMsg <> "" Then
message.Caption = userMsg
Else
message.Caption = "No Message"
End If
End Sub
|
|
Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
Keywords:
Looping in VB,
visual basic looping,
asp net looping,
visual basic vb,
vb source code,
while loop in vb,
for loop in vb,
vb asp net,
looping in excel,
looping in sql,
vb array,
vb functions,
vb controls
|
|
| HTML Quizes |
|
|
| XML Quizes |
|
|
| Browser Scripting Quizes |
|
|
| Server Scripting Quizes |
|
|
| .NET (dotnet) Quizes |
|
|
| Multimedia Quizes |
|
|
| Web Building Quizes |
|
|
| Java Quizes |
|
|
| Programming Langauges Quizes |
|
|
| Soft Skills Quizes |
|
|
| Database Quizes |
|
|
| Operating System Quizes |
|
|
| Software Testing Quizes |
|
|
| SAP Module Quizes |
|
|
| Networking Programming Quizes |
|
|
| Microsoft Office Quizes |
|
|
| Accounting Quizes |
|
|
| Computer Basics Quizes |
|
|
|