0% found this document useful (0 votes)
9 views

Csc301 Chapter 6-1

Uploaded by

dynzhaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Csc301 Chapter 6-1

Uploaded by

dynzhaa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CHAPTER 6:

INPUT BOX,
LIST BOXES Create and use input box,
list boxes and combo
AND boxes
COMBO
BOXES
THE INPUTBOX FUNCTION (1 OF 3)

¡ The InputBox function displays a dialog box that consists of a message


asking for input, an input area, a title, an OK button, and a Cancel button.
¡ When the user enters the text and taps or clicks the OK button, the
InputBox function returns this text as a string.
¡ If the user taps or clicks the Cancel button, the function returns a null
string ("").
THE INPUTBOX FUNCTION (2 OF 3)

Assigned to strUserName
THE INPUTBOX FUNCTION (3 OF 3)

• The InputBox object can be assigned a default value

Default value

Dim strUserInput As String =


InputBox("Enter the distance.","Provide a Value”, 150)
Double.TryParse(strUserInput, dblDistance)
¡ A ListBox control displays a list of items and
allows the user to select one or more items from
the list.
¡ Items can be added by the programmer at design
time or at runtime using a code.
¡ To create a ListBox control, double-click the
ListBox icon in the Toolbox window.
THE LIST ¡ The prefix that we will use in a ListBox control’s
BOXES name is lst (first letter is L).
CONTROL
¡ The items in a list box belong to a collection called
the Items collection.
¡ The String Collection Editor provides an easy
way to add items to the Items collection.
¡ To store values in the Items property at design time:
ADDING ¡ Select the ListBox control in the Designer window
In the Properties window, click the Items (Collection)
ITEMS TO ¡
ellipsis button (...)
THE LIST ¡ Type each value on a separate line in the String
Collection Editor dialog box
BOXES AT
DESIGN TIME
ADDING ITEMS USING THE ADD() METHOD

¡ To store values in the Items property with code at runtime, use the
Add() method.
CLEARING ITEMS FROM LIST BOX

¡ The Items collection provides a Clear method for clearing (removing)


the items from a list box.
COMBO BOXES SIMILAR TO LIST BOXES

¡ Both display a list of items to the user.


¡ Both have Items.Add, and Items.Clear methods.

¡ Additional combo box features are:


¡ a combo box also functions like a text box.
¡ the combo box has a Text property.
¡ the user may enter text into a combo box or the user may select the text
from a series of list box type choices.
¡ in code, we use the cbo prefix when naming combo boxes.
¡ Three styles of combo boxes are available in Visual
Basic.
COMBO BOX
¡ The style is controlled by the combo box’s
STYLES DropDownStyle property, which can be set to
Simple, DropDown (the default), or DropDownList.
LIST BOXES VERSUS COMBO BOXES

¡ If restricting the user to select items listed


¡ If empty space – Use list box
¡ If limited space – Use drop-down list combo box

¡ If allowing user to select an item listed or enter an entirely


new item
¡ If empty space – Use simple combo box
¡ If limited space – Use drop-down combo box
END OF SUBTOPIC …
INPUT BOX, LIST BOXES
AND COMBO BOXES

You might also like