Line Breaks In TextBox
Line Breaks In TextBox
Line Breaks In TextBox
Line Breaks In TextBox
Line Breaks In TextBox
Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox
Line Breaks In TextBox Line Breaks In TextBox
Line Breaks In TextBox
Go Back  Xtreme Visual Basic Talk > > > Line Breaks In TextBox


Reply
 
Thread Tools Display Modes
  #1  
Old 09-01-2010, 08:14 AM
vbnoober vbnoober is offline
Newcomer
 
Join Date: Sep 2010
Posts: 13
Default Line Breaks In TextBox


Hey Guys, iam new to visual basic, juz started learning it and i got some doubts ... i think they'll be cleared here

i am working on something and i got like 2 questions for ya, so here we go ...

No.1
-----
my interface is like this, i've put 4 text boxes above, followed by a Generate Button in the middle and a multiline text box below the Generate button (please see the attachment)

so all i want is when i click the Generate Button, i want the data entered inside the above 4 text boxes to display in the multiline text box at the bottom in 4 seperate lines and not in 1 row. Also i would like to have some line spaces.

this is the code i used

Code:
        ' This is used to display in Bold
        OutputTextBox.Text = "" & TextBox1.Text & ""
        ' This is used to display TextBox2.Text
        OutputTextBox.Text = TextBox2.Text
        ' This is used to display in Italic
        OutputTextBox.Text = "" & TextBox3.Text & ""
        ' This is used to display TextBox4.Text
        OutputTextBox.Text = TextBox4.Text
when i run this program, i am only able to see the data that i've entered inside the last text box that is in TextBox4



No.2
-----
Just wondering, is it possible to put some tabs above the big multiline text box at the bottom, say like 4 tabs and each tab consists of a big multiline text box inside it. And then when clicked the Generate Button which displays different data ...
Attached Images
File Type: jpg vb help.JPG (38.6 KB, 14 views)
Reply With Quote
  #2  
Old 09-01-2010, 12:04 PM
TRSDOSBasic79's Avatar
TRSDOSBasic79 TRSDOSBasic79 is offline
Contributor
 
Join Date: Oct 2003
Location: Pennsylvania
Posts: 422
Default

Your problem is that you are replacing the text in OutputTextBox each time instead of adding to the current text.
Try this ...

Code:
        ' This is used to display in Bold
        OutputTextBox.Text = OutputTextbox.text & "" & TextBox1.Text & "" & CrLf
        ' This is used to display TextBox2.Text
        OutputTextBox.Text = OutputTextBox.text & TextBox2.Text & CrLf
        ' This is used to display in Italic
        OutputTextBox.Text = OutputTextBox.text & "" & TextBox3.Text & "" & CrLf
        ' This is used to display TextBox4.Text
        OutputTextBox.Text = OutputTextBox.text & TextBox4.Text
The CrLf if a carriage return and line feed.

Last edited by Flyguy; 09-02-2010 at 01:57 AM. Reason: Removed quote
Reply With Quote
  #3  
Old 09-01-2010, 02:02 PM
Gruff's Avatar
GruffLine Breaks In TextBox Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

TrDos: I think you meant vbCrLf instead of CrLf

One could also just add them together in one go.
Code:
OutputTextBox.text = textbox1.text & vbcrlf & textbox2.text & vbcrlf & textbox3.text & vbcrlf & textbox4.text & vbcrlf
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #4  
Old 09-01-2010, 03:37 PM
TRSDOSBasic79's Avatar
TRSDOSBasic79 TRSDOSBasic79 is offline
Contributor
 
Join Date: Oct 2003
Location: Pennsylvania
Posts: 422
Default

Quote:
Originally Posted by Gruff View Post
TrDos: I think you meant vbCrLf instead of CrLf

One could also just add them together in one go.
Code:
OutputTextBox.text = textbox1.text & vbcrlf & textbox2.text & vbcrlf & textbox3.text & vbcrlf & textbox4.text & vbcrlf
I thought I typed that. Oooops. I was going to show that he could do it in one statement, but figured to hold to his design.
Reply With Quote
  #5  
Old 09-01-2010, 05:25 PM
Gruff's Avatar
GruffLine Breaks In TextBox Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Nothing wrong with your take on the problem. If I had a large control array of textboxes I would surely use the method you suggested in a loop, though I might use a lighter weight string variable to gather the sub strings as opposed to a heavier textbox control.
Code:
' Where txt is a control array of 0 to 25 perhaps Dim s as string Dim i as integer s = "" For i = 0 to 25 s = s & Txt(i).text & vbCrLf Next i OutputTextBox.text = s
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #6  
Old 09-02-2010, 07:02 AM
vbnoober vbnoober is offline
Newcomer
 
Join Date: Sep 2010
Posts: 13
Default

Thank you TRSDOSBasic79 and Gruff for the code ... it worked like a charm ... Juz curious about my 2nd question though i.e about Tabs, coz without it i'm havin a lot of text boxes which are looking like a clutter ... and also is it possible to directly post the data in a notepad rather than textbox ???
Reply With Quote
  #7  
Old 09-02-2010, 04:05 PM
Gruff's Avatar
GruffLine Breaks In TextBox Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

Didn't answer your 2nd question because I do not understand what you want.
What do you mean by Tabs? Do you mean the Microsoft Tabbed Dialog Control 6.0?

Why would you want to use NotePad? What does it support that you cannot get with a multiline textbox?
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #8  
Old 09-02-2010, 06:51 PM
TRSDOSBasic79's Avatar
TRSDOSBasic79 TRSDOSBasic79 is offline
Contributor
 
Join Date: Oct 2003
Location: Pennsylvania
Posts: 422
Default

I was kinda lost too on the second question. If you mean can you insert lines before you add the text from the other text boxes, just add a VbCrLf first and then add the textbox text. The only way I know of to use notepad is to send your data to a text file (Which you would need to create) and associate it with notepad. That's way more of a pain than just setting the multiline textbox to do what you need. Since you are just learning, notepad may seem simple but in the long run learning all that a textbox can do may save you a ton of unnecessary issues and long workarounds.
Reply With Quote
  #9  
Old 09-03-2010, 07:10 AM
vbnoober vbnoober is offline
Newcomer
 
Join Date: Sep 2010
Posts: 13
Default

Ok Guys ... i'll try to explain briefly about the tabs and notepad(text document)

First about the Tabs, i wanted the tabs bcoz i have so many text boxes in my software that i'm creating currently

To brief it up, there are 4 categories, for example let's say A,B,C & D and there are about 10 text boxes in each categoy, that makes about 40 text boxes on the whole. Instead of displaying all the 40 textboxes at once when i open my software, i want to display only category A and it's text boxes and there should be tabs for B,C & D.

Now when I click the "B" tab, i want to see only the text boxes of B and same goes for the C & D.

To make you more clear, plz open Firefox Browser and open 4 tabs, let's assume them as A,B,C & D, i hope now you got it guys, all i wanna do is switch between the tabs to access my data

i've also thought about .visible extension but that's not what i want.

And now about the "Notepad" or "Text Document" ......

TRSDOSBasic79 said "The only way I know of to use notepad is to send your data to a text file (Which you would need to create)"... and that's exactly what i want bro

First i am entering some text and then click the Generate Button to modify that text. At this point, i am manually copying all the modified text to a "text document" or "notepad".

Can it be done automatically, coz it will save a lot of time for me

I hope i made it very clear guys, if not then plz lemme know and i'll try to explain again
Reply With Quote
  #10  
Old 09-03-2010, 07:24 AM
TRSDOSBasic79's Avatar
TRSDOSBasic79 TRSDOSBasic79 is offline
Contributor
 
Join Date: Oct 2003
Location: Pennsylvania
Posts: 422
Default

I'm pretty sure there is an actual tab control for vb6, but I've never tried it. My suggestion would be to use frames. Set 4 frames named frame1 thru 4 and assign the textboxes per frame/group as you wish. Set 4 command buttons and on the click event have each button open the frame you want. That is your tabbed setup without using a tab control. I'm sure gruff can explain the tab control far better than I could.

As far as sending your text to a text file, it isn't hard. Once you have the text combined as you want, create a text file using the vb file controls (plenty info on the forum here and on google on how to do this). Remember to give the file a ".txt" extension and then write your text from the textbox you choose and close the file. Then just open it in notepad. As far as opening notepad directly from VB apps and writing info directly to it, I'm not 100% on that so I won't advise on it.

Heres one link at vbforums on the subject...
http://www.vbforums.com/showthread.php?t=342619

Last edited by TRSDOSBasic79; 09-03-2010 at 07:32 AM.
Reply With Quote
  #11  
Old 09-03-2010, 10:17 AM
dilettante's Avatar
dilettanteLine Breaks In TextBox dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,520
Default

Instead of using Frames for making tabbed dialogs it is often cleaner and much easier to support if you create a UserControl to represent the body for each "tab" in the dialog.

You can see what you're doing while laying things out, and you can keep local events (validation, etc.) local. Tidier in both Code and Object views.


To populate a multiline TextBox I wouldn't do a bunch of concatenation operations. Instead I prefer to set .Text = "", then set .SelStart = 0, and then add bits and pieces by setting .SelText = {chunk} & vbNewLine for each line.

Don't use vbCrLf for this. If you want a new line use vbNewLine, that's why it's there.

It can look cleaner if you set the TextBox.Visible = False at the beginning, set .SelStart = 0 again after appending, and then set .Visible = True at the end.
Code:
Option Explicit

'Text1 is a multiline TextBox.

Private Sub Text1_Click()
    Dim I As Integer
    
    Randomize
    With Text1
        .Visible = False
        .Text = ""
        .SelStart = 0
        For I = 1 To 15000
            .SelText = "abcdefghijklmnop " & CStr(Rnd()) & vbNewLine
        Next
        .SelStart = 0
        .Visible = True
    End With
End Sub
Reply With Quote
  #12  
Old 09-03-2010, 11:24 AM
Gruff's Avatar
GruffLine Breaks In TextBox Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

the MS Tabbed Dialog Control is easy to use and easy to set up at design time.
From the main menu select 'Projects | Components' and from the Components dialog select 'Microsoft Tabbed Dialog Control 6.0' from the list. Click OK. The new control will be displayed in your toolbox.

Draw the new control on your form. In the properties select custom. Enter the number of tab pages you desire and the number of tab rows. (You can select 1 row or several).

Each tab page is a container. At design time you can place any controls you wish on each tab page. All controls are global to the form even though they are on separate tab pages. (See attached pic)

There are scads of properties you can change to alter how the control looks.

D,

Is working within the control substantially faster?
Attached Images
File Type: jpg Tabbed Dialog Control.jpg (103.8 KB, 22 views)
__________________
Burn the land and boil the sea
You can't take the sky from me


~T

Last edited by Gruff; 09-03-2010 at 05:29 PM.
Reply With Quote
  #13  
Old 09-04-2010, 08:01 AM
vbnoober vbnoober is offline
Newcomer
 
Join Date: Sep 2010
Posts: 13
Default

Mr.dilettante, your code is too advanced for me, i'm juz a beginner to VB ... but thanks anyway for your time, hope i'll implement your code in the future when i understand it.

Mr.TRSDOSBasic79, thanks for the ideas, i'll search for it on web for more details

And Mr.Gruff, i can't find "Microsoft Tabbed Dialog Control 6.0" in my VB Software, btw i'm using VB 2008, do i have to install anything else separately.

Thank you very much guys ... you are really very helpful, i've created my first software (v 1.0 ... lol) with your help, i'll implement tabs and text document in v 2.0 when i understand them better ... though the code which i've written is very very lengthy, it's saving my time very much...
Reply With Quote
  #14  
Old 09-04-2010, 10:00 AM
dilettante's Avatar
dilettanteLine Breaks In TextBox dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,520
Default

Quote:
Originally Posted by Gruff View Post
D,

Is working within the control substantially faster?
I'm not sure what you mean by "faster" here.

The advantage of using a UserControl is that each of your tab-frames becomes a bit like a sub-form to work with. Then when you use a control like the TabStrip which does not offer separate container frames the only extra work required is to toggle visibility as tabs are seelcted at runtime.

If you use a Frame or PictureBox instead it gets messy, because you have to drag them out of the way of each other to work on the control layout within them.

Also as I mentioned before you can isolate a lot of the event handler logic so your Form code doesn't get huge and confusing.
Reply With Quote
  #15  
Old 09-04-2010, 11:10 AM
dilettante's Avatar
dilettanteLine Breaks In TextBox dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,520
Default

Using a TabStrip instead of the old SSTab control helps avoid that nasty "Windows 3.1" look too.
Attached Images
File Type: png sshot.png (4.5 KB, 14 views)
Reply With Quote
  #16  
Old 09-06-2010, 09:15 PM
passel's Avatar
passelLine Breaks In TextBox passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

Quote:
Originally Posted by vbnoober View Post
...
And Mr.Gruff, i can't find "Microsoft Tabbed Dialog Control 6.0" in my VB Software, btw i'm using VB 2008, do i have to install anything else separately.
...
If your're using VB 2008, which is VB.net, you should be posting in the .Net side of the forum. The Legacy side of the forum is for VB6 (1998) and earlier versions of Visual Basic. I'll move this thread. Post in the .Net side in the future.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #17  
Old 09-07-2010, 09:05 AM
AtmaWeapon's Avatar
AtmaWeaponLine Breaks In TextBox AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

I'll take a hack at answering the situation described in #9, but first I need you to agree to stop saying what you said in #13:
Quote:
your code is too advanced for me, i'm juz a beginner to VB ... but thanks anyway for your time, hope i'll implement your code in the future when i understand it.
You came here for help with a problem you didn't know how to solve; by definition that makes *any* answer too advanced for you. If the solution were within your grasp, you'd have solved the problem rather than asking about it on a forum! So I'm not really sure what kind of code snippets you were expecting.

In the future, ask about the parts you don't understand. The more you understand, the more problems you can solve. Putting it off until later just means you'll be a beginner that much longer.

Since this is a matter of UI, the relevant code snippets are going to be long and boring. The designer happens to generate this code for you, and I imagine you'd rather do that. If you want to put controls into tabs, this process works:
  1. Look in your toolbox for TabControl. It's normally in the "Containers" category, but I tend to always use "All Windows Forms" because it's easier than memorizing which category stuff belongs to.
  2. Drag the TabControl onto your form.
  3. Working with the TabControl works similar to how you work with it at runtime. The active tab looks brighter and in front of other tabs. You can change tabs by clicking the tab you want to change to. If you want to add tabs, you have a few choices. You should see a small button with a triangle on it near the top right of the control. If you click that (it's called a "Smart Tag"), you'll see an "Add Tab" and "Remove Tab" option. You can also see links in the control's Properties window (if the "Commands" right-click option is checked. The final (and probably most intuitive) way to work with the tab pages is to look for the TabPages property in the Properties window and click the "..." button in its value.
  4. When you drag a control onto the TabControl, the control is placed on the tab page that is currently selected.
The designer's not really magic. When you create a TabControl, it automatically generates code to create the control, add tab pages, and add controls to the pages. Here's a really simple example of what it might look like:
Code:
TabControl1 = New TabControl()
Dim page As New TabPage()
Dim textBox1 As New TextBox()

page.Controls.Add(textBox1)
TabControl1.TabPages.Add(page)
Me.Controls.Add(TabControl)
Trust me, you'll almost always want to use the designer instead of writing that code yourself.

Having 40 controls on a form is usually not a good idea. There's some magic number where the form starts to get slow, and my rule of thumb is to strive to keep it under 20 or so. Even if a control is on an invisible tab page, if it exists it is using resources. If you're interested, I can talk about techniques to reuse controls to keep the number of active controls down, but it's a little too much for this response.

I'm sort of curious about your second question. Are you asking how to save the text into a text document, how to copy it to the clipboard, or something else? I have a feeling it's likely that you have a problem and feel like Notepad is part of the solution; it'd be most useful if you describe the problem itself rather than how you think Notepad solves it.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #18  
Old 09-07-2010, 09:45 AM
Gruff's Avatar
GruffLine Breaks In TextBox Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

D, RE: 'Is working within the control substantially faster?'
I was referring to your solution for adjusting the contents of a textbox.
(The original question.)

Yes. The post being in the wrong area threw me off track as well.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
  #19  
Old 09-08-2010, 12:17 PM
vbnoober vbnoober is offline
Newcomer
 
Join Date: Sep 2010
Posts: 13
Default

Thank You Very Very Very much AtmaWeapon for explaining crystal clear about the tabs, i followed your steps and i juz got what i wanted ... lol now my design looks really great with those tabs

sorry for saying the "advanced code" thingy, from now on i'll try to ask until i understand completely.

And about the text document or notepad ..... before i got an idea to create a software and learn vb for that, i was doing all my work manually by writing, modifying and saving all the text in a notepad which is very hectic work i should say.

As you said, i'll try to describe the problem rather than how i think notepad solves it...

What i really want is, with the help of some "text boxes" and "buttons" i am able to generate some "text" which i wanted for my work. Now all i want is to store this "generated text" on my hard drive for later reference.

Even now i am doing "saving the generated text" part manually by copying from the "textboxes" and pasting it in the notepad, it will be very time saving if this can be done automatically. I hope you understand Now.
Reply With Quote
  #20  
Old 09-10-2010, 02:38 PM
Gruff's Avatar
GruffLine Breaks In TextBox Gruff is offline
Bald Mountain Survivor

Retired Moderator
* Expert *
 
Join Date: Aug 2003
Location: Oregon, USA - deceased
Posts: 6,440
Default

VB.NET has methods to write data to disk. If you look under System.IO you will find several. I suggest you take some time and explore them. One of the simple methods for the kind of task you want might be the System.IO.File.WriteAllText() method.
__________________
Burn the land and boil the sea
You can't take the sky from me


~T
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Line Breaks In TextBox
Line Breaks In TextBox
Line Breaks In TextBox Line Breaks In TextBox
Line Breaks In TextBox
Line Breaks In TextBox
Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox Line Breaks In TextBox
Line Breaks In TextBox
Line Breaks In TextBox
 
Line Breaks In TextBox
Line Breaks In TextBox
 
-->