“Temperature Conversion” dengan Visual Basic 6.0
Setelah mencari cara memasukan rumus yang tepat akhirnya aplikasi ini selesai juga di buat. Walaupun pada perhitungan konversi temperatur Fahrenheit hanya bisa mendekati tapi saya rasa tidak terlalu jauh perbedaannya. Kenapa saya hanya menyertakan ketiga temperatur ini saja? dikarenakan ketiga temperatur inilah yang sering dipergunakan baik dalam kalangan umum maupun peneliti. Sehingga saya merasa tidak perlu menambahkan konversi suhu yang lainnya. Berbeda dengan konversi Fahrenheit untuk perhitungan Celcius dan Kelvin saya bisa bilang keakuratannya 100%. Selanjutnya saya akan mencoba mengimplementasikannya ke dalam Visual Basic.NET 2010.
1. Jalankan aplikasi Visual Basic 6.0
2. Pada jendela “New Project” pilih “Standard EXE” kemudian tekan tombol “Open”
3. Berikut setingan kontrol properti yang terdapat pada aplikasi ini
Object | Name | Properties | Setting |
Form | Form1 | Border Style | 1 - Fixed Single |
Caption | Temperature Conversion | ||
Font | Tahoma; 10pt | ||
Start Up Position | 2 - Center Screen | ||
Option Button | optCelsius | Caption | Celsius |
Option Button | optFahrenheit | Caption | Fahrenheit |
Option Button | optKelvin | Caption | Kelvin |
Frame | Frame1 | Caption | (Empty) |
Label | Label3 | Caption | Degree: |
Text Box | txtUserInput | Alignment | 1 – Right Justify |
Text | (Empty) | ||
Label | Label5 | Caption | Press "Enter" to start Conversion |
Label | lblDegreeConversion | Alignment | 2 - Center |
Caption | (Empty) | ||
Font | Tahoma; 36pt | ||
Label | lblInfo | Alignment | 2 - Center |
Caption | (Empty) | ||
Label | lblDisplayConversion1 | Alignment | 2 - Center |
Caption | (Empty) | ||
Label | lblDisplayConversion2 | Alignment | 2 - Center |
Caption | (Empty) | ||
Label | lblConversion1 | Alignment | 2 - Center |
Back Color | &HFFFFFF | ||
Border Style | 1 – Fixed Single | ||
Caption | (Empty) | ||
Label | lblConversion2 | Alignment | 2 - Center |
Back Color | &HFFFFFF | ||
Border Style | 1 – Fixed Single | ||
Caption | (Empty) | ||
Line | Line1 | Border Color | H80000008& |
Border Width | 1 | ||
Line | Line2 | Border Color | &HFFFFFF |
Border Width | 2 | ||
Command Button | cmdExit | Caption | E&xit |
4. Berikut saya sertakan event program aplikasi ini:
Dim Coice As String
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Exit the aplication?", vbYesNo + vbQuestion, "Confirmation") = vbNo Then
Cancel = 1
End If
End Sub
Private Sub optCelsius_Click()
StarConverter
lblDisplayConversion1.Caption = "Fahrenheit:"
lblDisplayConversion2.Caption = "Kelvin:"
Coice = "Celsius"
End Sub
Private Sub optFahrenheit_Click()
StarConverter
lblDisplayConversion1.Caption = "Kelvin:"
lblDisplayConversion2.Caption = "Celsius:"
Coice = "Fahrenheit"
End Sub
Private Sub optKelvin_Click()
StarConverter
lblDisplayConversion1.Caption = "Celsius:"
lblDisplayConversion2.Caption = "Fahrenheit:"
Coice = "Kelvin"
End Sub
Private Sub StarConverter()
txtUserInput.Text = ""
lblDegreeConversion.Caption = ""
lblConversion2.Caption = ""
lblConversion1.Caption = ""
lblInfo.Caption = ""
txtUserInput.MaxLength = 7
txtUserInput.SetFocus
End Sub
Private Sub txtUserInput_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= vbKey0 And KeyAscii <= vbKey9 Or KeyAscii = 45 Or KeyAscii = 46 Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
KeyAscii = 0
ElseIf KeyAscii = vbKeyReturn Then
Select Case Coice
Case "Celsius"
lblDegreeConversion.Caption = Val(txtUserInput.Text)
lblConversion1.Caption = CDbl(Val(txtUserInput.Text) * 1.8 + 32)
lblConversion2.Caption = CDbl(Val(txtUserInput.Text) + 273.15)
txtUserInput.Text = ""
If lblDegreeConversion.Caption = -273.15 Then
lblInfo.Caption = "Absolute Zero"
ElseIf lblDegreeConversion.Caption = 0 Then
lblInfo.Caption = "Water Freezing"
ElseIf lblDegreeConversion.Caption = 37 Then
lblInfo.Caption = "Human Body Temperature"
ElseIf lblDegreeConversion.Caption = 100 Then
lblInfo.Caption = "Water boils"
Else
lblInfo.Caption = ""
End If
Case "Fahrenheit"
lblDegreeConversion.Caption = Val(txtUserInput.Text)
lblConversion1.Caption = CDbl((Val(txtUserInput.Text) + 459.67) * 5 \ 9)
lblConversion2.Caption = CDbl(Val(txtUserInput.Text - 32) * 5 \ 9)
txtUserInput.Text = ""
If lblDegreeConversion.Caption = -459.67 Then
lblInfo.Caption = "Absolute Zero"
ElseIf lblDegreeConversion.Caption = 32 Then
lblInfo.Caption = "Water Freezing"
ElseIf lblDegreeConversion.Caption = 98.6 Then
lblInfo.Caption = "Human Body Temperature"
ElseIf lblDegreeConversion.Caption = 212 Then
lblInfo.Caption = "Water boils"
Else
lblInfo.Caption = ""
End If
Case "Kelvin"
lblDegreeConversion.Caption = Val(txtUserInput.Text)
lblConversion1.Caption = CDbl(Val(txtUserInput.Text) - 273.15)
lblConversion2.Caption = CDbl(Val(txtUserInput.Text) * 1.8 - 459.67)
txtUserInput.Text = ""
If lblDegreeConversion.Caption = 0 Then
lblInfo.Caption = "Absolute Zero"
ElseIf lblDegreeConversion.Caption = 273.15 Then
lblInfo.Caption = "Water Freezing"
ElseIf lblDegreeConversion.Caption = 310.15 Then
lblInfo.Caption = "Human Body Temperature"
ElseIf lblDegreeConversion.Caption = 373.15 Then
lblInfo.Caption = "Water boils"
Else
lblInfo.Caption = ""
End If
End Select
End If
End Sub
Label: VB6
0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda