........................
.......................
0.231 -1.29 -2.848 -3.263 -4.159 -3.224 -1.95
0.044 1.292 2.438 2.018 0.502 -0.868 2.065
3.093 0.168 -1.055 -0.414 -2.132 -4.681 -2.4
1.445 -0.551 1.208 1.754 1.408 0.127 0.366
1.461 1.725 0.937 0.615 -0.281 -1.986 -3.428
0.015 -0.026 -1.451 -0.428 1.596 1.546 0.394
3.36 4.767 4.56 2.988 0.211 -2.509 -2.908
-1.29 -0.953 -1.249 -1.998 -3.908 -3.131 0.142
4.671 4.834 4.727 4.699 2.93 0.644 -0.776
-2.223 -0.097 0.912 -1.308 -4.855 -3.859 -0.508
0.013 2.698 3.491 3.312 1.566 0.575 1.137
0.299 -2.998 -5.818
我用split和UBound只得出了列和行的个数,而我的这些数据最后一行的个数是变换的,比如我上面列出的例子,怎样才能读出总的个数,数据中间是空格,这些数据会有几千个。

解决方案 »

  1.   

    split(fileData," ")得到数组,再减去空元素的个数即可
      

  2.   

    数小数点的个数,呵呵
    split的时候以小数点为分隔符
      

  3.   

    function numcount(byval s as string) as long
      dim count as long
      dim ch as string
      dim isNum as boolean
      dim i as long
      for i=1 to len(s)
        ch = mid$(s,i,1)
        if instr(1, "0123456789.+-", ch) <> 0 then
          if not isNum then count = count+1
          isNum = true
        else
          isNum = false
        end if
      next
      numcount = count
    end function
      

  4.   

    第一次运行成功了,为什么后面我调用这个函数的时候总说我变量未定义
    我将上面的代码改成了如下代码,不知道有什么错误: 
    Function numcount(ByVal s As String) As Long
      Dim count As Long
      Dim ch As String
      Dim isNum As Boolean
      Dim i As Long
      Dim hFile As Integer  hFile = FreeFile
      Open App.Path & "\1.txt" For Input As #hFile
       Do Until EOF(hFile)
         Line Input #hFile, s
       For i = 1 To Len(s)
         ch = Mid$(s, i, 1)
         If InStr(1, "0123456789.+-", ch) <> 0 Then
           If Not isNum Then count = count + 1
           isNum = True
         Else
          isNum = False
        End If
      Next
      numcount = count
      Loop
      Close #hFile
      
    End Function
      

  5.   

    Dim tmp As String, txtData() As String, i As Integer
    Dim MaxValue As Single
    Dim a As Integer
     a = 0
    hFile = FreeFile
    Open App.Path & "\Wavex.dat" For Input As #hFile
    Do Until EOF(hFile)
        Line Input #hFile, tmp
        If Trim(tmp) <> "" Then
            tmp = Replace(tmp, vbTab, Space(1))
            Do While InStr(tmp, Space(2))
                tmp = Replace(tmp, Space(2), Space(1))
            Loop
           
            txtData = Split(tmp, Space(1))
            For i = 0 To UBound(txtData)
                If Abs(Val(txtData(i))) >= Abs(MaxValue) Then MaxValue = Val(txtData(i))
                a = a + 1
            Next i
        End If
    Loop
    Close #hFilemsgbox a  '得到点数
    我用这段代码执行,对于只有一列的数据是满足的,可对于多列却总是大于实际的点数,不知道是什么问题怎么修改?
      

  6.   

    Function GetCount(pFile As String) As Long    'pFile文本路径和名称 如:"C:\test.txt"
        
        Dim hFile  As Integer
        Dim sFile As String
        Dim arr() As String
        Dim i As Integer    hFile = FreeFile()
        Open pFile For Binary As hFile
            sFile = Space(LOF(hFile))
            Get hFile, , sFile
        Close hFile
        
        sFile = Replace(sFile, vbCrLf, Chr(32))
        sFile = Replace(sFile, Chr(9), Chr(32))  
        arr = Split(sFile, Chr(32))
        For i = 0 To UBound(arr)
            If Trim(arr(i)) <> "" Then GetCount = GetCount + 1
        Next
        
    End Function