PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Separating the lines in a multiline textbox-VBForums
Results 1 to 8 of 8

Thread: Separating the lines in a multiline textbox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    Separating the lines in a multiline textbox

    My textbox contains 4 lines. What I want to do is separate these lines into strings i.e.
    str1 = Line1
    str2 = Line2
    etc.

    Simple enough I know
    Mel

  2. #2
    Banned plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    This will produce an array of lines for you called strArr()

    VB Code:
    1. Dim strArr() As String
    2. strArr = Split(Text1.Text, vbCrLf)

  3. #3
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    If your textbox Multiline property is set to True and Text1.Text doesn't have an explicit entry such vbNewLine/vbCrLf or similar then strArr = Split(Text1.Text, vbCrLf) will result only 1(one) entry in your array: Text1.Text as a single string value.
    Roy

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Thanks, but how do I find out how many elements are in strArr after I've done the split?
    Mel

  5. #5
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    If you know how many characters are in each line then how about...
    VB Code:
    1. Dim strText as String
    2. Dim strArr() as String
    3. Dim i,j as Integer
    4.  
    5. ''j is the number of characters per line
    6. j = 5
    7.  
    8. strText = Text1.Text
    9.  
    10. While strText <> ""
    11.    Redim Preserver strArr(i)
    12.    strArr(i) = Mid$(1, strText, j)
    13.    strText = Mid$(j + 1, strText, Len(strText) - j)
    14.    i = i + 1
    15. Wend
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  6. #6
    Frenzied Member seoptimizer2001's Avatar
    Join Date
    Apr 2001
    Location
    Toledo, Ohio USA GMT -5
    Posts
    1,075
    Originally posted by mel_flynn
    Thanks, but how do I find out how many elements are in strArr after I've done the split?
    Use the UBound function...
    VB Code:
    1. Dim elements as Integer
    2.  
    3. elements = UBound(strArr)
    4.  
    5. 'a looping example
    6. For i = LBound(strArr) to UBound(strArr)
    7.  
    8. ''do something
    9. Next
    seoptimizer2001
    VB 6.0, VC++, VI, ASP, JavaScript, HTML,
    Perl, XML, SQL Server 2000

    If God had intended us to drink beer, He would have given us stomachs.


    Please use the [code] and [vbcode] tags in your posts!
    If you don't know how to use them please go HERE!


  7. #7
    Banned plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Originally posted by mel_flynn
    Thanks, but how do I find out how many elements are in strArr after I've done the split?
    As seoptimizer2001 said, you would use the UBound() function on the strArr array :

    VB Code:
    1. UBound(strArr) '' zero based count of elements

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Cheers
    Mel

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width