Wednesday, October 28, 2009

InputBox Function in Visual Basic 6 (VB6)


InputBox Function in Visual Basic 6 (VB6). Displays a prompt in a dialog box, waits for the user to input text or click a button, and returns a String containing the contents of the text box.


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.
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 InputBox
Image Hosted by UploadHouse.com
Here I have entered "Hello World" in text field. As soon as you click OK the output is shown as shown below
Image Hosted by UploadHouse.com
Download Sourcecode

2 comments:

Unknown on March 11, 2010 at 10:24 PM said...

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.

Anonymous said...

hello... hapi blogging... have a nice day! just visiting here....

Your Ad Here