“Unit Conversion” dengan Visual Basic 6.0
Masih ingat perhitungan tangga konversi baik untuk satuan panjang, berat dan volume. Aplikasi ini sengaja saya buat berdasarkan hal itu dan mohon maaf bila penggunaannya agak kaku, karena bingung juga untuk mengatur dan membuat tampilan yang memikat dan di sisi lain bisa mencakup semua unit konversi. Dan bila diantara teman-teman yang ingin mengembangkan atau memberi saran dan masukan mengenai aplikasi ini? saya persilahkan dan berterima kasih.
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 | Unit Conversion | ||
Font | Tahoma; 10pt | ||
Start Up Position | 2 - Center Screen | ||
Option Button | optLength | Caption | Length Conversion |
Option Button | optWeight | Caption | Weight Conversion |
Option Button | optVolume | Caption | Volume Conversion |
Frame | Frame1 | Caption | (Empty) |
Label | lblDisplayUnit | Caption | Unit length: |
Text Box | txtUserInput | Alignment | 2 - Center |
Font | Tahoma; 14pt | ||
Label | Label1 | Caption | = |
Label | Label2 | Caption | Result: |
Label | Label3 | Caption | From: |
List Box | lstFrom | ||
Label | Label3 | ||
List Box | lstTo | Caption | To: |
Command Button | cmdConvert | Caption | Convert |
Line | Line1 | Border Width | 1 |
Line | Line2 | Border Color | &H00FFFFFF& |
Border Width | 2 | ||
Command Button | cmdExit | Caption | E&xit |
4. Berikut saya sertakan event program aplikasi ini:
Dim tmpList As Integer
Private Sub cmdConvert_Click()
If lstFrom.Selected(0) And lstTo.Selected(0) Then
lblResult.Caption = Val(txtUserInput.Text)
ElseIf lstFrom.Selected(0) And lstTo.Selected(1) Then
lblResult.Caption = Val(txtUserInput.Text) * 10
ElseIf lstFrom.Selected(0) And lstTo.Selected(2) Then
lblResult.Caption = Val(txtUserInput.Text) * 100
ElseIf lstFrom.Selected(0) And lstTo.Selected(3) Then
lblResult.Caption = Val(txtUserInput.Text) * 1000
ElseIf lstFrom.Selected(0) And lstTo.Selected(4) Then
lblResult.Caption = Val(txtUserInput.Text) * 10000
ElseIf lstFrom.Selected(0) And lstTo.Selected(5) Then
lblResult.Caption = Val(txtUserInput.Text) * 100000
ElseIf lstFrom.Selected(0) And lstTo.Selected(6) Then
lblResult.Caption = Val(txtUserInput.Text) * 1000000
End If
If lstFrom.Selected(1) And lstTo.Selected(0) Then
lblResult.Caption = Val(txtUserInput.Text) / 10
ElseIf lstFrom.Selected(1) And lstTo.Selected(1) Then
lblResult.Caption = Val(txtUserInput.Text)
ElseIf lstFrom.Selected(1) And lstTo.Selected(2) Then
lblResult.Caption = Val(txtUserInput.Text) * 10
ElseIf lstFrom.Selected(1) And lstTo.Selected(3) Then
lblResult.Caption = Val(txtUserInput.Text) * 100
ElseIf lstFrom.Selected(1) And lstTo.Selected(4) Then
lblResult.Caption = Val(txtUserInput.Text) * 1000
ElseIf lstFrom.Selected(1) And lstTo.Selected(5) Then
lblResult.Caption = Val(txtUserInput.Text) * 10000
ElseIf lstFrom.Selected(1) And lstTo.Selected(6) Then
lblResult.Caption = Val(txtUserInput.Text) * 100000
End If
If lstFrom.Selected(2) And lstTo.Selected(0) Then
lblResult.Caption = Val(txtUserInput.Text) / 100
ElseIf lstFrom.Selected(2) And lstTo.Selected(1) Then
lblResult.Caption = Val(txtUserInput.Text) / 10
ElseIf lstFrom.Selected(2) And lstTo.Selected(2) Then
lblResult.Caption = Val(txtUserInput.Text)
ElseIf lstFrom.Selected(2) And lstTo.Selected(3) Then
lblResult.Caption = Val(txtUserInput.Text) * 10
ElseIf lstFrom.Selected(2) And lstTo.Selected(4) Then
lblResult.Caption = Val(txtUserInput.Text) * 100
ElseIf lstFrom.Selected(2) And lstTo.Selected(5) Then
lblResult.Caption = Val(txtUserInput.Text) * 1000
ElseIf lstFrom.Selected(2) And lstTo.Selected(6) Then
lblResult.Caption = Val(txtUserInput.Text) * 10000
End If
If lstFrom.Selected(3) And lstTo.Selected(0) Then
lblResult.Caption = Val(txtUserInput.Text) / 1000
ElseIf lstFrom.Selected(3) And lstTo.Selected(1) Then
lblResult.Caption = Val(txtUserInput.Text) / 100
ElseIf lstFrom.Selected(3) And lstTo.Selected(2) Then
lblResult.Caption = Val(txtUserInput.Text) / 10
ElseIf lstFrom.Selected(3) And lstTo.Selected(3) Then
lblResult.Caption = Val(txtUserInput.Text)
ElseIf lstFrom.Selected(3) And lstTo.Selected(4) Then
lblResult.Caption = Val(txtUserInput.Text) * 10
ElseIf lstFrom.Selected(3) And lstTo.Selected(5) Then
lblResult.Caption = Val(txtUserInput.Text) * 100
ElseIf lstFrom.Selected(3) And lstTo.Selected(6) Then
lblResult.Caption = Val(txtUserInput.Text) * 1000
End If
If lstFrom.Selected(4) And lstTo.Selected(0) Then
lblResult.Caption = Val(txtUserInput.Text) / 10000
ElseIf lstFrom.Selected(4) And lstTo.Selected(1) Then
lblResult.Caption = Val(txtUserInput.Text) / 1000
ElseIf lstFrom.Selected(4) And lstTo.Selected(2) Then
lblResult.Caption = Val(txtUserInput.Text) / 100
ElseIf lstFrom.Selected(4) And lstTo.Selected(3) Then
lblResult.Caption = Val(txtUserInput.Text) / 10
ElseIf lstFrom.Selected(4) And lstTo.Selected(4) Then
lblResult.Caption = Val(txtUserInput.Text)
ElseIf lstFrom.Selected(4) And lstTo.Selected(5) Then
lblResult.Caption = Val(txtUserInput.Text) * 10
ElseIf lstFrom.Selected(4) And lstTo.Selected(6) Then
lblResult.Caption = Val(txtUserInput.Text) * 100
End If
If lstFrom.Selected(5) And lstTo.Selected(0) Then
lblResult.Caption = Val(txtUserInput.Text) / 100000
ElseIf lstFrom.Selected(5) And lstTo.Selected(1) Then
lblResult.Caption = Val(txtUserInput.Text) / 10000
ElseIf lstFrom.Selected(5) And lstTo.Selected(2) Then
lblResult.Caption = Val(txtUserInput.Text) / 1000
ElseIf lstFrom.Selected(5) And lstTo.Selected(3) Then
lblResult.Caption = Val(txtUserInput.Text) / 100
ElseIf lstFrom.Selected(5) And lstTo.Selected(4) Then
lblResult.Caption = Val(txtUserInput.Text) / 10
ElseIf lstFrom.Selected(5) And lstTo.Selected(5) Then
lblResult.Caption = Val(txtUserInput.Text)
ElseIf lstFrom.Selected(5) And lstTo.Selected(6) Then
lblResult.Caption = Val(txtUserInput.Text) * 10
End If
If lstFrom.Selected(6) And lstTo.Selected(0) Then
lblResult.Caption = Val(txtUserInput.Text) / 1000000
ElseIf lstFrom.Selected(6) And lstTo.Selected(1) Then
lblResult.Caption = Val(txtUserInput.Text) / 100000
ElseIf lstFrom.Selected(6) And lstTo.Selected(2) Then
lblResult.Caption = Val(txtUserInput.Text) / 10000
ElseIf lstFrom.Selected(6) And lstTo.Selected(3) Then
lblResult.Caption = Val(txtUserInput.Text) / 1000
ElseIf lstFrom.Selected(6) And lstTo.Selected(4) Then
lblResult.Caption = Val(txtUserInput.Text) / 100
ElseIf lstFrom.Selected(6) And lstTo.Selected(5) Then
lblResult.Caption = Val(txtUserInput.Text) / 10
ElseIf lstFrom.Selected(6) And lstTo.Selected(6) Then
lblResult.Caption = Val(txtUserInput.Text)
End If
End Sub
Private Sub cmdExit_Click()
Unload Me
End Sub
Private Sub Form_Load()
optLength.Value = True
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 optLength_Click()
lblDisplayUnit.Caption = "Unit length:"
Clear
lstFrom.AddItem "Kilometer (km)"
lstFrom.AddItem "Hektometer (hm)"
lstFrom.AddItem "Dekameter (dam)"
lstFrom.AddItem "Meter (m)"
lstFrom.AddItem "Desimeter (dm)"
lstFrom.AddItem "Centimeter (cm)"
lstFrom.AddItem "Milimeter (mm)"
For tmpList = 0 To (lstFrom.ListCount - 1)
lstTo.AddItem lstFrom.List(tmpList)
Next
End Sub
Private Sub optWeight_Click()
lblDisplayUnit.Caption = "Unit Weight:"
Clear
txtUserInput.SetFocus
lstFrom.AddItem "Kilogram (kg)"
lstFrom.AddItem "Hektogram (hg)"
lstFrom.AddItem "Dekagram (dag)"
lstFrom.AddItem "Gram (g)"
lstFrom.AddItem "Desigram (dg)"
lstFrom.AddItem "Centigram (cg)"
lstFrom.AddItem "Miligram (mg)"
For tmpList = 0 To (lstFrom.ListCount - 1)
lstTo.AddItem lstFrom.List(tmpList)
Next
End Sub
Private Sub Clear()
txtUserInput.Text = ""
lblResult.Caption = ""
lstFrom.Clear
lstTo.Clear
End Sub
Private Sub optVolume_Click()
lblDisplayUnit.Caption = "Unit Volume:"
Clear
txtUserInput.SetFocus
lstFrom.AddItem "Kiloliter (kl)"
lstFrom.AddItem "Hektoliter (hl)"
lstFrom.AddItem "Dekaliter (dal)"
lstFrom.AddItem "Liter (l)"
lstFrom.AddItem "Desiliter (dl)"
lstFrom.AddItem "Centiliter (cl)"
lstFrom.AddItem "Mililiter (ml)"
For tmpList = 0 To (lstFrom.ListCount - 1)
lstTo.AddItem lstFrom.List(tmpList)
Next
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
End If
End Sub
Label: VB6
0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda