home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 4_2005-2006.ISO / data / Zips / The_Matrix199261572006.psc / class / Matrix.cls < prev   
Text File  |  2006-05-05  |  2KB  |  78 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "Matrix"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Private theMatrix() As Double
  15. Private matRow As Integer
  16. Private matCol As Integer
  17.  
  18. Private Sub Initialize_Class()
  19.     Initialize 1, 1
  20.  
  21. End Sub
  22.  
  23. Public Sub Initialize(ByVal row As Integer, ByVal col As Integer)
  24.     ReDim theMatrix(1 To row, 1 To col) As Double
  25.     matRow = row
  26.     matCol = col
  27.     Dim a As Integer, b As Integer
  28.     
  29. End Sub
  30.  
  31. Property Get getRow()
  32.     getRow = matRow
  33.     
  34. End Property
  35.  
  36. Property Get getColumn()
  37.     getColumn = matCol
  38.     
  39. End Property
  40.  
  41. Sub setElementAt(ByVal val As Double, ByVal rowpos As Integer, ByVal colpos As Integer)
  42.     theMatrix(rowpos, colpos) = val
  43.     
  44. End Sub
  45. Function getElementAt(ByVal rowpos As Integer, ByVal colpos As Integer) As Double
  46.     getElementAt = theMatrix(rowpos, colpos)
  47.     
  48. End Function
  49. Sub clone(ByVal from As Matrix)
  50.     matRow = from.getRow
  51.     matCol = from.getColumn
  52.     
  53.     ReDim theMatrix(1 To matRow, 1 To matCol) As Double
  54.     Dim a As Integer, b As Integer
  55.     
  56.     For a = 1 To matRow Step 1
  57.         For b = 1 To matCol Step 1
  58.             theMatrix(a, b) = from.getElementAt(a, b)
  59.         Next
  60.     Next
  61. End Sub
  62. Function toString() As String
  63.     Dim tostr As String
  64.     Dim a As Integer, b As Integer
  65.     
  66.     tostr = ""
  67.     
  68.     For a = 1 To matRow Step 1
  69.         For b = 1 To matCol Step 1
  70.           tostr = tostr & theMatrix(a, b) & " "
  71.         Next
  72.         tostr = tostr & vbCrLf
  73.     Next
  74.     
  75.     toString = tostr
  76.     
  77. End Function
  78.