+ Reply to Thread
Results 1 to 3 of 3

Reading Lines from a Textbox

Hybrid View

  1. #1
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Reading Lines from a Textbox

    Hi,

    I want to know how to read certain lines from a textbox in a form.

    What I need is the ability to read ONLY lines 5 - 10 of the textbox (I don't want the content of lines 1-4 or 11+).


    Any info on this would be GREATLY appreciated - Thanks!

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,480

    Re: Reading Lines from a Textbox

    This assumes your textbox has multiline set to TRUE

        Dim vntLines As Variant
        Dim lngLine As Long
        Dim strText As String
        
        If Len(TextBox1.Text) > 0 Then
            vntLines = Split(TextBox1.Text, vbCrLf)
            strText = ""
            For lngLine = 4 To 10
                If lngLine >= LBound(vntLines) And lngLine <= UBound(vntLines) Then
                    strText = strText & vntLines(lngLine) & vbLf
                End If
            Next
            MsgBox strText, vbInformation, "Lines 5 to 11"
        End If
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    06-01-2010
    Location
    Canada
    MS-Off Ver
    Excel 2003
    Posts
    47

    Re: Reading Lines from a Textbox

    Quote Originally Posted by Andy Pope View Post
    This assumes your textbox has multiline set to TRUE

        Dim vntLines As Variant
        Dim lngLine As Long
        Dim strText As String
        
        If Len(TextBox1.Text) > 0 Then
            vntLines = Split(TextBox1.Text, vbCrLf)
            strText = ""
            For lngLine = 4 To 10
                If lngLine >= LBound(vntLines) And lngLine <= UBound(vntLines) Then
                    strText = strText & vntLines(lngLine) & vbLf
                End If
            Next
            MsgBox strText, vbInformation, "Lines 5 to 11"
        End If
    This worked perfectly! Thanks a lot!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1