Example: (Visual Basic 6.0)
Design and Write VB code to convert temperature degrees
From Fo to Co using the following formula:
TC = ( TF
- 32) / 1.8…..a vector is to be used to hold (20) F data elements and another for the output of the C converted data.
Solution:
The VB 6.0 Design Form could be something like this for instance:
VB 6.0 Code will be something like this:
'======================================================
' Converting Temperature degrees from F to C using two vectors
' Tf and Tc with 20 elements...Three Command buttons are used:
' Convert, Reset, and Exit........
'======================================================
Private Sub Command1_Click()
Dim Tc(20) As Single
Dim Tf(20) As Single
Tf(1) = Val(Text1.Text): Tf(11) = Val(Text11.Text)
Tf(2) = Val(Text2.Text): Tf(12) = Val(Text12.Text)
Tf(3) = Val(Text3.Text): Tf(13) = Val(Text13.Text)
Tf(4) = Val(Text4.Text): Tf(14) = Val(Text14.Text)
Tf(5) = Val(Text5.Text): Tf(15) = Val(Text15.Text)
Tf(6) = Val(Text6.Text): Tf(16) = Val(Text16.Text)
Tf(7) = Val(Text7.Text): Tf(17) = Val(Text17.Text)
Tf(8) = Val(Text8.Text): Tf(18) = Val(Text18.Text)
Tf(9) = Val(Text9.Text): Tf(19) = Val(Text19.Text)
Tf(10) = Val(Text10.Text): Tf(20) = Val(Text20.Text)
For i = 1 To 20
Tc(i) = (Tf(i) - 32) / 1.8
' If you want the result to be integer values, then use int function
Next
Text21.Text = Tc(1): Text31.Text = Tc(11)
Text22.Text = Tc(2): Text32.Text = Tc(12)
Text23.Text = Tc(3): Text33.Text = Tc(13)
Text24.Text = Tc(4): Text34.Text = Tc(14)
Text25.Text = Tc(5): Text35.Text = Tc(15)
Text26.Text = Tc(6): Text36.Text = Tc(16)
Text27.Text = Tc(7): Text37.Text = Tc(17)
Text28.Text = Tc(8): Text38.Text = Tc(18)
Text29.Text = Tc(9): Text39.Text = Tc(19)
Text30.Text = Tc(10): Text40.Text = Tc(20)
End Sub
Private Sub Command2_Click()
Text1.Text = "": Text11.Text = ""
Text2.Text = "": Text12.Text = ""
Text3.Text = "": Text13.Text = ""
Text4.Text = "": Text14.Text = ""
Text5.Text = "": Text15.Text = ""
Text6.Text = "": Text16.Text = ""
Text7.Text = "": Text17.Text = ""
Text8.Text = "": Text18.Text = ""
Text9.Text = "": Text19.Text = ""
Text10.Text = "": Text20.Text = ""
Text21.Text = "": Text31.Text = ""
Text22.Text = "": Text32.Text = ""
Text23.Text = "": Text33.Text = ""
Text24.Text = "": Text34.Text = ""
Text25.Text = "": Text35.Text = ""
Text26.Text = "": Text36.Text = ""
Text27.Text = "": Text37.Text = ""
Text28.Text = "": Text38.Text = ""
Text29.Text = "": Text39.Text = ""
Text30.Text = "": Text40.Text = ""
End Sub
Private Sub Command3_Click()
End
End Sub


0 Comments:
Post a Comment
السلام عليكم...سارد بعد قرائتي للتعليق...شكرا
<< Home