Left Quote    A clever person solves a problem. A wise person avoids it.
- Einstein    
Right Quote
[login] | [Register]

Getting Started with VB 6.0

by: bs0d
Page: 5 of 9
(View All)

Input Boxes, Message and List Boxes

Input Box - This is a function that will display a message, and allow the user to enter information in a text box. In the Input box, you can display a message called a prompt. The prompt will help the user decide what information he or she needs to enter in the text box.

The input box will have a text box with the prompt above it and two command buttons (OK and CANCEL). OK will accept any input the user enters, and place it in the variable on the left hand side of the equals sign. CANCEL will ignore any input entered by the user, and return back to the form currently open.

Input Boxes are often used when one wants to retrieve records from files.

VariableName = InputBox("Prompt","Title")


The prompt must be enclosed in quotes. The title must also be in quotes and will appear in the Title Bar of the Input Box. If no title is entered, the title of the project will appear in the Title Bar.

Input Boxes can appear in the following places:

  • Form_Load
  • Command Buttons
  • Option Buttons
  • Check Boxes

Form Load

Form_Load - Code executed as the project is loading. The first time a form is displayed in a project, VB generates an event knows as FORM_LOAD. Any code in Form Load is then executed.

Things that are done in the FORM_LOAD section of a VB program include the following:
  • Code to center the form in the middle of the screen
  • Code to initialize variables
  • Code for input boxes so the user can enter info.
  • Display info in labels on the form.

To get the FORM_LOAD event to enter code, double click on an empty area on the form. The FORM_LOAD event begins and ends with the following procedure headings:

Private Sub Form_Load()

< Place Code Here >
End Sub

Example of code in the FORM_LOAD event:

Message Boxes and List Boxes

Message Box - A special type of VB statement/function that displays a window in which you can display a message to a user. The message box can be a statement or function and has the name, MsgBox.

The following can be displayed to the user with a Message Box:
  • Message
  • Optional Icon
  • Title Bar Caption
  • Command Buttons


The message box statement is designed to be on a line by itself. The syntax of the MsgBox is identified below:

MsgBox < "Prompt" > , < Buttons/Icons > , < "Caption" >

Prompt - The message you want to appear in the message box.

Buttons/Icons - This determines what command buttons and/or icons that will appear on the message box (this portion is optional).

Caption - This is the caption that will appear on the title bar of the message.


The message box function will appear on the right hand side of the equals sign. Also, if your message box is a function, you must enclose arguments in ( and ).

VarName = MsgBox( < "Prompt" > , < Buttons/Icons > , < "Caption" > )

Sample code using Message Boxes:


List Box - A type of control used to hold a list of items from which the user can select one item from the list. You should use the lst prefix when naming list boxes.

Items can be added to a list box in two ways.

Using the LIST property for the list control
Using the AddItem method

< object_name > .AddItem < Value >

If your values are strings, they must be enclosed in double quotes. When items are added to the list, they are given an index. The first item added to the list will have an index of zero the 2nd of one, and so forth.


This will highlight the item "Brown". Harvard will have an index of 0, Yale of 1 and so forth.

ListIndex PROPERTY :

The listIndex property will highlight an item in the list when the program is run. Only one item can be set with the listIndex property. The format of List Index property is shown here:

< control > .ListIndex = 3 'This will highlight the 4th item in the list.


This will sort the items in your list alphabetically if the SORTED property is set to TRUE. This will also re-index the items in your list. If the ListIndex property is used, the highlighted item will change.


This will empty out the contents of a list box...

< control > .Clear

RemoveItem METHOD:

This will remove one item from the list. When using RemoveItem, you must include the index of the item to remove.

< control > .RemoveItem < index >

This will remove the item in the lstSchools list box with the index of 3, which is the 4th item in the list.

LstCount - The ListCount property is used to hold the number of items in the list. ListCount will always be one more than the highest element in the list.

1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  
Next »

No Comments for this page.

You Must be logged in or a member to comment.

Tutorial Stats

Tutorial Stats

0 Total Comments
4.16 Rating of 5 (6 Votes)


Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article



· Coding a Webserver
· Using Crystal Reports in VB
Your Article Here

"" Copyright © 2002-2020; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank