Freetutes.com

VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

VB .NET - Learn Visual Basic .NET

Systems Analysis - System analysis and Design tutorial for Software Engineering

Browse Topics

- Getting started
- Data Types
- Modules
- Operators in VB6
- VB6 Variable
- VB6 Procedures
- VB6 Control Structures
- Loops in VB6
- VB6 Exit Do & With End With
- Arrays in VB6
- User-Defined Data Types
- VB6 Constants
-
VB6 Built-in Functions
- Date and Time in VB6
- VB6 Controls
- TextBox Control
- ComboBox & OptionButton
- Label & Frame
- PictureBox & ImageBox
- Timer Control
- ListBox & ComboBox
- VB6 ScrollBar
- Control Arrays in VB6
- Files controls in VB6
- VB6 CheckBox
- Forms in VB6
- Menus in VB6
- MDI Form in VB6
- InputBox
- MessageBox
- Mouse events
- Mouse Move
- Error Handling
-
Error Handling (2)
-
VB6 Database

You are here: Visual Basic > VB6 (Beginners Tutorial)

Previous Page | Table of Contents | Next Page

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.

Following is an expanded InputBox

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

Here I have entered "Hello World" in text field. As soon as you click OK the output is shown as shown below

( Download the source code )

Related Topics


  

Previous Page | Table of Contents | Next Page

   

Home | Link to Us | About Us | Privacy Policy | Contact Us

Copyright © Freetutes.com | All Rights Reserved