19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

288 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

adds str to the list. The item is added at the proper sorted position if the Sorted property is True,<br />

<strong>and</strong> otherwise is added to the end of the list. At any time, the value of<br />

lstBox.ListCount<br />

is the number of items in the list box.<br />

Each item in lstBox is identified by an index number ranging from 0 through<br />

lstBox.ListCount – 1. The value of<br />

lstBox.NewIndex<br />

is the index number of the item most recently added to lstBox by the AddItem method. During<br />

run time you can highlight an item from a list by clicking on it with the mouse or by moving<br />

to it with the up- <strong>and</strong> down-arrow keys when the list box has the focus. (The second method<br />

triggers the Click event each time an arrow key causes the highlight to move.) The value of<br />

lstBox.ListIndex<br />

is the index number of the item currently highlighted in lstBox. (If no item is highlighted, the<br />

value of ListIndex is –1.)<br />

The string array lstBox.List( ) holds the list of items stored in the list box. In particular,<br />

the value of<br />

lstBox.List(n)<br />

is the item of lstBox having index n. For instance, the statement picBox.Print lstBox.List(0)<br />

displays the first item of the list box lstBox. The value of<br />

lstBox.List(lstBox.ListIndex)<br />

is the item (string) currently highlighted in lstBox. Alternatively, the value of<br />

lstBox.Text<br />

is also the currently highlighted item. Unlike the Text property of a text box, you may not assign<br />

a value to lstBox.Text.<br />

The statement<br />

lstBox.RemoveItem n<br />

deletes the item of index n from lstBox, the statement<br />

lstBox.RemoveItem lstBox.ListIndex<br />

deletes the item currently highlighted in lstBox, <strong>and</strong> the statement<br />

lstBox.Clear<br />

deletes every item of lstBox.<br />

EXAMPLE 1<br />

An oxymoron is a pairing of contradictory or incongruous words. The following program displays a sorted<br />

list of oxymorons. When you click an item (or highlight it with the up- <strong>and</strong> down-arrow keys), it is displayed<br />

in a picture box. A comm<strong>and</strong> button allows you to add an additional item with an Input box. You<br />

can delete an item by double-clicking on it with the mouse. (Note: When you double-click the mouse,<br />

two events are processed—the Click event <strong>and</strong> the DblClick event.) After running the program, click on<br />

different items, add an item or two (such as “same difference” or “liquid gas”), <strong>and</strong> delete an item.<br />

Object Property Setting<br />

frmOxyMor Caption OXYMORONS<br />

lstOxys Sorted True<br />

cmdAdd Caption Add an Item<br />

lblDelete Caption [To delete an item,<br />

double-click on it.]<br />

picSelected

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!