Simple little ditty

I have several text boxes that write text to another text box.  How do I make it so I can keep the text previously written, put in a carrage return then write more text without it writing over the existing text?
charnalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
Not sure if this is what you are after, but insert the vbCrLf (carriage return/ linefeed) characters between strings to wrap them on different lines.
Set all Textbox .Multiline properties True:

Private Sub Text1_Change()
    Text3.Text = Text1.Text & vbCrLf & Text2.Text
End Sub

Private Sub Text2_Change()
    Text3.Text = Text1.Text & vbCrLf & Text2.Text
End Sub
0
Bob LearnedCommented:
Another way could be:

With Text1
   .SelStart = Len(.Text)
   .SelLength = 1
   .Text = vbCrLf & Text2.Text
End With
0
VbmasterCommented:
Just wanted to correct the 'typo' on TheLearnedOne's comment..

  With Text1
    .SelStart = Len(.Text)
    .SelLength = 1
    .SelText = vbCrLf & Text2.Text    '<- corrected
  End With
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

charnalAuthor Commented:
I think that I may have explained it kind of bad.  I have 4 text boxes that write data to a single, multi-line textbox.  consider the data written from the 4 text boxes to the single multi-line text box as a paragraph.  Now I want to hit a button and clear the origional data from the 4 boxes, enter new data into then and write it to the single text box as a new paragraph. Does this help?  it is kind of hard to explain.
0
Erick37Commented:
Maybe this?

Private Sub cmdBuild_Click()
    'Build the paragraph
    txtMain.Text = Text1.Text & vbCrLf & _
                Text2.Text & vbCrLf & _
                Text3.Text & vbCrLf & _
                Text4.Text
    Text1.Text = "" 'Clear the other boxes after building the aragraph
    Text2.Text = ""
    Text3.Text = ""
    Text4.Text = ""
End Sub
0
Erick37Commented:
P.S.
Add two vbCrLf's if you want a space between paragraphs...
0
charnalAuthor Commented:
The only problem is that the data form all 4 text boxes combine to make 1 paragraph in the main text box.  Then I want to clear the 4 and create another paragraph under the first.  The problem now is that it writes over the first paragraph instead of creating a new one.
0
lmerrellCommented:
Try changing:

  txtMain.Text = Text1.Text & vbCrLf & _
   Text2.Text & vbCrLf & _
    Text3.Text & vbCrLf & _
    Text4.Text

to:

  txtMain.Text = txtMain.Text & Text1.Text & vbCrLf & _
   Text2.Text & vbCrLf & _
    Text3.Text & vbCrLf & _
    Text4.Text

lmerrell
0
charnalAuthor Commented:
O.k. here it is...(Example of what output should look like.)

Imaging this is my main text box.  I enter data into the 4 text boxes and the out put is the following.


output:
----------------------------------------
This would be the first paragraph in th e main text box, la, la, la, blah.
----------------------------------------

Now I want to enter new data in to the 4 textboxes and create another paragraph under the first one.  like the following.

Desired output:
----------------------------------------
This would be the first paragraph in th e main text box, la, la, la, blah.

This would be the second paragraph in the main text box under the output from the first input.
----------------------------------------



0
lmerrellCommented:
Do as Erick37 suggested except make the change that I suggested.  This should give you what you want.


 Private Sub cmdBuild_Click()
  'Build the paragraph
txtMain.Text = txtMain.Text & Text1.Text & vbCrLf & _
 Text2.Text & vbCrLf & _
 Text3.Text & vbCrLf & _
 Text4.Text & vbCrLf & vbCrLf
 Text1.Text = "" 'Clear the other boxes after building the aragraph
  Text2.Text = "" 
  Text3.Text = "" 
  Text4.Text = "" 
End Sub
0
Erick37Commented:
Do the 4 textboxes represent paragraphs, sentences, or words?

i.e. if yooy had 4 text boxes with:

"one"   "two"   "three"   "four"

what should the first paragraph be?
0
charnalAuthor Commented:
The four text boxes represent sentences, that combine to make a paragraph.  As is when I clear them after the paragraph is writen to the main text box and write new ones it overwrites the existing paragraph.
0
lmerrellCommented:
charnal - Have you tried the code that I pasted.  If you notice, txtMain.text is being appended to the beginning of the four sentences.  Therefore you will get whatever is already in txtMain and the addition of the four sentences.
0
Erick37Commented:
Try this:

Dim sTmp As String
sTmp = IIf(Text1.Text = "", "", Text1.Text & " ")
sTmp = sTmp & IIf(Text2.Text = "", "", Text2.Text & " ")
sTmp = sTmp & IIf(Text3.Text = "", "", Text3.Text & " ")
sTmp = sTmp & IIf(Text4.Text = "", "", Text4.Text)
If txtMain.Text = "" Then
    txtMain.Text = sTmp
Else
    txtMain.Text = txtMain.Text & IIf(sTmp = "", "", vbCrLf & sTmp)
End If
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
0
lmerrellCommented:
Actually, Erick37, you shouldn't need to check for an existing value in txtMain.Text because if txtMain.Text was "" then:

txtMain.Text = sTmp

and

txtMain.Text = txtMain.Text & sTmp

would render the same results.
0
Erick37Commented:
I did that to prevent the first line from being a vbCrLf
0
lmerrellCommented:
Ok, I see.  But you could have placed the vbCrLf at the end if sTmp was not "", but that would still require a conditional check.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.