Source Code :
Public Class Form1
Dim Nilai As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("Selamat Datang Di Program Konversi Bilangan", MsgBoxStyle.Information, "Welcome")
End Sub
Public Function DesToBin(ByVal NDesimal As Long) As String
Dim C As Byte
Dim D As Long
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
End While
DesToBin = Nilai
Exit Function
ErrorHandler:
DesToBin = 0
End Function
Public Function DesToOk(ByVal NDesimal As Long) As String
DesToOk = Oct(NDesimal)
End Function
Public Function DesToHex(ByVal NDesimal As Long) As String
DesToHex = Hex(NDesimal)
End Function
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 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 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 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 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 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 Konversi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Konversi.Click
Output.Enabled = False
If Input.Text = "" And Output.Text = "" Then
MsgBox("Maaf !!! Anda Harus Memasukkan Nilai")
Me.Focus()
End If
If mDesimal.Checked And kDesimal.Checked Then Output.Text = Input.Text
If mDesimal.Checked And kBiner.Checked Then Output.Text = DesToBin(Input.Text)
If mDesimal.Checked And kOktal.Checked Then Output.Text = DesToOk(Input.Text)
If mDesimal.Checked And kHexadesimal.Checked Then Output.Text = DesToHex(Input.Text)
If mBiner.Checked And kDesimal.Checked Then Output.Text = BinToDes(Input.Text)
If mBiner.Checked And kBiner.Checked Then Output.Text = Input.Text
If mBiner.Checked And kOktal.Checked Then Output.Text = BinToOk(Input.Text)
If mBiner.Checked And kHexadesimal.Checked Then Output.Text = BinToHex(Input.Text)
If mOktal.Checked And kDesimal.Checked Then Output.Text = OkToDes(Input.Text)
If mOktal.Checked And kBiner.Checked Then Output.Text = OkToBin(Input.Text)
If mOktal.Checked And kOktal.Checked Then Output.Text = Input.Text
If mOktal.Checked And kHexadesimal.Checked Then Output.Text = OkToHex(Input.Text)
If mHexadesimal.Checked And kDesimal.Checked Then Output.Text = HexToDes(Input.Text)
If mHexadesimal.Checked And kBiner.Checked Then Output.Text = HexToBin(Input.Text)
If mHexadesimal.Checked And kOktal.Checked Then Output.Text = HexToOk(Input.Text)
If mHexadesimal.Checked And kHexadesimal.Checked Then Output.Text = Input.Text
With Output
.SelectionStart = 0
.SelectionLength = Len(Output.Text)
End With
End Sub
Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
Input.Text = ""
Output.Text = ""
End Sub
Private Sub Keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Keluar.Click
Dim x As String
x = MsgBox("Apakah Anda Ingin Keluar?", MsgBoxStyle.Information + MsgBoxStyle.OkCancel, "Keluar")
If x = vbCancel Then
Me.Focus()
ElseIf x = vbOK Then
Me.Close()
End If
End Sub
End Class
Sekian artikel saya, semoga bermanfaat untuk kita semua !!!