Selasa, 18 Oktober 2011

Cara Membuat Program Konversi Suhu Dengan Vb

Terlebih dahulu buatlah form seperti berikut ini:

Kemudian masukkan source code berikut ini:
Dim Celcius As Single
Dim Reamur As Single
Dim Fahrenheit As Single
Dim Kelvin As Single
Private Sub Command1_Click()
If Option1.Value = True Then
Celcius = Val(Text1.Text)
Reamur = Celcius * 0.8
Fahrenheit = (Celcius * 9 / 5) + 32
Kelvin = Celcius + 273
IsiText
End If
If Option2.Value = True Then
Reamur = Val(Text2.Text)
Celcius = Reamur * 1.25
Fahrenheit = (Celcius * 9 / 5) + 32
Kelvin = Celcius + 273
IsiText
End If
If Option3.Value = True Then
Fahrenheit = Val(Text3.Text)
Celcius = (Fahrenheit – 32) * 5 / 9
Reamur = Celcius * 0.8
Kelvin = Celcius + 273
IsiText
End If
If Option4.Value = True Then
Kelvin = Val(Text4.Text)
Celcius = Kelvin – 273
Reamur = Celcius * 0.8
Fahrenheit = (Celcius * 9 / 5) + 32
IsiText
End If
End Sub
Private Sub Option1_Click()
If Option1.Value = True Then
Text1.Enabled = True
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = False
KosongkanText
End If
End Sub
Private Sub Option2_Click()
If Option2.Value = True Then
Text1.Enabled = False
Text2.Enabled = True
Text3.Enabled = False
Text4.Enabled = False
KosongkanText
End If
End Sub
Private Sub Option3_Click()
If Option3.Value = True Then
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = True
Text4.Enabled = False
KosongkanText
End If
End Sub
Private Sub Option4_Click()
If Option4.Value = True Then
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
Text4.Enabled = True
KosongkanText
End If
End Sub
Sub KosongkanText()
Text1.Text = “”
Text2.Text = “”
Text3.Text = “”
Text4.Text = “”
End Sub
Sub IsiText()
Text1.Text = Celcius
Text2.Text = Reamur
Text3.Text = Fahrenheit
Text4.Text = Kelvin
End Sub

0 comments:

Posting Komentar