Mesran

Hanya ingin berbagi kebaikan dan mendapatkan kebaikan yang lain.

VB Tips : Kolom Matrik Dengan Visual Basic

Microsoft Visual Basic

Microsoft Visual Basic

Anda mungkin ribet membuat kolom kolom matrik dengan Visual Basic yah. Pada postingan ini saya akan memberikan contoh program untuk menginputkan sebuah matrik. Tapi hanya satu matrik aja, selebihnya pengembangan anda sendiri aja deh😀

Matrik yang kita buat ini memanfaatkan FlexGrid, karna dengan komponen ini akan lebih mudah mendesain dan memprogramnya, dibandingkan bila membuat dengan textbox. Bahkan lebih efektif lagi.😀

Design Fom


Berikut listing programnya.

Dim bDtRAB As Integer ' 0=nothing,1 =edit ,2=new
Private Type FlxCell
  row As Long
  col As Long
End Type

Private m_ActiveCell As FlxCell

Private Sub BARA_Change()
        BuatMatrikA MatrikA, KOLA, BARA
End Sub

Private Sub Form_Load()
        KOLA = ""
        BARA = ""
End Sub

Private Sub KOLA_Change()
        BuatMatrikA MatrikA, KOLA, BARA
End Sub

Sub BuatMatrikA(obj As Object, kolom As Object, baris As Object)
        On Error Resume Next
        obj.Cols = kolom + 1
        obj.Rows = baris + 1
        obj.Width = (kolom + 1) * 1200
        obj.Height = (baris + 1) * 330
        obj.col = 0
        obj.row = 0
        obj.Text = "A"
        obj.row = 0
        For i = 1 To kolom
            obj.col = i
            obj.Text = i
        Next i
        obj.col = 0
        For i = 1 To baris
            obj.row = i
            obj.Text = i
        Next i
End Sub

Private Sub MatrikA_Click()
        If (bDtRAB = 2 And Me.MatrikA.row < Me.MatrikA.Rows - 1) And Me.MatrikA.col = 6 Then Exit Sub

        m_ActiveCell.row = MatrikA.row
        m_ActiveCell.col = MatrikA.col
        With txtEdit
                    .Top = MatrikA.CellTop + MatrikA.Top
                    .Left = MatrikA.CellLeft + MatrikA.Left
                    .Width = MatrikA.CellWidth
                    .Text = MatrikA.Text
                    .Visible = True
                    .ZOrder
                    .SetFocus
        End With
        RAbTmp = Me.txtEdit
End Sub

Private Sub MatrikA_KeyPress(KeyAscii As Integer)
        If KeyAscii = 13 Then MatrikA_Click
End Sub

Private Sub txtEdit_GotFocus()
            txtEdit.SelStart = Len(txtEdit.Text)
End Sub

Private Sub txtEdit_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
        Case vbKeyEscape
            KeyAscii = 0
            Me.MatrikA.SetFocus
        Case vbKeyReturn
            txtEdit_LostFocus
            KeyAscii = 0
            Me.MatrikA.SetFocus
    End Select
End Sub

Private Sub txtEdit_LostFocus()
            MatrikA.TextMatrix(m_ActiveCell.row, m_ActiveCell.col) = txtEdit.Text
            txtEdit.Visible = False
End Sub

Program selengkapnya unduh disini
Selamat Berpikir :D

Filed under: VB Tips,

8 Responses

  1. san says:

    pak, kalo matriknya 2, code nya gimana pak,dah saya coba ga bisa.btuh bnget buat tugas akhir.trims..

  2. san says:

    mas, kalo 2 matrik code nya gimana, saya dah coba ga bisa, tolong dong mas, butuh banget buat tugas akhir.trims..

    • Mesran says:

      Program tersebut sudah saya buat menggunakan sub yang fleksibel, seperti :
      pembuatan matrik A : tinggal panggil BuatMatrikA MatrikA, KOLA, BARA

      jadi kalau mau di buat matrik B : tinggal rubah BuatMatrikA MatrikB, KOLB, BARB (yah di buat lah grid untuk MatrikB dengan texbox KOLB dan BARB) ok

      • san says:

        mas,ini sudah saya coba bikin, tapi error pas mau di isi jumlah barisnya,salahnya dimana ya mas? trims..

        Dim bDtRAB As Integer ‘ 0=nothing,1 =edit ,2=new
        Private Type FlxCell
        row As Long
        col As Long
        End Type

        Private m_ActiveCell As FlxCell

        Private Sub BARA_Change()
        BuatMatrikA MatrikA, KOLA, BARA
        End Sub
        Private Sub BARB_Change()
        BuatMatrikB MatrikB, KOLB, BARB
        End Sub

        Private Sub Form_Load()
        KOLA = “”
        BARA = “”
        KOLB = “”
        BARB = “”
        End Sub

        Private Sub KOLA_Change()
        BuatMatrikA MatrikA, KOLA, BARA
        End Sub
        Private Sub KOLB_Change()
        BuatMatrikB MatrikB, KOLB, BARB
        End Sub

        Sub BuatMatrikA(obj As Object, kolom As Object, baris As Object)
        On Error Resume Next
        obj.Cols = kolom + 1
        obj.Rows = baris + 1
        obj.Width = (kolom + 1) * 1200
        obj.Height = (baris + 1) * 330
        obj.col = 0
        obj.row = 0
        obj.Text = “A”
        obj.row = 0
        For i = 1 To kolom
        obj.col = i
        obj.Text = i
        Next i
        obj.col = 0
        For i = 1 To baris
        obj.row = i
        obj.Text = i
        Next i
        End Sub
        Sub BuatMatrikB(obj As Object, kolom As Object, baris As Object)
        On Error Resume Next
        obj.Cols = kolom + 1
        obj.Rows = baris + 1
        obj.Width = (kolom + 1) * 1200
        obj.Height = (baris + 1) * 330
        obj.col = 0
        obj.row = 0
        obj.Text = “B”
        obj.row = 0
        For i = 1 To kolom
        obj.col = i
        obj.Text = i
        Next i
        obj.col = 0
        For i = 1 To baris
        obj.row = i
        obj.Text = i
        Next i
        End Sub

        Private Sub MatrikA_Click()
        If (bDtRAB = 2 And Me.MatrikA.row < Me.MatrikA.Rows – 1) And Me.MatrikA.col = 6 Then Exit Sub

        m_ActiveCell.row = MatrikA.row
        m_ActiveCell.col = MatrikA.col
        With txtEdit
        .Top = MatrikA.CellTop + MatrikA.Top
        .Left = MatrikA.CellLeft + MatrikA.Left
        .Width = MatrikA.CellWidth
        .Text = MatrikA.Text
        .Visible = True
        .ZOrder
        .SetFocus
        Private Sub MatrikB_Click()
        If (bDtRAB = 2 And Me.MatrikB.row < Me.MatrikA.Rows – 1) And Me.MatrikB.col = 6 Then Exit Sub

        m_ActiveCell.row = MatrikB.row
        m_ActiveCell.col = MatrikB.col
        With txtEdit
        .Top = MatrikB.CellTop + MatrikB.Top
        .Left = MatrikB.CellLeft + MatrikB.Left
        .Width = MatrikB.CellWidth
        .Text = MatrikB.Text
        .Visible = True
        .ZOrder
        .SetFocus
        End With
        RAbTmp = Me.txtEdit
        End Sub

        Private Sub MatrikA_KeyPress(KeyAscii As Integer)
        If KeyAscii = 13 Then MatrikA_Click
        Private Sub MatrikB_KeyPress(KeyAscii As Integer)
        If KeyAscii = 13 Then MatrikB_Click
        End Sub

        Private Sub txtEdit_GotFocus()
        txtEdit.SelStart = Len(txtEdit.Text)
        End Sub

        Private Sub txtEdit_KeyPress(KeyAscii As Integer)
        Select Case KeyAscii
        Case vbKeyEscape
        KeyAscii = 0
        Me.MatrikA.SetFocus
        Case vbKeyReturn
        txtEdit_LostFocus
        KeyAscii = 0
        Me.MatrikA.SetFocus
        Private Sub txtEdit2_KeyPress(KeyAscii As Integer)
        Select Case KeyAscii
        Case vbKeyEscape
        KeyAscii = 0
        Me.MatrikB.SetFocus
        Case vbKeyReturn
        txtEdit_LostFocus
        KeyAscii = 0
        Me.MatrikB.SetFocus
        End Select
        End Sub

        Private Sub txtEdit_LostFocus()
        MatrikA.TextMatrix(m_ActiveCell.row, m_ActiveCell.col) = txtEdit.Text
        txtEdit.Visible = False
        End Sub

  3. pak…bisa kirim contoh program VB nya g ke email saya….
    coz saya kurang ngerti sama penjelasan di atas, saya bingung coding nya di ketikan di objek yang mana…
    kalau boleh, tolong kirimkan program sederhana nya ke email saya azifebriansyah@yahoo.co.id
    terima kasih sebelum nya ya pak…:)

  4. sir…!!!

    leh mnt program VB a ..??

  5. muti says:

    makasih y pak ats pencerahanya,,
    mau tie coba dlu ach..!! ^_^

Terima kasih telah memberikan komentar anda.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Archives Per Tahun

%d bloggers like this: