Friday, January 15, 2010

InputBox example in VB 6.0

What is inputbox? Input Box Tutorial


Inputbox function in Vb 6 is used to receive input from user. A Dialog box prompt will appear on the screen asking for the text input. The input is one line in size. You can type any data as string. Date, Time, Numeric values, Character Data. The maximum acceptable length of the string is 254. This is the syntax of the InputBox funtion.

InputBox(Prompt, [Title], [Default], [XPos], [YPos], [HelpFile], [Context]) as string

'Prompt' is the Descriptive text on the inputbox. 'Title' appears on the Windows Title Bar. 'Default' is the InputBox Default Value. Xpos is the X co-ordinate position in twips. YPos is the Y Coordinate position in twips.

Here is the example of typical Inputbox. This small tutorial will help you understand the usage of InputBox

Create a Standard Exe project and put a command button and set its name property to cmdGetAge. Double click the button and write the following code.

Private Sub cmdGetAge_Click()
    Dim Age
    Age = InputBox("Enter your age", "Your Age", 20, 100, 100)
    MsgBox ("The age is: " + Age)
End Sub

Press F5 to run the project and click the button.