VB Program to Matrix Operation - Addition, Subtraction,Multiplication

Program to Matrix Operation - Addition, Subtraction,Multiplication

Sample code :

Declaration [General]


Dim a(20, 20), b(20, 20), c(20, 20), z, X, Y, x1, y1 As Integer


Reading array a(20,20)


Private Sub Text2_Change()
    z = Len(Text2.Text)
    Text2.SelStart = z - 1
    Text2.SelLength = z
    If (Val(Text2.SelText) > 0 And Val(Text2.SelText) < 9) Or Text2.SelText = " " Then
    Else
        x1 = x1 + 1
        y1 = 0
    End If
    If Text2.SelText = " " Then
        y1 = y1 + 1
    Else
        b(x1, y1) = b(x1, y1) * 10
        b(x1, y1) = b(x1, y1) + Val(Text2.SelText)
    End If
    Text2.SelStart = z
End Sub


Reading array b(20,20)


Private Sub Text1_Change()
    z = Len(Text1.Text)
    Text1.SelStart = z - 1
    Text1.SelLength = z
    If (Val(Text1.SelText) > 0 And Val(Text1.SelText) < 9) Or Text1.SelText = " " Then
    Else
        X = X + 1
        Y = 0
    End If
    If Text1.SelText = " " Then
        Y = Y + 1
    Else
        a(X, Y) = a(X, Y) * 10
        a(X, Y) = a(X, Y) + Val(Text1.SelText)
    End If
    Text1.SelStart = z
End Sub


Adding array a and b     [c=a+b]


Private Sub Command2_Click()
    Label1.Caption = "+"
    Dim i, j As Integer
    Dim s As String
    For i = 0 To X
        For j = 0 To Y
            c(i, j) = a(i, j) + b(i, j)
        Next j
    Next i
End Sub


Display array c on listbox


Private Sub Command1_Click()
    Dim i, j As Integer
    Dim s As String
    For i = 0 To X
        For j = 0 To Y
            s = s + Str(c(i, j)) + " "
        Next j
        List1.List(i) = s
        s = ""
    Next i


End Sub

Output(Matrix.exe)

Full code(Matrix.docx)

Full project(Matrix.vbp,.frm)

*Note Full project require Visual Basic 6.0