Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Convert a MultiLine textbox Into strings for each line
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GlobeTrotter




PostPosted: Sat Apr 30, 2005 7:35 pm   Post subject: Convert a MultiLine textbox Into strings for each line

I want to be able to have the user enter some data into a multiline textbox, and then seperate each line into a string, stored in an array.
This is what I have so far, but it doesn't really work.
VisualBASIC:

    Dim iCount As Integer
    Dim TempStr() As String
    Dim TempMarker As Integer
    Dim TempCount As Integer
    TempMarker = 1
    For iCount = 1 To Len(txtInput.Text) - 1
        If InStr(Mid(txtInput.Text, iCount, 2), vbNewLine) Then
            TempCount = TempCount + 1
            ReDim TempStr(TempCount)
            TempStr(TempCount) = Mid(txtInput.Text, TempMarker, iCount - TempMarker)
            TempMarker = iCount
        End If
    Next iCount
Sponsor
Sponsor
Sponsor
sponsor
Brightguy




PostPosted: Mon May 02, 2005 8:08 pm   Post subject: Re: Convert a MultiLine textbox Into strings for each line

A couple little things:
-Use the Preserve keyword after ReDim to keep the data in the array when you resize it
-TempMarker represents the start of the next line, so it should be set to iCount + 2 (to skip the new line character)
-There isn't a new line character at the end of the text, so you'll have to add the last line into the array when the loop finishes
-You don't need to use the InStr function... simply check if Mid(txtInput.Text, iCount, 2) is the new line character
GlobeTrotter




PostPosted: Mon May 02, 2005 8:48 pm   Post subject: (No subject)

Thanks a lot, I got it working. i have a question about it though...
code:
If Mid(txtInput.Text, iCount, 2) = vbNewLine Then

How does that line work? It's checking if a string of length 2 is equal to vbNewLine, which I assume is one character. How does that work?
Brightguy




PostPosted: Thu May 05, 2005 9:22 am   Post subject: Re: Convert a MultiLine textbox Into strings for each line

I normally use vbCrLf for new lines, which is two characters: carriage return + linefeed.

I thought vbNewLine was the same as vbCrLf, although after checking the VB help files, apparently vbNewLine is a platform-specific new line character, and sometimes doesn't include the linefeed character.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: