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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How in listbox can I force to start the text at the next line: VBCRLF

Status
Not open for further replies.

nerdalert1

Programmer
Nov 4, 2004
92
US
Hello all. I have a listbox. On Enter I want to be able to start the cursor at the first position of a new line after the last character of text. I am trying to use vbCrlf but when I do this the text is taking into consideration the vbcrlf each time. So what happens is each time I keep starting a blank line down which I dont want. Its like I want to keep the cariage returns for each line but anything from the last character down I want to start in the next exact line. Hope this makes sense. Thanks all
 
It may just be me be, but I can't seem to grasp what you are trying to do. Could you explain a bite more clearly and perhaps post some of the code you are trying.

Thanks

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Hi,

Listbox???

What you could do is PAD each line with SPACES, the number of which equals the number of characters in the previous line.

ALSO, change the FONT to Courier, the only fixed pitch font commonly available -- all other are variable pitch, wich will not work properly.

Skip,
[sub]
[glasses] [red]Be advised:[/red] Researchers have found another Descartes trueism, "Cogito ergo spud."
"I think; therefore, I YAM!
[tongue][/sub]
 
Ok I have 5 listboxes placed beside each other. The user enters data across the boxes like a date, next box a number, next box an amount etc. When they finish the last listbox and tab the first line is then highlighted and they have to click into the list box to get to the next line. They want when they tab to just go directly to the start of the next line to type then when they tab same deal go to the next line and not highlight the text in it. So I was thinking that if I could force a carriage return after the last "character" on the enter of the box I would bring the user to where they can just start typing. However, the first time I use this "TextBox1.Text = TextBox1.Text & vbcrlf". Works great. But if they dont have anything to type in that column and they missed something etc. Too many Carriage returns are being added and its skipping to 2 lines down etc. So I tried using ON ENTER using:

TextBox13.Text = Replace(Trim(TextBox13.Text), vbCrLf, "")
If TextBox13.Text <> "" Then
TextBox13.Text = TextBox13.Text & vbCrLf
DoEvents
End If

Problem with that is I dont want to replace the carriage returns between text, so this wont work. I want to keep the carriage returns between text, but I want to delete any carriage returns that are preceding the character text and then vbcrlf. Hope this makes more sense.

For example:
10/2/2004 2 30.00
11/3/2004 3 10.00
 
> Ok I have 5 listboxes placed beside each other

Do you actually mean listboxes? Your code is referring to a TextBox.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 


Don't you mean Textbox rather then ListBox???

Skip,
[sub]
[glasses] [red]Be advised:[/red] Researchers have found another Descartes trueism, "Cogito ergo spud."
"I think; therefore, I YAM!
[tongue][/sub]
 
SORRY. Yes I mean textboxes not listboxes. My bad. 5 MultiLine TextBoxes I have
 
How about someting along these lines...

TextBox1.SelStart = 65535
TextBox1.SelText = vbCrLf

Harleyquinn
 
OK - just before we go any further with this - is this related to the program that you were asking questions on yesterday (thread222-948635) as it came up that it wasnt actually a VB5/6 program - it was a VBA program from Microsoft Word.

If this is the case then you may find that you get better answers by asking the question in the VBA forum (as suggested by Harlequin in the previous post)

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
What about just

TextBox13.Text = Replace(Trim(TextBox13.Text), vbCrLf& vbCRLF, vbCRLF)

This would do away with the string of vbCRLF's you will get if no data is entered.
 
Opps sorry - error in typing. If you use Trim$ I believe that the vbCRLF at the end of the line will be dropped so your

textbox13.text = Replace(trim(textBox13.Text),vbCRLF,"") would with trim drop the vbCRLF at the end of the line and the Replace would replace all of the other vbCRLF's in the textbox
So if in the text box you had

Cat
Dog
Bird

TextBox13.Text = "Cat" & vbCRLF & "Dog" & vbCRLF & "Bird" & vbCRLF

Your code would convert this to
TextBox13.Text = "Cat & "" & "Dog" & "" & "Bird" & ""

and the TextBox13.Text would look like Cat Dog Bird

What you want to prevent is a double vbCRLF at the end and

Textbox13.Text = Replace(TextBox13.Text,vbCRLF & vbCRLF, vbCRLF)

should do that and leave all the other vbCRLF alone.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top