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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
lmerrellConnect With a Mentor Commented:
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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
 
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
All Courses

From novice to tech pro — start learning today.