-------------------------------------------------------------
To use this example, copy this sample code to the Declarations portion of a
form. Make sure that the form contains the following controls:
A TextBox named TextBox1.
A CommandButton named CommandButton1.
Two Label controls named Label1 and Label2.
'Type SHIFT+ENTER to start a new line in the text box.
Private Sub CommandButton1_Click()
'Must first give TextBox1 the focus to get line count
TextBox1.SetFocus
Label1.Caption = "LineCount = " & TextBox1.LineCount
Label2.Caption = "TextLength = " & TextBox1.TextLength
End Sub
Private Sub UserForm_Initialize()
CommandButton1.WordWrap = True
CommandButton1.AutoSize = True
CommandButton1.Caption = "Get Counts"
Label1.Caption = "LineCount = "
Label2.Caption = "TextLength = "
TextBox1.MultiLine = True
TextBox1.WordWrap = True
TextBox1.Text = "Enter your text here."
End Sub
----------------------------------------------
Thank you for your time,
Scott Laughton.
Private Sub Form_Initialize()
CommandButton1.Caption = "Get Counts"
Label1.Caption = "LineCount = "
Label2.Caption = "TextLength = "
TextBox1.Text = "Enter your text here."
End Sub
"Scott Laughon" <sco...@sympac.com.au> wrote in message
news:99sj88$hv0$1...@perki.connect.com.au...
It's *extremely* cludgy, but you might be able to
work something using SendKeys.
(On the fly...)
Text1.SetFocus
SendKeys "^{HOME}", 1 ' Start of text
Do While Text1.SelStart < Len( Text1.Text)
' Select current line
SendKeys "+{END}", 1
sLine = .SelText
' Get to start of next line
SendKeys "{HOME}", 1
SendKeys "{DOWN}", 1
Loop
You'll probably have to experiment with the loop
condition ...
HTH,
Phill W.
....
....
Label1.Caption = "LineCount = " & CStr(1 + UBound(lines))
Label2.Caption = "TextLength = " & CStr(Len(TextBox1.Text))
....
....
Rick
"wmf" <nospam-at-nospam.com> wrote in message
news:#wRgZT4tAHA.2248@tkmsftngp05...
Dim sLines() As String
sLines = Split(Text1.Text, vbCrLf)
However, in a multiline TextBox, when there is a wordwrap at the edge of the
box, there is no carriage return unless the user hit enter. That's a little
more complicated.
"Scott Laughon" <sco...@sympac.com.au> wrote in message
news:99sj88$hv0$1...@perki.connect.com.au...
Function CountStrings(longstring As String)
Dim position, count
Dim aryStrings(0 To 20) As String
position = 1
startpos = 1
Do While InStr(position, longstring, Chr(13))
position = InStr(position, longstring, Chr(13)) + 2
aryStrings(count) = Mid(longstring, startpos, position - startpos -
2)
count = count + 1
startpos = position
Loop
aryStrings(count) = Right(longstring, Len(longstring) - position +
1)
For idx = 0 To count
Debug.Print "'" & aryStrings(idx) & "'"
Next idx
End Function
"Scott Laughon" <sco...@sympac.com.au> wrote in message
news:99sj88$hv0$1...@perki.connect.com.au...
In Visual Basic, the code won't work for 2 reasons: 1. A textbox does not
have WordWrap, LineCount, and TextLength properties (that's the cause of the
compile error). For that matter, a command button does not have AutoSize
and WordWrap properties. 2. The MultiLine property is read-only at
runtime. This would have caused a runtime error were it not for the compile
error.
The following KB article should be of assistance:
HOWTO: Print Multiline Text Box Using Windows API Functions
Article ID: Q140886
http://support.microsoft.com/support/kb/articles/Q140/8/86.asp
Mike
"Scott Laughon" <sco...@sympac.com.au> wrote in message
news:99sj88$hv0$1...@perki.connect.com.au...
I have now got things happening!!!
Thank yuo all very much!!
Scott Laughton.
"Scott Laughon" <sco...@sympac.com.au> wrote in message
news:99sj88$hv0$1...@perki.connect.com.au...