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.

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

Object Property Setting<br />

frm7_3_2 Caption (blank)<br />

cmdDigit( ) Index 0 to 9<br />

Caption (same as Index)<br />

lblPhoneNum BorderStyle 1 - Fixed Single<br />

Caption (blank)<br />

Private Sub cmdDigit_Click(Index As Integer)<br />

lblPhoneNum.Caption = lblPhoneNum.Caption & Right(str(index), 1)<br />

If Len(lblPhoneNum.Caption) = 3 Then<br />

lblPhoneNum.Caption = lblPhoneNum.Caption & ”-”<br />

ElseIf Len(lblPhoneNum.Caption) = 8 Then<br />

MsgBox “Dialing ...”, , “”<br />

lblPhoneNum.Caption = “”<br />

End If<br />

End Sub<br />

■ CREATING CONTROL ARRAYS AT RUN TIME<br />

We have discussed the process for creating an entire control array while designing a form, that is,<br />

at design time. However, copying <strong>and</strong> positioning control array elements can become tedious if the<br />

number of elements is large. Also, the actual number of elements needed in a control array may not<br />

be known until a response from the user is processed at run time. In light of these concerns, <strong>Visual</strong><br />

<strong>Basic</strong> provides a solution via the Load statement that only requires us to create the first element of<br />

a control array during design time. The remaining elements are then created as needed at run time.<br />

Before we discuss creating arrays at run time, we must consider a preliminary topic—the Left, Top,<br />

Width, <strong>and</strong> Height properties of controls. These properties specify the location <strong>and</strong> size of controls.<br />

The st<strong>and</strong>ard unit of measurement in <strong>Visual</strong> <strong>Basic</strong> is called a twip. There are about 1440 twips<br />

to the inch. At design time, when a control is active the two panels on the right side of the toolbar<br />

give the location <strong>and</strong> size of the control, respectively. Figure 6-6(a) shows an active text box, named<br />

Text1. The first panel says that the left side of the text box is 960 twips from the left side of the<br />

form, <strong>and</strong> the top of the text box is 720 twips down from the title bar of the form. In terms of properties,<br />

Text1.Left is 960, <strong>and</strong> Text1.Top is 720. Similarly, the numbers 1935 <strong>and</strong> 975 in the second<br />

panel give the width <strong>and</strong> height of the text box in twips. In terms of properties, Text1.Width is 1935<br />

<strong>and</strong> Text1.Height is 975. Figure 6-6(b) shows the meanings of these four properties.<br />

The location <strong>and</strong> size properties of a control can be altered at run time with statements<br />

such as<br />

Text1.Left = 480<br />

which moves the text box to the left or<br />

Text2.Top = Text1.Top + 1.5 * Text1.Height<br />

which places Text2 a comfortable distance below Text1. As a result of the second statement,<br />

the distance between the two text boxes will be half the height of Text1.<br />

FIGURE 6-6 The Location <strong>and</strong> Size of a Control

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

Saved successfully!

Ooh no, something went wrong!