|
-
Mar 6th, 2007, 07:04 PM
#1
Thread Starter
Junior Member
Multiline text boxes
I have a mutiline text box on a form. I intend to use this box to display information as i loop through a dataset (so each new record will add new info to the text box)
Thing is at certain points i want to have the text box move onto a new line. However i have no idea how i get VB to do this. I tried looking up anything i could about carridge returns and that in VB but found nothing of any help.
Cna anybody tell me what code i would use to take a text box, and add new information onto a new line in that text box?
Any help appreciated, thanks in advance.
-
Mar 6th, 2007, 07:07 PM
#2
Re: Multiline text boxes
There are two options:
vbCrLf
vbNewLine
Both work, but without seeing the code you have, I can't tell you why they didn't work for you.
Post what you have.
-
Mar 6th, 2007, 07:19 PM
#3
Thread Starter
Junior Member
Re: Multiline text boxes
Ok well the code im testing it with at the moment is nothing complex.
Private Sub Form_Load()
Text1.Text = "line1" + vbcr + "line 2" + vbcr + "line 3"
End Sub
The code for the project will be exactly the same in terms of the text box only the line1 line2 and line 3 will be replaced with variables (totals made from looping the dataset)
-
Mar 6th, 2007, 07:41 PM
#4
Re: Multiline text boxes
Two things: first make sure that the MultiLine property of your textbox is set to True, and second, you should use & rather than + when concatenating strings.
-
Mar 6th, 2007, 07:50 PM
#5
Thread Starter
Junior Member
Re: Multiline text boxes
Ahhh ok vbNewLine seems to work. i hadnt found that before only vbcr and vbclf.
And thanks for the tip on the + and the & might i ask though why & is better?
-
Mar 6th, 2007, 08:13 PM
#6
Re: Multiline text boxes
+ is overloaded and the operation (addition or concatenation) depends on the data types of the operands. If you intend to do concatenation, then by using & there is no ambiguity.
vbCr wouldn't give you a new line, just resets cursor to start of line (Carriage Return). What you needed was Line Feed with vbLf. vbCrLf is a combination since usually for a new line of text you also need carriage return after doing a line feed (like what you did with typewriters in days gone by). vbNewline works similarly to vbCrLf, but I forgot the details regarding their differences if there are any.
-
Mar 7th, 2007, 08:17 AM
#7
Re: Multiline text boxes
 Originally Posted by flamereaper
And thanks for the tip on the + and the & might i ask though why & is better?
Fundamentally VB, and most programming languages, treat + as the sign for addition as opposed to concantenation.
It can, and often does, work but that is not what it was designed to do and therefore, could cause problems that would be a complete bugger to figure out.
Use + when you want to add some numbers and & when you want to contanate strings.
-
Mar 7th, 2007, 01:19 PM
#8
Re: Multiline text boxes
 Originally Posted by leinad31
vbNewline works similarly to vbCrLf, but I forgot the details regarding their differences if there are any.
vbCrLf is always CR+LF whereas vbNewLine is platform specific. Whilst that might not mean anything in terms of VB6, the vbNewLine constant is part of the VBA library, so in Word for Mac, for example, it may not represent both CR and LF.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|