RT

解决方案 »

  1.   

    Private Function vSpace(Vstring As String) As String
    Do While InStr(Vstring, Chr(32)) <> 0
    Vstring = Replace(Vstring, Chr(32), "")
    Loop
    vSpace = VstringEnd Function
    Private Sub Command1_Click()
    Dim a As String
    a = Text1.Text
    xx = vSpace(a)
    If xx = "" Then
    MsgBox "文本共0行"
    Else
    yy = InStr(xx, Chr(10))
    Select Case yy
    Case 0
    MsgBox "文本共1行"
    Case Else
    j = 0
    zz = Split(xx, Chr(10))
    For i = 0 To UBound(zz)
    If zz(i) <> Chr(13) Then
    Debug.Print zz(i)
    j = j + 1
    End If
    Next
    MsgBox "文本共" & j & "行"
    End Select
    End If
    End Sub
      

  2.   

    如何计算TextBox中行数?
    你是指TextBox能显示的行数?还是TextBox全部文本的行数?还是光标所在的行数?
      

  3.   

    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 Const EM_GETLINECOUNT = &HBA
    Private Sub Command1_Click()LineCnt = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    MsgBox LineCnt
    End Sub
      

  4.   


    text1.text文件框中有这样的数据: 1 ,J1, 1.522 
     2 ,J2, 1.295, 0, 90.0712, 75.024, 180, 269.5248, 75.024
     3 ,H1, 1.295, 2.0206, 90.0241, 303.296, 182.0206, 269.5719, 303.296
     2 ,J1, 1.522 
     4 ,J2, 1.295, 0, 90.0712, 75.024, 180, 269.5248, 75.024
     5 ,H2, 1.295, 2.0853, 90.0256, 266.295, 182.0853, 269.5704, 266.295
     3 ,J1, 1.522 
     6 ,J2, 1.295, 0, 90.0712, 75.024, 180, 269.5248, 75.024
     7 ,H3, 1.295, 2.0043, 90.0205, 259.75, 182.0043, 269.5755, 259.75
     4 ,J1, 1.522 
     8 ,J2, 1.295, 0, 90.0712, 75.024, 180, 269.5248, 75.024
     9 ,H4, 1.295, 2.0702, 90.0313, 231.653, 182.0702, 269.5647, 231.653
     5 ,J1, 1.522 
     10 ,J2, 1.295, 0, 90.0712, 75.024, 180, 269.5248, 75.024我想计算短的数据有几行  和长的数据有行
      a=text1.text 
     if Len(A)>20 then j=j+1 '为长行  
     if Len(A)<20 then s=s+1 '为短行J 就TEXT 中一共有几行长的S 就是text 中一共有几行矩的
    在文件中我是这样写可以得到   在TEXT中就不道怎么写了  Private Sub Command1_Click()
    Dim arr() As String
    Dim strFile As String
     Open "c:\1.txt" For Input As #1
      Do
      Line Input #1, strFile
      If Len(strFile) > 20 Then
      i = i + 1
      Else
      s = s + 1
      End If
       Loop While Not EOF(1)
      Text1.Text = i & vbCrLf & s
    Close #1
    End Sub
      

  5.   

              Public Function GetFileLineCnt(fpn As String) As Integer
              Dim LineCnt As Long
              Open fpn For Input As #1
                  While Not EOF(1)
                        Line Input #1, Mystr
                        LineCnt = LineCnt + 1
                  Wend
              Close #1
              GetFileLineCnt = LineCnt
              End Function
                 
              Private Sub Form_Load()
              Me.AutoRedraw = True
              Print GetFileLineCnt("d:\a.txt")
              End Sub
      

  6.   

    我要的是在TEXT1.TEXT  文件框中的写法   ("d:\a.txt") 不用你写了  
      

  7.   

    '模块里
    Public Const EM_GETLINE = &HC4
        Public Const EM_LINELENGTH = &HC1
        Public Const EM_LINEINDEX = &HBB
       
        Private Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
     Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As LongPublic Const EM_GETLINECOUNT = &HBA
        Public Sub TB_GetLine(ByVal hwnd As Long, ByVal whichLine As Long, Line As String)
        Dim length As Long, bArr() As Byte, bArr2() As Byte, lc As Long
        lc = SendMessage(hwnd, EM_LINEINDEX, whichLine, ByVal 0&)
        length = SendMessage(hwnd, EM_LINELENGTH, lc, ByVal 0&)
        If length > 0 Then
        ReDim bArr(length + 1) As Byte, bArr2(length - 1) As Byte
        Call RtlMoveMemory(bArr(0), length, 2) '准备一个存储器,传递消息之前先在存储器的前两个字节填入存储器的长度。
        Call SendMessage(hwnd, EM_GETLINE, whichLine, bArr(0))
        Call RtlMoveMemory(bArr2(0), bArr(0), length)
        Line = StrConv(bArr2, vbUnicode)
        Else
        Line = ""
        End If
        End Sub
    窗体里
    Private Sub Command1_Click()
    Dim S As String
    LineCnt = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
    For i = 0 To LineCnt - 1
    Call TB_GetLine(Text1.hwnd, i, S)
    MsgBox S '长行还是短行你自己弄
    Next
    End Sub
      

  8.   

    就你的程序来改可以这样Private Sub Command1_Click()
       Dim arr() As String
       Dim strFile As String
       Dim X as Long, i As Long, s As Long
       arr = Split(Text2.Text, vbCrLf) '这里的 Text2 是指你所说的 TextBox
       For X = 0 To UBound(arr)
          strFile = arr(X)
          If Len(strFile) > 20 Then
             i = i + 1
          Else
             s = s + 1
          End If
       Next X
       Text1.Text = i & vbCrLf & s
    End Sub
      

  9.   

    这是个老问题了,在总行数、可见行、第一可见行,光标所在行等多种,用SendMessage基本可以搞定
      

  10.   


    你将text1.text另存为app.path & "\tmp.txt",不也一样嘛。
      

  11.   

    Private Sub Command1_Click()
       arr = Split(Text2.Text, vbCrLf)
       For X = 0 To UBound(arr)
          If Len(arr(X)) > 20 Then
             i = i + 1
          Else
             j = j + 1
          End If
          K = K + 1
       Next X
       Text1.Text = "总共" & k &“行,其中长"& i &"行,短"& j &"行"
    End Sub