CARA MEMBUAT PROGRAM KONVERSI BILANGAN DENGAN VISUAL STUDIO 2012


  1. Buat desain form seperti berikut:

Dengan keterangan :

 
Toolbox
Name Text
Name Desain
Label1
APLIKASI KONVERSI BILANGAN
Label1
Label2
INPUT NILAI
Label2
Label3
HASIL
Label3
Groupbox1
TYPE KONVERSI BILANGAN INPUT
Groupbox1
Groupbox2
TYPE KONVERSI BILANGAN OUTPUT
Groupbox2
RadioButton1
DESIMAL
RadioButtonDecimal_in
RadioButton2
BINER
RadioButtonBiner_In
RadioButton3
OKTAL
RadioButtonOktal_in
RadioButton4
HEXADESIMAL
RadioButtonHexa_In
RadioButton5
DESIMAL
RadioButtonDecimalOut
RadioButton6
BINER
RadioButtonBinerOut
RadioButton7
OKTAL
RadioButtonOktalOut
RadioButton8
HEXADESIMAL
RadioButtonHexaOut
Button1
KONVERSI
Button1
Button2
HAPUS
Button2
Button3
KELUAR
Button3
Form1
Aplikasi Konversi Bilangan
Konversi

 2.      Double klik di area kosong form1, Masukkan sintak berikut:
Private Sub Konversi_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        TextBoxOutput.Enabled = False
    End Sub

3.      Letakkan sintak Option Explicit On diatas sintak Public Class Konversi
Seperti contoh dibawah
Option Explicit On
Public Class Konversi

4.      Masukkan sintak berikut untuk rumus konversi bilangan
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 Integer
        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 OkToBin(ByVal NOktal As Double) As String
        OkToBin = DesToBin(OkToDes(NOktal))
    End Function
    Public Function BinToHex(ByVal NBiner As Long) As String
        BinToHex = DesToHex(BinToDes(NBiner))
    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  

5.      5. Double klik pada Button 1 Atau Button Konversi, Masukkan Sintak Berikut:
If RadioButtonBiner_In.Checked And RadioButtonDecimalOut.Checked Then TextBoxOutput.Text = BinToDes(TextBoxInput.Text)
        If RadioButtonBiner_In.Checked And RadioButtonBinerOut.Checked Then TextBoxOutput.Text = TextBoxInput.Text
        If RadioButtonBiner_In.Checked And RadioButtonOktalOut.Checked Then TextBoxOutput.Text = BinToOk(TextBoxInput.Text)
        If RadioButtonBiner_In.Checked And RadioButtonHexaOut.Checked Then TextBoxOutput.Text = BinToHex(TextBoxInput.Text)
        If RadioButtonDecimal_in.Checked And RadioButtonBinerOut.Checked Then TextBoxOutput.Text = DesToBin(TextBoxInput.Text)
        If RadioButtonDecimal_in.Checked And RadioButtonDecimalOut.Checked Then TextBoxOutput.Text = TextBoxInput.Text
        If RadioButtonDecimal_in.Checked And RadioButtonOktalOut.Checked Then TextBoxOutput.Text = DesToOk(TextBoxInput.Text)
        If RadioButtonDecimal_in.Checked And RadioButtonHexaOut.Checked Then TextBoxOutput.Text = DesToHex(TextBoxInput.Text)
        If RadioButtonOktal_in.Checked And RadioButtonBinerOut.Checked Then TextBoxOutput.Text = OkToBin(TextBoxInput.Text)
        If RadioButtonOktal_in.Checked And RadioButtonHexaOut.Checked Then TextBoxOutput.Text = OkToHex(TextBoxInput.Text)
        If RadioButtonOktal_in.Checked And RadioButtonDecimalOut.Checked Then TextBoxOutput.Text = OkToDes(TextBoxInput.Text)
        If RadioButtonOktal_in.Checked And RadioButtonOktalOut.Checked Then TextBoxOutput.Text = TextBoxInput.Text
        If RadioButtonHexa_In.Checked And RadioButtonBinerOut.Checked Then TextBoxOutput.Text = HexToBin(TextBoxInput.Text)
        If RadioButtonHexa_In.Checked And RadioButtonDecimalOut.Checked Then TextBoxOutput.Text = HexToDes(TextBoxInput.Text)
        If RadioButtonHexa_In.Checked And RadioButtonOktalOut.Checked Then TextBoxOutput.Text = HexToOk(TextBoxInput.Text)
        If RadioButtonHexa_In.Checked And RadioButtonHexaOut.Checked Then TextBoxOutput.Text = TextBoxInput.Text
        If TextBoxInput.Text = "" Then
            MsgBox("maaf ???? anda belum memasukan bilangan")
        End If


6.      6. Double klik di Button2 atau Button Hapus, Masukkan sintak berikut:
TextBoxInput.Text = ""
TextBoxOutput.Text = ""
TextBoxInput.Focus()

7.      7. Double klik di Button3 atau Button Keluar,Masukkan sintak berikut:
Dim tutup As String
        tutup = MessageBox.Show("Anda Yakin Ingin Menutup Program ini ?", "INFORMASI", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If tutup = MsgBoxResult.Yes Then
            End
        Else
        End If

Sekian dari saya

2 komentar

Bang buat rumus itu dimana tarok coding nya?


EmoticonEmoticon