pucakwangi-pati

Batman Begins - Diagonal Resize 2

Kamis, 11 September 2014

Converter suhu dengan visual basic

Sediakan toolsnya sebagai berikut :

- Frame1 : INPUT
- Frame2 : OUTPUT
- Option1 : Fahrenheit
- Option2 : Celcius
- Option3 : Rheamur
- Option4 : Kelvin
- Label1 : Masukkan Suhu
- Label2 : Fahrenheit
- Label3 : Celcius
- Label4 : Rheamur
- Label5 : Kelvin
- Text1 : Kosongkan saja (posisinya tepat pada angka 20)
- Text2 : Kosongkan saja (Posisinya disamping kanan Fahrenheit)
- Text3 : Kosongkan saja (Posisinya disamping kanan Celcius)
- Text4 : Kosongkan saja (Posisinya disamping kanan Rheamur)
- Text4 : Kosongkan saja (Posisinya disamping kanan Kelvin)
- Command1 : Konversi
- Command2 : Clear
- Command3 : Exit

==> Kalau sudah membuat tools diatas sesuai pada gambar diatas, silahkan langsung copy paste listing dibawah ke formnya. Cekidoooooooooooooooot :

Private Sub Command1_Click()
Dim jwb As Integer
If Text1.Text = "" Then
jwb = MsgBox("Masukkan Nilai Suhu Yang Akan Dikonversi!!!   ", _
vbInformation + vbYesNo, "WARNING")
If jwb = vbNo Then
Unload Me
ElseIf jwb = vbYes Then
FrmKonversiSuhu.Show
End If
ElseIf Option1 = True Then
Fahrenheit
ElseIf Option2 = True Then
Celcius
ElseIf Option3 = True Then
Rheamur
ElseIf Option4 = True Then
Kelvin
End If
End Sub

Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text2.BackColor = "&H80000005"
Text3.BackColor = "&H80000005"
Text4.BackColor = "&H80000005"
Text5.BackColor = "&H80000005"
Text1.SetFocus
End Sub

Private Sub Command3_Click()
Unload Me
End Sub

Private Sub Option1_Click()
If Option1 = True Then
Option2 = False And Option3 = False And Option4 = False
End If
End Sub

Sub Celcius()
Dim bil1, fah, rhe, kel As Integer
bil1 = Text1
fah = Val((Text1.Text) * 9 / 5) + 32
Text2.Text = FormatNumber(fah, 2, vbFalse, vbFalse, vbFalse)
rhe = Val(Text1.Text) * 4 / 5
Text4.Text = FormatNumber(rhe, 2, vbFalse, vbFalse, vbFalse)
kel = Val(Text1.Text) + 273
Text5.Text = FormatNumber(kel, 2, vbFalse, vbFalse, vbFalse)
Text3.BackColor = black
End Sub

Sub Fahrenheit()
Dim bil1, cel, rhe, kel As Integer
bil1 = Text1
cel = Val((Text1.Text) - 32) * 5 / 9
Text3.Text = FormatNumber(cel, 2, vbFalse, vbFalse, vbFalse)
rhe = Val((Text1.Text) - 32) * 4 / 9
Text4.Text = FormatNumber(rhe, 2, vbFalse, vbFalse, vbFalse)
kel = Val(((Text1.Text) - 32) * 5 / 9) + 273
Text5.Text = FormatNumber(kel, 2, vbFalse, vbFalse, vbFalse)
Text2.BackColor = black
End Sub

Sub Rheamur()
Dim bil1, fah, cel, kel As Integer
bil1 = Text1
fah = Val((Text1.Text) * 9 / 4) + 32
Text2.Text = FormatNumber(fah, 2, vbFalse, vbFalse, vbFalse)
cel = Val(Text1.Text) * 5 / 4
Text3.Text = FormatNumber(cel, 2, vbFalse, vbFalse, vbFalse)
kel = Val((Text1.Text) * 5 / 4) + 273
Text5.Text = FormatNumber(kel, 2, vbFalse, vbFalse, vbFalse)
Text4.BackColor = black
End Sub

Sub Kelvin()
Dim bil1, fah, cel, rhe As Integer
bil1 = Text1
fah = Val((((Text1.Text) - 273) * 9 / 5)) + 32
Text2.Text = FormatNumber(fah, 2, vbFalse, vbFalse, vbFalse)
cel = Val(Text1.Text) - 273
Text3.Text = FormatNumber(cel, 2, vbFalse, vbFalse, vbFalse)
rhe = Val((Text1.Text) - 273) * 4 / 5
Text4.Text = FormatNumber(rhe, 2, vbFalse, vbFalse, vbFalse)
Text5.BackColor = black
End Sub

0 komentar:

Posting Komentar