Visual Basic 6.0 Programming learning
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]
The following program illustrates th fact that each time a Sub procedure is called, its variables are set to their default values; that is, numerical variable are set to 0 and string variable are set to the empty string.
code:
private sub cmdDisplay_Click()
'Demonstrate that variables in a Sub procedure do
'no retain their value in subsequent calls
picResults.Cls
call three
call three
End Sub
Private Sub Three()
Dim num As Single
'Display the value of num and assign it the value 3
PicResults.Print num;
num = 3
End Sub
[Run, and then click the command button.The following is displayed in the picture box]
0 0
identify the errors.
private Sub cmdDisplay_Click()
Dim purchase As Single
purchase = Val (InputBox("Quantity purchased?))
Select Case purchase
Case Is < 10000
picOutput.Print "Five dollars per item."
Case Is 10000 To 30000
picOutput.Print "Four dollars per item.
Case Is >30000
picOutput.Print "Three dollar per item."
End Select
End Sub
private sub cmdDisplay_Click()
Dim age As Single, price As Single
age= Val(InputBox("what is your age?"))
Select Case age
Case Is < 6
price = 0
Case 6 To 17
price = 3.75
Case Is >= 17
price = 5
End Select
picOutput.print "The price is "; FormatCurrency(price)
End Sub
(8.5, 17)
The following program uses the function FtoC.
frm4_3_1>caption>Convert Fahrenheit to Celsius.
lblTempF>caption>Temperature(Fahrenheit).
txtTempF>text>(blank).
cmdConvert>caption>Convert to Celsius.
lblTempC>caption>Temperation(Celsius).
picTempC.
codin
private sub cmdConvert_Click()
picTempC.Cls
picTempC.print FtoC(Val(txtTempF.text))
end sub
private function FtoC(t As Single) As Single
'Convert Fahrenheit temperature to Celsius
FtoC = (5/9) * (t -32)
End Funtion
[run, type 212 into the text box, and then click the command button]
The following program offers assistance to the user before presenting a quotation.
>>>frm5_2_4 >caption>Quotation.
lblQuestion>caption>Do you know what the game of skittles is (Y/N)..
txtAnswer>text>(blank)---------
cmdDisplay>caption>Display Quotation.
picQuote(add a picture on th form.
codin:
private sub cmdDisplay_Click()
Dim message As String.
message= "Skittles is an old form of bowling in which a wooden" & _ "disk is used to knock down nine pins arranged in a square."
If UCase(txtAnswer.text)="N" then
msgbox message, ,""
End If
picQuote.Cls
picQuote.print "Life ain't all beer and skittles. - Fraz Samiyengo (2015)"
End sub
[Run, type N into the text box, and press the command button.]
remember were picQuote.print there is no print in V.B so just type.enjoy
Click here to claim your Sponsored Listing.
Category
Contact the school
Telephone
Website
Address
Libala South
Lusaka
LUSAKA