Visual Basic 6.0 Programming learning

Visual Basic 6.0 Programming learning

Share

Making simple software programs &Teaching the world for free.

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]

04/11/2015

The following program creates an electronic dialing pad. The form contains a control array of 10 commands buttons. Each time a command button is clicked, the Index parameter conveys the digit to be added onto the phone number. This program illustrates using the Index parameter without employing a select Case statement."must read"

Object frm7_3_2>caption>(blank)
cmd Digit()>Index>0 to 9
Caption>(same as Index)>(blank)
lblPhoneNum>BorderStyle>1 - Fixed Single.

code:

private sub cmdDigit_Click(Index As Integer)
lblPhoneNum.caption = lblPhoneNum.Caption & Right(str(index).1)
if Len(lblPhoneNum.caption)= 3 Then
lblPhoneNum.caption= lblPhoneNum.caption & "-"
ElseIf Len(lblPhoneNum.caption) =8 Then
Msgbox"Dialing ...". .""
lblPhoneNum.caption =""
End If
End Sub

Photos 02/09/2015
05/08/2015

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

23/07/2015

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

23/07/2015

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)

28/05/2015

The following program uses the Hypotenuse funtion.

Object:

frm4_3_4>caption>Right Triangle.
lblSideOne>Caption>length of one side.
txtSideOne>Text>(blank).
lblSideTwo>caption>Length of other side.
txtSideTwo>text>(blank).
cmdCalculate>caption>Calculate Hypotenuse.
lblHelp>caption>Length of Hypotenuse.
picHyp.

codin

private sub cmdCalculate_Click()
Dim a As Single, b As Single
'Calculate Length of the hypotenuse of a right triangle
a = Val(txtSideOne.Text)
b = Val(txtSideTwo.Text)
picHyp.Cls
picHyp.Print Hypotenuse(a, b)
End Sub

Private Function Hypotenuse(a As Single, b As Single) As Single
'Calculate the hypotenuse of a right triangle
'having sides of lengths a and b
Hypotenuse = sqr(a ^ 2 + b ^ 2)
End Function

[Run, type 3 and 4 into the boxes, and then click the command button]

Old School Days.......(a + b) =?

13/05/2015

object:

frmMultiply>caption>multiplication Table.
cmdDisplay>caption>Display Table.
picTable.

code:

private sub cmdDisplay_click()
dim j as integer, k as integer
picTable.Cls
For j = 1 To 4
For k = 1 To 4
picTable.print j; "x" ; k; "=";j * k,
Next j
End Sub

[Run and press the command button]

Taste this.....??

11/04/2015

The following program requests a color(blue or red)&a mode(steady or flashing)as input and display the weather forecast.the program contains a select Case block with a string expression as the selector.

steady blue, clear view.
flashing blue, clouds due.
steady red, rain ahead.
flashing red, snow instead.

frmWeather>caption>Weather Beacon.
lblColor>caption>color of the light.
txtColor>text>(blank).
lblMode>caption>Mode (S or F).
txtMode>text>(blank).
cmdInterpret>caption>Interpret Beacon.
picForecast.

codin.

private sub cmdInterpret_click().
dim color as string, mode as string.
'Interpret a weather beacon.
picForecast.Cls.
color=txtColor.text.
mode=txtMode.text.
select Case UCase(mode)&UCase(color).
Case "SBlue".
picForecast.print "CLEAR VIEW"
Case "FBlue"
picForecast.print "CLOUDS DUE"
Case "SRed".
picForecast.print "RAIN AHEAD"
Case "FRED"
picForecast.print "SNOW AHEAD"
End Select
End Sub

[run, type red and S into the text boxes, and press the command button.]

06/04/2015

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]

28/03/2015

The following program accepts a word as input &displays it backwards.
frm6_3_3>caption>write backwards.
lblword>caption>enter word.
txtword>text>(blank).
cmdreverse>caption>reverse letters.
pictranspose.

code:
private sub cmdreverse_click()
pictranspose.cls
picstranspose.print reverse(txtword.text)
end sub

private function reverse(info as string) as string.
dim m as integer, j as integer, temp as string.
m=len(info)
temp=""
for j =m to 1 step -1
temp =temp + mid(info, j , 1)
next j
reverse= temp
end function

[run,type Suez into the text box, and click the command button.]

08/03/2015

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

Want your school to be the top-listed School/college in Lusaka?

Click here to claim your Sponsored Listing.

Location

Category

Telephone

Address


Libala South
Lusaka
LUSAKA