看这段代码
   Dim str As String
   Dim arrStr() As String
   Dim iLine As Integer
   
   str = Text1.Text
   str = Mid(str, 1, Text1.SelStart + Text1.SelLength)
   If str <> "" Then
      arrStr = Split(str, Chr(13) & Chr(10))
      iLine = UBound(arrStr) + 1
   Else
      iLine = 1
   End If
   MsgBox ("&micro;±&Ccedil;°&Ocirc;&Uacute;&micro;&Uacute;" & iLine & "&ETH;&ETH;")

解决方案 »

  1.   

    api函数可以实现该功能,具体函数忘了,参考王国容的关于VB-API函数的书.
      

  2.   

    Split是VB标准函数啊,不用自己写
      

  3.   

    '在 Form 中放入一个 TextBox 并将 Multiline 属性设为 True,放入一个 Label 用来显示目前光标所在的行数,在表单声明区中加入以下声明及模组:Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, _
    ByVal wMsg As Long, _
    ByVal wParam As Long, _
    ByVal lParam As Long) As LongConst EM_LINEFROMCHAR = &HC9Function LineNo(txthwnd As Long) As Long
    On Local Error Resume Next
    LineNo = SendMessageLong(txthwnd, EM_LINEFROMCHAR, -1&, 0&) + 1
    LineNo = Format$(LineNo, "##,###")
    End Function'呼叫这个模组时要导入的是 TextBox 的 hwnd
    '实际使用时,必须在 TextBox 的以下几个事件中呼叫这个模组,才会完全正确:
    '1. Change事件:输入资料时可侦测计算
    '2. Click 事件:用鼠标移动光标时可侦测计算
    '3. KeyUp 事件:用上下左右键移动光标时可侦测计算Sub Text1_Change()
    Label1 = LineNo(Text1.hwnd)
    End SubPrivate Sub Text1_Click()
    Label1 = LineNo(Text1.hwnd)
    End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
    Label1 = LineNo(Text1.hwnd)
    End Sub
      

  4.   

    Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageW" _
            (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
            lParam As Any) As Long
    Private Declare Function SendMessageByRef Lib "user32" Alias "SendMessageA" _
            (ByVal hwnd As Long, ByVal wMsg As Long, wParam As Long, _
            lParam As Long) As Long
            
    Const EM_LINEFROMCHAR = &HC9
    Const EM_LINEINDEX = &HBB
    Const EM_GETLINE = &HC4
    Const EM_GETSEL = &HB0Dim iLineX, iLineY As LongSub GetCurPos(txtA As TextBox)
        Dim l, l1, l2 As Long
        Dim astr As String * 256
        
        l = SendMessage(txtA.hwnd, EM_LINEINDEX, -1, 0)
        iLineY = SendMessage(txtA.hwnd, EM_LINEFROMCHAR, l, 0)
        
        SendMessageByRef txtA.hwnd, EM_GETSEL, l1, l2
        iLineX = l1 - l
        Label1.Caption = "列:" + Str(iLineX)
        Label2.Caption = "行:" + Str(iLineY)
    End SubPrivate Sub Form_Load()
        Dim iFile
        Dim astr As String
        
        Label1.Height = 300: Label2.Height = 300
        Text1.Left = 0: Text1.Top = 0
        Text1.Text = ""
        Label1.Caption = ""
        Label2.Caption = ""
        
        iFile = FreeFile
        Open "C:\windows\readme.txt" For Input As #iFile
        Do
            Line Input #iFile, astr
            Text1.Text = Text1.Text + astr + vbCrLf
        Loop Until EOF(iFile)
        Close iFile
    End SubPrivate Sub Form_Resize()
        Label1.Top = Me.ScaleHeight - 300
        Label2.Top = Me.ScaleHeight - 300    Label1.Left = 0: Label2.Left = 1200
        Label1.Width = 1200
        Label2.Width = 1200
        
        Text1.Width = Me.ScaleWidth
        Text1.Height = Me.ScaleHeight - Label1.Height
    End SubPrivate Sub Text1_Click()
        GetCurPos Text1
    End SubPrivate Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
        GetCurPos Text1
    End Sub
        
      

  5.   

    谢谢大家我已知道了:
    SendMessage(Text1.hwnd, EM_LINEFROMCHAR, -1, 0) + 1