1. Desimal
Bilangan desimal adalah bilangan yang mempunyai sepuluh simbol angka yaitu 0,1,2,3,4,5,6,7,8,9.
2. Heksadesimal
Bilangan heksadesimal adalah bilangan yang mempunyai enam belas simbol angka yaitu 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
3. Biner
Bilangan Biner adalah bilangan yang mempunyai dua simbol 0 dan 1
4. Oktal
Bilangan heksadesimal adalah bilangan yang mempunyai delapan simbol angka yaitu 0,1,2,3,4,5,6,7
Berikut tabel Konversi Bilangan:
Desimal | Biner | Oktal | Hexadesimal |
0 | 0 | 0 | 0 |
1 | 1 | 1 | 1 |
2 | 10 | 2 | 2 |
3 | 11 | 3 | 3 |
4 | 100 | 4 | 4 |
5 | 101 | 5 | 5 |
6 | 110 | 6 | 6 |
7 | 111 | 7 | 7 |
8 | 1000 | 10 | 8 |
9 | 1001 | 11 | 9 |
10 | 1010 | 12 | A |
11 | 1011 | 13 | B |
12 | 1100 | 14 | C |
13 | 1101 | 15 | D |
14 | 1110 | 16 | E |
15 | 1111 | 17 | F |
Baiklah kita akan membuat program Aplikasi Konversi Bilangan dengan VB dimana aplikasi ini akan membantu anda mengkonversikan bilangan secara cepat dan tepat :
1. Seperti biasa buatlah New Project pada software VB anda kemudian tambahkan 11 label, 2 textbox, 2 frame, 8 optionbutton, dan 3 commandbutton.
2. Desainlah menjadi seperti gambar dibawah ini :
3. Dan setiap beri nama setiap textbox dan optionbutton seperti text warna coklat tersebut, mengganti namanya di Propertiesbar. Jika ada kekeliruan form tidak berjalan dengan sempurna :v
4. Lalu Copy code/script dibawah ini
Untuk Tombol Clearnya
Private Sub cmdclear_Click()
txtmasuk.Text = ""
txtkeluar.Caption = ""
txtmasuk.SetFocus
optdesimalm.Value = False
optbinerm.Value = False
optoktalm.Value = False
optheksam.Value = False
optdesimalk.Value = False
optbinerk.Value = False
optoktalk.Value = False
optheksak.Value = False
End Sub
Untuk Tombol Exitnya
Private Sub cmdexit_Click()
x = MsgBox("Do you want to exit now ?", vbYesNo, "Information")
If x = vbYes Then
Unload Me
Else
End If
End Sub
Untuk Tombol Konversinya
Private Sub cmdkonversi_Click()
If optbinerm.Value And optdesimalk.Value Then txtkeluar.Caption = BinToDes(txtmasuk.Text)
If optbinerm.Value And optbinerk.Value Then txtkeluar.Caption = txtmasuk.Text
If optbinerm.Value And optoktalk.Value Then txtkeluar.Caption = BinToOk(txtmasuk.Text)
If optbinerm.Value And optheksak.Value Then txtkeluar.Caption = BinToHex(txtmasuk.Text)
If optdesimalm.Value And optbinerk.Value Then txtkeluar.Caption = DesToBin(txtmasuk.Text)
If optdesimalm.Value And optdesimalk.Value Then txtkeluar.Caption = txtmasuk.Text
If optdesimalm.Value And optoktalk.Value Then txtkeluar.Caption = DesToOk(txtmasuk.Text)
If optdesimalm.Value And optheksak.Value Then txtkeluar.Caption = DesToHex(txtmasuk.Text)
If optoktalm.Value And optbinerk.Value Then txtkeluar.Caption = OkToBin(txtmasuk.Text)
If optoktalm.Value And optheksak.Value Then txtkeluar.Caption = OkToHex(txtmasuk.Text)
If optoktalm.Value And optdesimalk.Value Then txtkeluar.Caption = OkToDes(txtmasuk.Text)
If optoktalm.Value And optoktalk.Value Then txtkeluar.Caption = txtmasuk.Text
If optheksam.Value And optbinerk.Value Then txtkeluar.Caption = HexToBin(txtmasuk.Text)
If optheksam.Value And optdesimalk.Value Then txtkeluar.Caption = HexToDes(txtmasuk.Text)
If optheksam.Value And optoktalk.Value Then txtkeluar.Caption = HexToOk(txtmasuk.Text)
If optheksam.Value And optheksak.Value Then txtkeluar.Caption = txtmasuk.Text
With txtmasuk
.SelStart = 0
.SelLength = Len(txtmasuk.Text)
End With
End Sub
Public Function BinToDes(ByVal NBiner As String) As Long
Dim A As Integer
Dim B As Long
Dim Nilai As Long
On Error GoTo ErrorHandler
B = 1
For A = Len(NBiner) To 1 Step -1
If Mid(NBiner, A, 1) = "1" Then Nilai = Nilai + B
B = B * 2
Next
BinToDes = Nilai
Exit Function
ErrorHandler:
BinToDes = 0
End Function
Public Function DesToBin(ByVal NDesimal As Long) As String
Dim C As Byte
Dim D As Long
Dim Nilai As String
On Error GoTo ErrorHandler
D = (2 ^ 31) - 1
While D > 0
If NDesimal - D >= 0 Then
NDesimal = NDesimal - D
Nilai = Nilai & "1"
Else
If Val(Nilai) > 0 Then Nilai = Nilai & "0"
End If
D = D / 2
Wend
DesToBin = Nilai
Exit Function
ErrorHandler:
DesToBin = 0
End Function
Public Function DesToHex(ByVal NDesimal As Long) As String
DesToHex = Hex(NDesimal)
End Function
Public Function HexToDes(ByVal NHexa As String) As Long
Dim E As Integer
Dim Nilai As Long
Dim F As Long
Dim CharNilai As Byte
On Error GoTo ErrorHandler
For E = Len(NHexa) To 1 Step -1
Select Case Mid(NHexa, E, 1)
Case "0" To "9": CharNilai = CInt(Mid(NHexa, E, 1))
Case Else: CharNilai = Asc(Mid(NHexa, E, 1)) - 55
End Select
Nilai = Nilai + ((16 ^ F) * CharNilai)
F = F + 1
Next E
HexToDes = Nilai
Exit Function
ErrorHandler:
HexToDes = 0
End Function
Public Function DesToOk(ByVal NDesimal As Long) As String
DesToOk = Oct(NDesimal)
End Function
Public Function OkToDes(ByVal NOktal As String) As Long
Dim G As Integer
Dim H As Long
Dim Nilai As Long
On Error GoTo ErrorHandler
For G = Len(NOktal) To 1 Step -1
Nilai = Nilai + (8 ^ H) * CInt(Mid(NOktal, G, 1))
H = H + 1
Next G
OkToDes = Nilai
Exit Function
ErrorHandler:
OkToDes = 0
End Function
Public Function BinToOk(ByVal bin As Long) As String
BinToOk = DesToOk(BinToDes(bin))
End Function
Public Function BinToHex(ByVal NBiner As Long) As String
BinToHex = DesToHex(BinToDes(NBiner))
End Function
Public Function OkToBin(ByVal NOktal As Double) As String
OkToBin = DesToBin(OkToDes(NOktal))
End Function
Public Function OkToHex(ByVal NOktal As Double) As String
OkToHex = DesToHex(OkToDes(NOktal))
End Function
Public Function HexToBin(ByVal NHexa As String) As String
HexToBin = DesToBin(HexToDes(NHexa))
End Function
Public Function HexToOk(ByVal NHexa As String) As Double
HexToOk = DesToOk(HexToDes(NHexa))
End Function
Private Sub FrKonBil_Load()
Welcome = MsgBox("Konversi Bilangan by Chimpunk!", vbInformation, "Thanks to XTKJD")
If Welcom = okvb Then
Unload Me
Else
OpenURL "http://blogspot.com", Me.hWnd
End If
Move (Screen.Width - Me.Width) / 2, (Screen.Height - Me.Height) / 2
txtmasuk.Text = ""
txtkeluar.Caption = ""
End Sub
Private Sub Form_Load()
End Sub
6. Coba Run/Play form tadi.
7. Tadaaa! udah jadi. Selamat bereksperimen Gan
0 comments:
Post a Comment