count, vbLf, string

exaccess

Registered User.
Local time
Today, 02:24
Joined
Apr 21, 2013
Messages
287
Hello Experts,
I have to count the number of occurrences of Line feed (vbLf) in a long string.
The code I am using is:
Code:
[CODE]MAX = TLine.Split(vbLf).Length - 1
[/CODE]
It does not work. Help please.
 
Google yields 2.150.000.000 hits on "it does not work". Which one applies to your case?
 
Rejected use of text as an expression.
 
Hello Experts,
I have to count the number of occurrences of Line feed (vbLf) in a long string.
The code I am using is:
Code:
[CODE]MAX = TLine.Split(vbLf).Length - 1
[/CODE]
It does not work. Help please.

This is string.split method coding from VB Net. It won't work in VBA (never did for me, at any rate). You need to split TLine into a variable defined as Variant and then seek the upper limit of the array as the number of line feeds that occur, eg.::

Code:
Dim MAX as Integer, txt as Variant, TLine as String
TLine = "This is" & vbLf & "a sample of" & vbLf & "a hen crossing " & vbLf & "the street"
txt = Split(TLine, Chr(10))
MAX = UBound(txt)

Best,
Jiri
 
SOLVED

This is string.split method coding from VB Net. It won't work in VBA (never did for me, at any rate). You need to split TLine into a variable defined as Variant and then seek the upper limit of the array as the number of line feeds that occur, eg.::

Code:
Dim MAX as Integer, txt as Variant, TLine as String
TLine = "This is" & vbLf & "a sample of" & vbLf & "a hen crossing " & vbLf & "the street"
txt = Split(TLine, Chr(10))
MAX = UBound(txt)

Best,
Jiri
Thanks a lot for the help. Sorry I could not get back sooner. I have solved the problem in a similar way by storing the result of the split function in an array.
 
SOLVED


Thanks a lot for the help. Sorry I could not get back sooner. I have solved the problem in a similar way by storing the result of the split function in an array.

You are welcome, and no problem !

Best,
Jiri
 

Users who are viewing this thread

Back
Top Bottom