Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text box length wrong if text set at design time 2

Status
Not open for further replies.

SJA

Technical User
Nov 27, 2000
15
0
0
GB
I wonder if anyone can explain this:-

Create a form with a multi line text box and 2 buttons.

Put the following code under the buttons:-

Private Sub Cmd_Count_Click()
MsgBox Len(Text1.Text) & " characters.", vbOKOnly
End Sub

Private Sub Cmd_Fill_Click()
Dim X As Long
Dim sTemp As String

For X = 1 To 500
sTemp = sTemp & "A"
Next
Text1.Text = sTemp

End Sub

Run the program and click the fill button, then click the count
button, the message box tells us there are 500 characters in the
text box. No suprises there.

Now select and copy the text in the text box, stop the program
and paste the characters into the text property of the text box.
i.e. fill it at design time.

Run the program again but this time click the count button first.
I see 502 characters reported. I can't find the extra 2.

Any ideas ?
 

"Run the program again but this time click the count button first.
I see 502 characters reported. I can't find the extra 2."
Code:
Private Sub Cmd_Count_Click()[blue]
Dim c As Integer

For c = 1 To Len(Text1.Text)
    If Mid(Text1.Text, c, 1) <> "A" Then
        MsgBox Asc(Mid(Text1.Text, c, 1))
    End If
Next c[/blue]

MsgBox Len(Text1.Text) & " characters.", vbOKOnly

End Sub
You get 13 and 10: [tt]vbCrLf[/tt]

Have fun.

---- Andy
 
the extra characters are the chr(13) (carriage return) and chr(10) line feed at the end of the line.

At design time, when you are pasting your 500 characters, notice that the cursor will go to the next line (because there is a cr/lf present). click backspace to delete it, and re-run your program, and it should show 500 characters
 
Thank you for your prompt replies. I should have seen this
because the project I'm working on transmits these characters
out via USB and I can see the 0x0A and 0x0D appear in the
receive buffer of the device.
Problem solved :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top