Pada artikel kali ini Admin akan berbagi sebuah kode untuk mengkonversi sebuah satuan berat menggunakan kode VB6.
Satuan berat ini sering kita temukan pada sebuah timbangan yang berguna untuk menghitung berapa berat barang tersebut.
Karena untuk menghitung berat kita tidak dapat menghitung secara manual dengan menggunakan rumus matematika salah satunya adalah dengan menimbang.
Konversi Berat |
Berikut adalah cara membuat konversi berat dengan menggunakan kode vb6 :
1. Buka Form VB6 dengan Standar EXE
2. Desainlah Form seperti gambar dibawah ini :
Desain Form |
3. Ketik kode dibawah ini :
Sub RumusKonversi()
If Combo1.Text = "Ton" And Combo2.Text = "Ton" Then
Text2.Text = Text1.Text
ElseIf Combo1.Text = "Ton" And Combo2.Text = "Kwintal" Then
Text2.Text = Val(Text1.Text) * 10
ElseIf Combo1.Text = "Ton" And Combo2.Text = "Kilogram" Then
Text2.Text = Val(Text1.Text) * 1000
ElseIf Combo1.Text = "Ton" And Combo2.Text = "Gram" Then
Text2.Text = Val(Text1.Text) * 10 ^ 6
ElseIf Combo1.Text = "Ton" And Combo2.Text = "Pound" Then
Text2.Text = (Val(Text1.Text) * 1000) / 0.45359237
ElseIf Combo1.Text = "Ton" And Combo2.Text = "Lb" Then
Text2.Text = ((Val(Text1.Text) * 1000) / 14.59) / 0.03108
ElseIf Combo1.Text = "Ton" And Combo2.Text = "Kip" Then
Text2.Text = (((Val(Text1.Text) * 1000) / 14.59) / 0.03108) / 1000
ElseIf Combo1.Text = "Ton" And Combo2.Text = "Slug" Then
Text2.Text = (Val(Text1.Text) * 1000) / 14.59
ElseIf Combo1.Text = "Kwintal" And Combo2.Text = "Ton" Then
Text2.Text = Val(Text1.Text) / 10
ElseIf Combo1.Text = "Kwintal" And Combo2.Text = "Kwintal" Then
Text2.Text = Text1.Text
ElseIf Combo1.Text = "Kwintal" And Combo2.Text = "Kilogram" Then
Text2.Text = Val(Text1.Text) * 100
ElseIf Combo1.Text = "Kwintal" And Combo2.Text = "Gram" Then
Text2.Text = Val(Text1.Text) * 10 ^ 5
ElseIf Combo1.Text = "Kwintal" And Combo2.Text = "Pound" Then
Text2.Text = (Val(Text1.Text) * 100) / 0.45359237
ElseIf Combo1.Text = "Kwintal" And Combo2.Text = "Lb" Then
Text2.Text = ((Val(Text1.Text) * 100) / 14.59) / 0.03108
ElseIf Combo1.Text = "Kwintal" And Combo2.Text = "Kip" Then
Text2.Text = (((Val(Text1.Text) * 100) / 14.59) / 0.03108) / 1000
ElseIf Combo1.Text = "Kwintal" And Combo2.Text = "Slug" Then
Text2.Text = (Val(Text1.Text) * 100) / 14.59
ElseIf Combo1.Text = "Kilogram" And Combo2.Text = "Ton" Then
Text2.Text = Val(Text1.Text) / 1000
ElseIf Combo1.Text = "Kilogram" And Combo2.Text = "Kwintal" Then
Text2.Text = Val(Text1.Text) / 100
ElseIf Combo1.Text = "Kilogram" And Combo2.Text = "Kilogram" Then
Text2.Text = Text1.Text
ElseIf Combo1.Text = "Kilogram" And Combo2.Text = "Gram" Then
Text2.Text = Val(Text1.Text) * 10 ^ 3
ElseIf Combo1.Text = "Kilogram" And Combo2.Text = "Pound" Then
Text2.Text = Val(Text1.Text) / 0.45359237
ElseIf Combo1.Text = "Kilogram" And Combo2.Text = "Lb" Then
Text2.Text = (Val(Text1.Text) / 14.59) / 0.03108
ElseIf Combo1.Text = "Kilogram" And Combo2.Text = "Kip" Then
Text2.Text = (((Val(Text1.Text) / 14.59) / 0.03108) / 1000)
ElseIf Combo1.Text = "Kilogram" And Combo2.Text = "Slug" Then
Text2.Text = Val(Text1.Text) / 14.59
ElseIf Combo1.Text = "Gram" And Combo2.Text = "Ton" Then
Text2.Text = Val(Text1.Text) / 10 ^ 6
ElseIf Combo1.Text = "Gram" And Combo2.Text = "Kwintal" Then
Text2.Text = Val(Text1.Text) * 10 ^ -5
ElseIf Combo1.Text = "Gram" And Combo2.Text = "Kilogram" Then
Text2.Text = Val(Text1.Text) * 10 ^ -3
ElseIf Combo1.Text = "Gram" And Combo2.Text = "Gram" Then
Text2.Text = Text1.Text
ElseIf Combo1.Text = "Gram" And Combo2.Text = "Pound" Then
Text2.Text = (Val(Text1.Text) * 10 ^ -3) / 0.45359237
ElseIf Combo1.Text = "Gram" And Combo2.Text = "Lb" Then
Text2.Text = ((Val(Text1.Text) * 10 ^ -3) / 14.59) / 0.03108
ElseIf Combo1.Text = "Gram" And Combo2.Text = "Kip" Then
Text2.Text = (((Val(Text1.Text) * 10 ^ -3) / 14.59) / 0.03108) / 1000
ElseIf Combo1.Text = "Gram" And Combo2.Text = "Slug" Then
Text2.Text = (Val(Text1.Text) * 10 ^ -3) / 14.59
ElseIf Combo1.Text = "Pound" And Combo2.Text = "Ton" Then
Text2.Text = (Val(Text1.Text) * 0.45359237) * 10 ^ -3
ElseIf Combo1.Text = "Pound" And Combo2.Text = "Kwintal" Then
Text2.Text = (Val(Text1.Text) * 0.45359237) * 10 ^ -2
ElseIf Combo1.Text = "Pound" And Combo2.Text = "Kilogram" Then
Text2.Text = Val(Text1.Text) * 0.45359237
ElseIf Combo1.Text = "Pound" And Combo2.Text = "Gram" Then
Text2.Text = (Val(Text1.Text) * 0.45359237) * 10 ^ 3
ElseIf Combo1.Text = "Pound" And Combo2.Text = "Pound" Then
Text2.Text = Text1.Text
ElseIf Combo1.Text = "Pound" And Combo2.Text = "Lb" Then
Text2.Text = ((Val(Text1.Text) * 0.45359237) / 14.59) / 0.03108
ElseIf Combo1.Text = "Pound" And Combo2.Text = "Kip" Then
Text2.Text = (((Val(Text1.Text) * 0.45359237) / 14.59) / 0.03108) / 1000
ElseIf Combo1.Text = "Pound" And Combo2.Text = "Slug" Then
Text2.Text = (Val(Text1.Text) * 0.45359237) / 14.59
ElseIf Combo1.Text = "Lb" And Combo2.Text = "Ton" Then
Text2.Text = ((Val(Text1.Text) * 0.03108) * 14.59) * 10 ^ 3
ElseIf Combo1.Text = "Lb" And Combo2.Text = "Kwintal" Then
Text2.Text = ((Val(Text1.Text) * 0.03108) * 14.59) * 10 ^ 2
ElseIf Combo1.Text = "Lb" And Combo2.Text = "Kilogram" Then
Text2.Text = (Val(Text1.Text) * 0.03108) * 14.59
ElseIf Combo1.Text = "Lb" And Combo2.Text = "Gram" Then
Text2.Text = ((Val(Text1.Text) * 0.03108) * 14.59) * 10 ^ -3
ElseIf Combo1.Text = "Lb" And Combo2.Text = "Pound" Then
Text2.Text = ((Val(Text1.Text) * 0.03108) * 14.59) / 0.45359237
ElseIf Combo1.Text = "Lb" And Combo2.Text = "Lb" Then
Text2.Text = Text1.Text
ElseIf Combo1.Text = "Lb" And Combo2.Text = "Kip" Then
Text2.Text = Val(Text1.Text) / 1000
ElseIf Combo1.Text = "Lb" And Combo2.Text = "Slug" Then
Text2.Text = Val(Text1.Text) * 0.03108
ElseIf Combo1.Text = "Kip" And Combo2.Text = "Ton" Then
Text2.Text = (((Val(Text1.Text) * 1000) * 0.03108) * 14.59) / 10 ^ -3
ElseIf Combo1.Text = "Kip" And Combo2.Text = "Kwintal" Then
Text2.Text = (((Val(Text1.Text) * 1000) * 0.03108) * 14.59) / 10 ^ -2
ElseIf Combo1.Text = "Kip" And Combo2.Text = "Kilogram" Then
Text2.Text = ((Val(Text1.Text) * 1000) * 0.03108) * 14.59
ElseIf Combo1.Text = "Kip" And Combo2.Text = "Gram" Then
Text2.Text = (((Val(Text1.Text) * 1000) * 0.03108) * 14.59) / 10 ^ 3
ElseIf Combo1.Text = "Kip" And Combo2.Text = "Pound" Then
Text2.Text = (((Val(Text1.Text) * 1000) * 0.03108) * 14.59) / 0.45359237
ElseIf Combo1.Text = "Kip" And Combo2.Text = "Lb" Then
Text2.Text = Val(Text1.Text) * 1000
ElseIf Combo1.Text = "Kip" And Combo2.Text = "Kip" Then
Text2.Text = Text1.Text
ElseIf Combo1.Text = "Kip" And Combo2.Text = "Slug" Then
Text2.Text = (Val(Text1.Text) * 1000) * 0.03108
ElseIf Combo1.Text = "Slug" And Combo2.Text = "Ton" Then
Text2.Text = (Val(Text1.Text) * 14.59) * 10 ^ -3
ElseIf Combo1.Text = "Slug" And Combo2.Text = "Kwintal" Then
Text2.Text = (Val(Text1.Text) * 14.59) * 10 ^ -2
ElseIf Combo1.Text = "Slug" And Combo2.Text = "Kilogram" Then
Text2.Text = Val(Text1.Text) * 14.59
ElseIf Combo1.Text = "Slug" And Combo2.Text = "Gram" Then
Text2.Text = (Val(Text1.Text) * 14.59) * 10 ^ 3
ElseIf Combo1.Text = "Slug" And Combo2.Text = "Pound" Then
Text2.Text = (Val(Text1.Text) * 14.59) / 0.45359273
ElseIf Combo1.Text = "Slug" And Combo2.Text = "Lb" Then
Text2.Text = Val(Text1.Text) / 0.03108
ElseIf Combo1.Text = "Slug" And Combo2.Text = "Kip" Then
Text2.Text = (Val(Text1.Text) / 0.03108) / 1000
ElseIf Combo1.Text = "Slug" And Combo2.Text = "Slug" Then
Text2.Text = Text1.Text
End If
End Sub
Private Sub Command1_Click()
Call RumusKonversi
End Sub
Private Sub Form_Load()
Combo1.Text = "Pilih Satuan"
Combo1.AddItem "Ton"
Combo1.AddItem "Kwintal"
Combo1.AddItem "Kilogram"
Combo1.AddItem "Gram"
Combo1.AddItem "Pound"
Combo1.AddItem "Lb"
Combo1.AddItem "Kip"
Combo1.AddItem "Slug"
Combo2.Text = "Pilih Satuan"
Combo2.AddItem "Ton"
Combo2.AddItem "Kwintal"
Combo2.AddItem "Kilogram"
Combo2.AddItem "Gram"
Combo2.AddItem "Pound"
Combo2.AddItem "Lb"
Combo2.AddItem "Kip"
Combo2.AddItem "Slug"
Text1.Text = ""
Text2.Text = ""
End Sub
4. Jalankan project Anda, jika tidak ada error maka hasilnya akan tampak pada gambar diatas awal artikel.
Demikianlah artikel singkat hari ini mengenai Cara Membuat Konversi Berat Dengan Kode VB6.
Semoga artikel ini bermanfaat buat kita semua,Amin.
Selamat mencoba semoga berhasil.
No comments:
Post a Comment