|
-
Nov 6th, 2002, 10:03 AM
#1
Thread Starter
Frenzied Member
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
-
Nov 6th, 2002, 10:04 AM
#2
Retired VBF Adm1nistrator
This will produce an array of lines for you called strArr()
VB Code:
Dim strArr() As String
strArr = Split(Text1.Text, vbCrLf)
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 6th, 2002, 10:10 AM
#3
PowerPoster
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.
-
Nov 6th, 2002, 10:17 AM
#4
Thread Starter
Frenzied Member
Thanks, but how do I find out how many elements are in strArr after I've done the split?
-
Nov 6th, 2002, 10:17 AM
#5
Frenzied Member
If you know how many characters are in each line then how about...
VB Code:
Dim strText as String
Dim strArr() as String
Dim i,j as Integer
''j is the number of characters per line
j = 5
strText = Text1.Text
While strText <> ""
Redim Preserver strArr(i)
strArr(i) = Mid$(1, strText, j)
strText = Mid$(j + 1, strText, Len(strText) - j)
i = i + 1
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!

-
Nov 6th, 2002, 10:19 AM
#6
Frenzied Member
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:
Dim elements as Integer
elements = UBound(strArr)
'a looping example
For i = LBound(strArr) to UBound(strArr)
''do something
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!

-
Nov 6th, 2002, 10:23 AM
#7
Retired VBF Adm1nistrator
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:
UBound(strArr) '' zero based count of elements
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
-
Nov 6th, 2002, 11:29 AM
#8
Thread Starter
Frenzied Member
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|