Syntax :
memory_variable = InputBox (prompt[,title][,default])
memory_variable is a variant data type but typically it is declared as string, which accept the message input by the users. The arguments are explained as follows: - Prompt - String expression displayed as the message in the dialog box. If prompt consists of more than one line, you can separate the lines using the vbCrLf constant
- Title - String expression displayed in the title bar of the dialog box. If you omit the title, the application name is displayed in the title bar
- default-text - The default text that appears in the input field where users can use it as his intended input or he may change to the message he wish to key in.
- x-position and y-position - the position or the coordinate of the input box.
Following example demonstrates the use of InputBox function
* Open a new project and save the Form as InputBox.frm and save the Project as InputBox.vbp
* Design the application as shown below.* Open a new project and save the Form as InputBox.frm and save the Project as InputBox.vbp
Object | Property | Setting |
Form | Caption Name | InputBox test frmInputBox |
Label | Caption Name | You entered lbl1 |
Label | Caption Name BorderStyle | ( empty) lbl2 1-Fixed Single |
CommandButton | Caption Name | OK cmdOK |
Following code is entered in cmdOK_Click ( ) event
Private Sub cmdok_Click()
Dim ans As String
ans = InputBox("Enter something to be displayed in the label", "Testing", 0)
If ans = "" Then
lbl2.Caption = "No message"
Else
lbl2.Caption = ans
End If
End Sub
Save and run the application. As soon as you click the OK button you will get the following InputBoxDim ans As String
ans = InputBox("Enter something to be displayed in the label", "Testing", 0)
If ans = "" Then
lbl2.Caption = "No message"
Else
lbl2.Caption = ans
End If
End Sub
Here I have entered "Hello World" in text field. As soon as you click OK the output is shown as shown below
Download Sourcecode
2 comments:
Raiz,
We saw you have copied content from our site freetutes.com and used in this blog as it is your own articles or properties. This is not the only article I found and I ask you to remove ALL the articles, images and anything copied from our website freetutes.com as soon as possible. If you fail to do so will cause you on having your Google Adsense account banned and removed(banned) from major search engines due to copyright infringement.
NOTE: I couldn't find any contact email or form in this blog so I had to let you know this way.
hello... hapi blogging... have a nice day! just visiting here....
Post a Comment