怎么将text控件中所输入的矩阵放入二维数组中?

解决方案 »

  1.   

    比如说在一个文本框里面输入
    1 2 3 4
    5 6 7 8
    7 8 9 6
    然后将这些数放入a(i,j)中
    应该怎么做啊?
    我主要想做一个数学方面的软件
      

  2.   

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    Private Const EM_GETLINE = &HC4
    Private Const EM_GETLINECOUNT = &HBA
    Dim lngLineCount As Long
    Dim strData As String
    Private Const NumMax = 10Private Sub Command1_Click()
       Dim a(1 To NumMax, 1 To NumMax) As Integer
       Dim i As Integer, j As Integer
       Dim intBegin As Integer, intEnd As Integer
       lngLineCount = GetCount
       
       '得到有效行
       For i = 1 To lngLineCount
         If Len(GetData(i - 1)) < 0 Then
           Exit For
           lngLineCount = i
         End If
       Next i
       
       For i = 1 To lngLineCount
          strData = GetData(i - 1)
          intBegin = 0
          intEnd = 0
         For j = 1 To lngLineCount
           
            
            intEnd = InStr(intBegin + 1, strData, " ")
            
            If intBegin >= intEnd Then intEnd = Len(strData)
            
            a(i, j) = Val(Mid(strData, intBegin + 1, intEnd - intBegin))
             intBegin = InStr(intBegin + 1, strData, " ")
             
           If intBegin <= 0 Then Exit For
         Next j
      Next i
         
      '显示
      strData = ""
      For i = 1 To lngLineCount
         For j = 1 To lngLineCount
            strData = strData + Str(a(i, j)) + " "
           
         Next j
         strData = strData + vbCrLf
      Next i
      
      MsgBox strData
      
    End Sub
    '获得总行数
    Private Function GetCount() As Long
       GetCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    End Function'获得指定行的内容
    Private Function GetData(index As Integer) As String
       Dim lngRet As Long
       Dim strTemp As String
       strTemp = Space$(1056)
       lngRet = SendMessage(Text1.hwnd, EM_GETLINE, index, ByVal strTemp)
       GetData = Trim(strTemp)
    End Function