Computer Science Canada

A mistake in 3 simple lines!

Author:  HazySmoke)345 [ Fri Mar 10, 2006 7:43 pm ]
Post subject:  A mistake in 3 simple lines!

Here goes. For this project, you need a textbox called Text1 (Multiline=True), and button called Command1. Under the button, write the following lines:
VisualBASIC:
Private Sub Command1_Click()
    MsgBox Len(Text1.Text)
End Sub


Now run the program. In the textbox, type in the following text:
code:
123
456
789


From my understanding, Len(Text1.Text) should be 11 because there are 9 digits and 2 returns, but when I press the button, it gave me 13. Any explainations for that?

Author:  pavol [ Fri Mar 10, 2006 8:32 pm ]
Post subject: 

just a thought, but maybe a space counts as one character and enter counts as two, in which case 13 would make sense

Author:  GlobeTrotter [ Fri Mar 10, 2006 10:34 pm ]
Post subject: 

Yeah, I suspect it is because each new line represents two characters. For example, if you'll notice, the vbNewLine character is actually made of two characters. Thus, 9 letters plus 2*2 vbNewLine = 13

Author:  wtd [ Sat Mar 11, 2006 4:59 am ]
Post subject: 

Welcome to the wonderful world of Windows. A newline is actually both a carriage return and a linefeed.


: