我先将文本框设置为多行文本,那末请问如何获得每一行文本的内容?(如方便请付代码)

解决方案 »

  1.   

    1.利用Split函数
    Dim TempStrs() as String
    TempStrs=Split(Text1.Text,vbCrLf)
    第n行=TempStrs(n)2.发送EM_GETLINE消息
    EM_GETLINE
    An application sends an EM_GETLINE message to copy a line of text from an edit control and place it in a specified buffer. EM_GETLINE 
    wParam = (WPARAM) line;          // line number to retrieve 
    lParam = (LPARAM) (LPCSTR) lpch; // address of buffer for line 
     
    Parameters
    line 
    Value of wParam. Specifies the zero-based index of the line to retrieve from a multiline edit control. A value of zero specifies the topmost line. This parameter is ignored by a single-line edit control. 
    lpch 
    Value of lParam. Pointer to the buffer that receives a copy of the line. The first word of the buffer specifies the maximum number of characters that can be copied to the buffer. 
    Return Values
    The return value is the number of characters copied. The return value is zero if the line number specified by the line parameter is greater than the number of lines in the edit control. Res
    The copied line does not contain a terminating null character. QuickInfo
      Windows NT: Requires version 3.1 or later.
      Windows: Requires Windows 95 or later.
      Windows CE: Requires version 1.0 or later.
      Header: Declared in winuser.h.
      

  2.   


    Split函数
          描述返回一个下标从零开始的一维数组,它包含指定数目的子字符串。语法Split(expression[, delimiter[, count[, compare]]])Split函数语法有如下几部分:部分 描述 
    expression 必需的。包含子字符串和分隔符的字符串表达式 。如果expression是一个长度为零的字符串(""),Split则返回一个空数组,即没有元素和数据的数组。 
    delimiter 可选的。用于标识子字符串边界的字符串字符。如果忽略,则使用空格字符(" ")作为分隔符。如果delimiter是一个长度为零的字符串,则返回的数组仅包含一个元素,即完整的 expression字符串。 
    count 可选的。要返回的子字符串数,–1表示返回所有的子字符串。 
    compare 可选的。数字值,表示判别子字符串时使用的比较方式。关于其值,请参阅“设置值”部分。 
    设置值compare参数的设置值如下:常数 值 描述 
    vbUseCompareOption –1 用Option Compare语句中的设置值执行比较。 
    vbBinaryCompare 0 执行二进制比较。 
    vbTextCompare 1 执行文字比较。 
    vbDatabaseCompare 2 仅用于Microsoft Access。基于您的数据库的信息执行比较。 
      

  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
     Const EM_GETLINE = &HC4Private Sub Command1_Click()
        Dim str(256) As Byte
        str(1) = 1 '最大允许存放256个字符
        '获取总行数,结果显示在文本框txtLineCount中
        txtlineCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
        '获取第3行的数据放在str中,转换为字符串后显示在文本框Text2中
        SendMessage Text1.hwnd, EM_GETLINE, 2, str(0)
        Text2.Text = StrConv(str, vbUnicode)
       ' Debug.Print txtstring
        
    End Sub
      

  4.   

    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
     Const EM_GETLINE = &HC4Private Sub Command1_Click()
        Dim str(256) As Byte
        str(1) = 1 '最大允许存放256个字符
        '获取总行数
        txtlineCount = SendMessage(Text1.hwnd, EM_GETLINECOUNT, 0, 0)
        '获取第3行的数据放在str中,转换为字符串后显示在文本框Text2中
        SendMessage Text1.hwnd, EM_GETLINE, 2, str(0)
        Text2.Text = StrConv(str, vbUnicode)
        
    End Sub
      

  5.   

    既然每行长度固定,那么每次可以选一行
     selstart
     sellength
     setfocus
      

  6.   


    利用粘贴,剪切,复制原理
     selstart
     sellength
     setfocus
    你试一试。