Hi there, I'm doing a project for one of my classes and I'm stuck trying to add two matrices. I managed to make the matrix via keypress, but when I input details for the calculate function (cals_click), I cannot find a way to add two matrices (which in design would be under ListA and ListB boxes). How do I approach this?
Private Sub Input_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Input.KeyPress
Dim x1, x2, x3 As String
Dim x23 As String
Dim pos1, pos2 As Integer
If Asc(e.KeyChar) = 13 Then
pos1 = InStr(Input.Text, ";")
x1 = Mid(Input.Text, 1, pos1 - 1)
x23 = Mid(Input.Text, pos1 + 2)
pos2 = InStr(x23, ";")
x2 = Mid(x23, 1, pos2 - 1)
x3 = Mid(x23, pos2 + 2)
If MA.Checked Then
ListA.Items.Add(x1)
ListA.Items.Add(x2)
ListA.Items.Add(x3)
End If
If MB.Checked Then
ListB.Items.Add(x1)
ListB.Items.Add(x2)
ListB.Items.Add(x3)
End If
If MC.Checked Then
ListC.Items.Add(x1)
ListC.Items.Add(x2)
ListC.Items.Add(x3)
End If
Input.Text = ""
End If
End Sub
Private Sub midinstr(ByVal x123 As String, ByRef x1 As Single, ByRef x2 As Single, ByRef x3 As Single)
Dim x23 As String
Dim pos1, pos2 As Integer
pos1 = InStr(x123, ",")
x1 = Val(Mid(x123, 1, pos1 - 1))
x23 = Mid(x123, pos1 + 1)
pos2 = InStr(x23, ",")
x2 = Val(Mid(x23, 1, pos2 - 1))
x3 = Val(Mid(x23, pos2 + 1))
End Sub
Private Sub Cals_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cals.Click
Dim A123, a2123, a3123 As String
Dim a1, a2, a3 As Single
Dim a21, a22, a23 As Single
Dim a31, a32, a33 As Single
Dim r As Double
If DA.Checked Then
A123 = ListA.Items(0)
midinstr(A123, a1, a2, a3)
a2123 = ListA.Items(1)
midinstr(a2123, a21, a22, a23)
a3123 = ListA.Items(2)
midinstr(a3123, a31, a32, a33)
r = a1 * (a22 * a33 - a23 * a32) - a2 * (a21 * a33 - a23 * a31) + a3 * (a21 * a32 - a22 * a31)
End If
If DB.Checked Then
A123 = ListB.Items(0)
midinstr(A123, a1, a2, a3)
a2123 = ListB.Items(1)
midinstr(a2123, a21, a22, a23)
a3123 = ListB.Items(2)
midinstr(a3123, a31, a32, a33)
r = a1 * (a22 * a33 - a23 * a32) - a2 * (a21 * a33 - a23 * a31) + a3 * (a21 * a32 - a22 * a31)
End If
R_Val.Text = Str(r)
If M1.Checked Then
ListD.Items.Add()
End If
End Sub