![]() |
|
||||||
Input Boxes, Message and List BoxesInput 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 promp 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. CANCLEL 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") Examples: 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 LoadForm_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:
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 BoxesMessage 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 BOX STATEMENTThe 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. MESSAGE BOX FUNCTION: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 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. Example of - ADDING ITEMS TO THE LIST: 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. Sorted PROPERTY: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. Clear METHOD: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.
No Comments for this page. |
|
||||||||||||||||||||||||||||||||