18/03/2016
The following progrm modifies the progrm in e.g. To search the tele-phone directory for name specified by the user.If the name does not appear in the directory, the user is so notified.We want to keep searching as long as there is no match and we have not reached the end of the list.Therefore, the condition for the Do While statement is a compound logical expression with the operator And.After the last pass through the, we will know whether the name was found and be able to display the requested information.
Objects:
frmPhone>caption>Phone Number.
lblName>caption>Name to look up.
txtName>Text>(blank).
cmdDisplay>caption>Display Phone Number.
picNumber.
codes:
Private Sub cmdDisplay_Click()
Dim nom As String, phoneNum As String
Open "PHONE.TXT" For Input As #1
nom=""
Do While (nomtxtName.Text) And (Not EOF))
Input #1, nom, PhoneNum
Loop
Close #1
picNumber.Cls
If nom=txtName.Text Then
picNumber.Print nom, PhoneNum
Else
picNumber.Print "Name not found."
End If
End sub
[Run, type Grover into the text box, and press the command button]