PDA

View Full Version : Is textbox entry only 1 line?



clhare
12-11-2007, 04:13 AM
I have a userform with a textbox on it for the user to type in an address. The text box EnterKeyBehavior = True and MultiLine = True. Is there a way to determine if the address entered is only one line in length (vs. multiple lines)? If it is, I need to add additional spacing to the letter.

TonyJollans
12-11-2007, 07:16 AM
What about:

If Instr(TextBox,vbCr) = 0 Then
' Single Line
Else
' Multiple Lines
EndIf

clhare
12-11-2007, 08:47 AM
That sounds good! Thanks, I'll try that!

clhare
01-03-2008, 06:39 AM
Question...

Is there a way to find out how many returns are in the string?

fumei
01-03-2008, 09:45 AM
My mind is off in la-la land today...but perhaps:Dim counter As Long
Dim k As Long
Dim strIn As String
strIn = TextBox1.Text
If InStr(strIn, vbCr) > 0 Then
Do Until InStr(strIn, vbCr) = 0
counter = counter + 1
k = InStr(strIn, vbCr)
strIn = Right(strIn, Len(strIn) - k)
Loop
End If

The variable "counter" is the number of times the Enter key was pressed in Textbox1.

This is significant.

This (press Enter)
is (press Enter)
three

in the textbox would return 2

This (press Enter)
is (press Enter)
three (press Enter)

would return 3. Even though in the Textbox, the text would look the same.

There is likely a more simple, straightforward function to count a specific character in a string, but as I said...my mind is waaaaay off somewhere this morning.

TonyJollans
01-03-2008, 12:28 PM
With all Gerry's caveats ...

len(Textbox.Text) - len(replace(textbox.text,vbcr,""))

or ...

ubound(split(textbox.text,vbcr))

fumei
01-04-2008, 11:08 AM
<mumbles incoherently> be-bedee-be-deee </mumbles incoherently>