|
-
Jun 15th, 2001, 08:26 AM
#1
text box question
I have a multi-line text box that is updated automatically. Sometimes it could have 5 lines - sometimes 20 lines.
I have found code somewhere to count the lines in the box however I need to do something with each line.
I want to setup a loop to grab each line and do something.
Any ideas?
Thanks,
pp
-
Jun 15th, 2001, 08:32 AM
#2
Registered User
Try using split(text1,vbcrlf)
Then loop through each element iof the array. Just an idea.
-
Jun 15th, 2001, 03:55 PM
#3
is split a vb6 feature? It doesn't work on vb5. Any ideas?
pp
-
Jun 15th, 2001, 05:24 PM
#4
Hyperactive Member
I don't think the "split" function is new just to VB6... I think you can use it in VB5 too but I have no way to test to be sure. Did you make sure you replaced "text1" with your textbox's name? Later,
-zer0 flaw
-
Jun 15th, 2001, 05:31 PM
#5
Here is Microsoft's Split function (which they rewrote for VB5 and 4)
VB Code:
Public Function Split(ByVal sIn As String, Optional sDelim As _
String, Optional nLimit As Long = -1, Optional bCompare As _
VbCompareMethod = vbBinaryCompare) As Variant
Dim sRead As String, sOut() As String, nC As Integer
If sDelim = "" Then
Split = sIn
End If
sRead = ReadUntil(sIn, sDelim, bCompare)
Do
ReDim Preserve sOut(nC)
sOut(nC) = sRead
nC = nC + 1
If nLimit <> -1 And nC >= nLimit Then Exit Do
sRead = ReadUntil(sIn, sDelim)
Loop While sRead <> ""
ReDim Preserve sOut(nC)
sOut(nC) = sIn
Split = sOut
End Function
Public Function ReadUntil(ByRef sIn As String, _
sDelim As String, Optional bCompare As VbCompareMethod _
= vbBinaryCompare) As String
Dim nPos As String
nPos = InStr(1, sIn, sDelim, bCompare)
If nPos > 0 Then
ReadUntil = Left(sIn, nPos - 1)
sIn = Mid(sIn, nPos + Len(sDelim))
End If
End Function
-
Jun 15th, 2001, 06:10 PM
#6
thank you very much - that should work.
However, I'm trying to grab each line in a variable and processing it but I get an Type Mismatch error on the debug line.
oneline = Split(txtCellContents, vbCrLf)
Debug.Print oneline
Now what?
pp
-
Jun 15th, 2001, 06:37 PM
#7
_______
<?>
'VB5 Split Function
'split function for VB5 and under vb6 has the function
'posted originally by Aaron Young
Public Function Split2(ByVal sString As String, ByVal sSeparator As String) As Variant
Dim sParts() As String
Dim lParts As Long
Dim lPos As Long
lPos = InStr(sString, sSeparator)
While lPos
ReDim Preserve sParts(lParts)
sParts(lParts) = Left(sString, lPos - 1)
sString = Mid(sString, lPos + Len(sSeparator))
lPos = InStr(sString, sSeparator)
lParts = lParts + 1
Wend
If Len(sString) Then
ReDim Preserve sParts(lParts)
sParts(lParts) = sString
End If
Split2 = IIf(lParts, sParts, Array())
End Function
'Example:
'the individual lines go into an array
'so you can access them as you would any array
'for i = 0 to ubound(vLines)
' printer.print vlines(i)
'next i
'
'or whatever
Private Sub Form_Load()
Dim vLines As Variant 'this will be your array
Dim lLine As Long
'put some useless text in the textbox
Text1 = "wayne Is here"
Text1 = Text1 & vbCrLf & "the ice man cometh"
Text1 = Text1 & vbCrLf & "help me out will you"
vLines = Split2(Text1.Text, vbCrLf)
For lLine = 0 To UBound(vLines)
Debug.Print vLines(lLine)
Next
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Jun 15th, 2001, 10:47 PM
#8
Member
Yeah it's me.
Here's how I would do it.
So you have the split function working and you're pumped up to kick some app as$.
Code:
dim oneline() as string
oneline = split(strString, vbcrlf)
dim i as integer
dim x as integer
i = ubound(oneline)
if i > 20 then
for x = (i -20) to ubound(oneline)
'do what you have to do here
lstBox.additem oneline(x)
next x
end if
Last edited by Cabral; Jun 15th, 2001 at 10:51 PM.
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
|