Link to home
Start Free TrialLog in
Avatar of charnal
charnal

asked on

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?
Avatar of Erick37
Erick37
Flag of United States of America image

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
Avatar of Bob Learned
Another way could be:

With Text1
   .SelStart = Len(.Text)
   .SelLength = 1
   .Text = vbCrLf & Text2.Text
End With
Avatar of Vbmaster
Vbmaster

Just wanted to correct the 'typo' on TheLearnedOne's comment..

  With Text1
    .SelStart = Len(.Text)
    .SelLength = 1
    .SelText = vbCrLf & Text2.Text    '<- corrected
  End With
Avatar of charnal

ASKER

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.
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
P.S.
Add two vbCrLf's if you want a space between paragraphs...
Avatar of charnal

ASKER

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.
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
Avatar of charnal

ASKER

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.
----------------------------------------



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
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?
Avatar of charnal

ASKER

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.
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.
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 = ""
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.
I did that to prevent the first line from being a vbCrLf
ASKER CERTIFIED SOLUTION
Avatar of lmerrell
lmerrell

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial