Sebelum Kita Memasukkan
Program Ada Baiknya Saya Sedikit Member Tau Teman Sekalian Objek –Objek Apa Saja Yang Kita Pakai Dalam Mendisain Form Konversi Bilangan Sederhana Ini Ok..
Atau Lebih Jelas Lagi ..Sebagai Contoh Disain Form Seperti Gambar Di Bawah :
Setelah Selesai Mendisain.. Jangan Lupa Untuk Merubah Name-Name PadaTexbox,Radiobutton,Button Dan Text Pada Label Pada kotak properties… Dan Sesuai Kan Dengan Program Yang Saya Buat J…
Selanjutnya gan mari kita masukkan program nya…ikuti langkah-langkah saya yak :
1) Klik double bebas di form …dan isikan printah :
Private Sub Form1_Load(ByVal senderAs System.Object, ByVal e AsSystem.EventArgs) HandlesMyBase.Load
MsgBox("Welcome To Program Konversi Bilangan", MsgBoxStyle.Information, "Welcome")
End Sub
End Sub
2) Klik double pada button konversi dan isikan printah ini :
Private Sub konversi_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles konversi.Click
hasil.Enabled = False
If input.Text = "" And hasil.Text = "" Then
MsgBox("Maaf !! Anda Harus Memasukkan Nilai")
Me.Focus()
If RadioButton2.Checked And RadioButton5.Checked Then hasil.Text = BinToDes(input.Text)
If RadioButton2.Checked And RadioButton6.Checked Then hasil.Text = input.Text
If RadioButton2.Checked And RadioButton7.Checked Then hasil.Text = BinToOk(input.Text)
If RadioButton2.Checked And RadioButton8.Checked Then hasil.Text = BinToHex(input.Text)
If RadioButton1.Checked And RadioButton6.Checked Then hasil.Text = DesToBin(input.Text)
If RadioButton1.Checked And RadioButton5.Checked Then hasil.Text = input.Text
If RadioButton1.Checked And RadioButton7.Checked Then hasil.Text = DesToOk(input.Text)
If RadioButton1.Checked And RadioButton8.Checked Then hasil.Text = DesToHex(input.Text)
If RadioButton3.Checked And RadioButton6.Checked Then hasil.Text = OkToBin(input.Text)
If RadioButton3.Checked And RadioButton8.Checked Then hasil.Text = OkToHex(input.Text)
If RadioButton3.Checked And RadioButton5.Checked Then hasil.Text = OkToDes(input.Text)
If RadioButton3.Checked And RadioButton7.Checked Then hasil.Text = input.Text
If RadioButton4.Checked And RadioButton6.Checked Then hasil.Text = HexToBin(input.Text)
If RadioButton4.Checked And RadioButton5.Checked Then hasil.Text = HexToDes(input.Text)
If RadioButton4.Checked And RadioButton7.Checked Then hasil.Text = HexToOk(input.Text)
If RadioButton4.Checked And RadioButton8.Checked Then hasil.Text = input.Text
With hasil
.SelectionStart = 0
.SelectionLength = Len(hasil.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 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
End While
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
NB:PROGRAM DIATAS KITA HARUS MEMBUAT FUNCTION(VARIABEL PEMANGGILAN) …Dan Selanjutnya…
3) Klik double pada button hapus dan isikan :
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Hapus.Click
input.Text = ""
hasil.Text = ""
End Sub
4) Dan klik double pada buuton keluar dan isikan :
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e AsSystem.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
Program pun selesai… dan coba di jalan kan dengan menekan tombol F5 pada keyboard…n jika ada yang error…coba di perhatikan name-name pada radio button untuk tidak di ubah
Ok…selamat mencoba
0 Comments:
Posting Komentar