hiiiiii
i have some problem for developing the code for addtion of 3x3 matrix class
the code which i have develop is given below.
but this class is not executed in vb.net code.
dont know whats getting wrong in it as m nt getting the required result.
please help me in correcting the code as m new in vb.net...
Public Class Matrix3x3
Private m_values(8) As Integer
Sub New()
' initialise array:
m_values = New Integer(8) {}
End Sub
' expose a member of the array:
Public Property Item(ByVal index As Integer) As Integer
Get
If index < 0 Or index > 8 Then Throw New ArgumentOutOfRangeException
Return m_values(index)
End Get
Set(ByVal value As Integer)
If index < 0 Or index > 8 Then Throw New ArgumentOutOfRangeException
m_values(index) = value
End Set
End Property
' allow get/set by row/column
Public Property Item(ByVal row As Integer, ByVal column As Integer) As Integer
Get
If row < 0 Or row > 2 Then Throw New System.ArgumentOutOfRangeException("3x3 array only!")
If column < 0 Or column > 2 Then Throw New System.ArgumentOutOfRangeException("3x3 array only!")
Dim index As Integer = (row * 3) + column
Return m_values(index)
End Get
Set(ByVal value As Integer)
If row < 0 Or row > 2 Then Throw New System.ArgumentOutOfRangeException("3x3 array only!")
If column < 0 Or column > 2 Then Throw New System.ArgumentOutOfRangeException("3x3 array only!")
Dim index As Integer = (row * 3) + column
m_values(index) = value
End Set
End Property
Public Function Add(ByVal matrixToAdd As Matrix3x3) As Matrix3x3
' declare a matrix to hold the result
Dim result As New Matrix3x3
' loop through arrays and the members of the two matrixes, store in the result matrix
For i As Integer = 0 To 8
result.Item(i) = m_values(i) + matrixToAdd.Item(i)
Next
Return result
End Function
Public Overrides Function ToString() As String
Dim msg As New System.Text.StringBuilder
' find the longest value when represented as string
Dim longest As Integer = -1
For i As Integer = 0 To 8
If m_values(i).ToString.Length > longest Then longest = m_values(i).ToString.Length
Next
' create the string
longest += 1
Dim width As String = longest.ToString
For y As Integer = 0 To 2
For x As Integer = 0 To 2
msg.Append(String.Format("{0," & width & "}", m_values((y * 3) + x)))
Next
msg.Append(Environment.NewLine)
Next
Return msg.ToString
End Function
End Class
this is vb.net code
Public Class Form1
Dim a1 As New Matrix3x3
Dim b1 As New Matrix3x3
Dim c1 As New Matrix3x3
Dim rand As New Random
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim m As New Matrix3x3
Dim n As New Matrix3x3
For row As Integer = 0 To 2
For col As Integer = 0 To 2
m.Item(row, col) = ((row * 3) + col) = Val(TextBox2.Text)
n.Item(row, col) = rand.Next(0, 2000) = Val(TextBox3.Text)
Next
Next
a1=val(textbox1.text)
b1=val(textbox2.text)
c1=c1.add(a1,b1)
textbox3.text=c1.tostring
End Sub
I want the result in textboxes where the inputs are given in textboxex manually...
here m,n are the rows and columns of matrix...
please help
thanx in advance