transfer text from label to textbox preserving linebreaks 
Author Message
 transfer text from label to textbox preserving linebreaks

(vb6) I want to write the text which appears in a label to a textbox
while keeping linebreaks.

The label caption is written using -

[text] & vbnewline & [text] & vbnewline & [text]

but

textbox1 = label1

gives me the text seperated by "|" all on one line
(even though the textbox is set multiline at design time).

Interestingly

msgbox label1

displays the text with linebreaks correctly.

Any ideas. Something so simple is baffling me!!



Wed, 22 Jun 2011 16:45:03 GMT  
 transfer text from label to textbox preserving linebreaks
See whether using vbCrLf instead of vbNewLine helps.

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no private e-mails, please)


Quote:
> (vb6) I want to write the text which appears in a label to a textbox while
> keeping linebreaks.

> The label caption is written using -

> [text] & vbnewline & [text] & vbnewline & [text]

> but

> textbox1 = label1

> gives me the text seperated by "|" all on one line
> (even though the textbox is set multiline at design time).

> Interestingly

> msgbox label1

> displays the text with linebreaks correctly.

> Any ideas. Something so simple is baffling me!!



Wed, 22 Jun 2011 20:47:59 GMT  
 transfer text from label to textbox preserving linebreaks

Quote:
> (vb6) I want to write the text which appears in a label to a textbox while
> keeping linebreaks.

> The label caption is written using -

> [text] & vbnewline & [text] & vbnewline & [text]

> but

> textbox1 = label1

> gives me the text seperated by "|" all on one line
> (even though the textbox is set multiline at design time).

I can't duplicate that with VB6 + SP5 on XP+SP2. Please post your code. Here
is the test I tried(with MultiLine is set to True):

Option Explicit

Private Sub Form_Load()
    Label1.Caption = "Line1" & vbNewLine & "Line2" & vbNewLine & "Line3"
    Text1.Text = Label1.Caption
End Sub



Wed, 22 Jun 2011 20:57:23 GMT  
 transfer text from label to textbox preserving linebreaks


Quote:
> See whether using vbCrLf instead of vbNewLine helps.

In my copy of VB6+SP5, and using SP6 of the runtime, vbNewLine is the same
as vbCrLf. Here is test code I used:

Option Explicit

Private Sub Form_Load()
    Dim i As Long
    Dim s As String

    s = vbNewLine
    For i = 1 To Len(s)
        Debug.Print Asc(Mid(s, i, 1))
    Next

End Sub

It prints the following for both vbNewLine and vbCrLf.

 13
 10

I am not sure if they are the same under all circumstances.



Wed, 22 Jun 2011 21:12:30 GMT  
 transfer text from label to textbox preserving linebreaks


Quote:
> (vb6) I want to write the text which appears in a label to a textbox while
> keeping linebreaks.

> The label caption is written using -

> [text] & vbnewline & [text] & vbnewline & [text]

> but

> textbox1 = label1

> gives me the text seperated by "|" all on one line
> (even though the textbox is set multiline at design time).

> Interestingly

> msgbox label1

> displays the text with linebreaks correctly.

> Any ideas. Something so simple is baffling me!!

Make sure the TextBox's MultiLine property is set to True.  You must do this
at design-time as the property is read-only at runtime.

--
Mike



Wed, 22 Jun 2011 21:54:41 GMT  
 transfer text from label to textbox preserving linebreaks

Quote:



>> (vb6) I want to write the text which appears in a label to a textbox while
>> keeping linebreaks.

>> The label caption is written using -

>> [text] & vbnewline & [text] & vbnewline & [text]

>> but

>> textbox1 = label1

>> gives me the text seperated by "|" all on one line
>> (even though the textbox is set multiline at design time).

> I can't duplicate that with VB6 + SP5 on XP+SP2. Please post your code. Here
> is the test I tried(with MultiLine is set to True):

> Option Explicit

> Private Sub Form_Load()
>     Label1.Caption = "Line1" & vbNewLine & "Line2" & vbNewLine & "Line3"
>     Text1.Text = Label1.Caption
> End Sub

Basically it is a form with lots of filled in labels (a control array).
If the user wants to edit one they can right click, choose edit, and a
small form comes up with a text box containing the label text. They
edit, click Save, and the label changes.

I have coded it so a public variable stores the label text on the mouse
down event when the user right clicks to display the menu.

Here's the simplified code.

[Main form]
Public CurrentLabelText As Object

Private Sub MyLabel_MouseDown(.....)
If (Button = vbRightButton) Then
     Set CurrentLabelText = MyLabel(Index).caption
     PopupMenu mnuOptions
end if
End Sub

Private Sub mnuEdit_Click()
SmallForm.show
SmallForm.textbox1 = CurrentLabelText
End Sub



Thu, 23 Jun 2011 03:10:31 GMT  
 transfer text from label to textbox preserving linebreaks
Quote:




>>> (vb6) I want to write the text which appears in a label to a textbox
>>> while keeping linebreaks.

>>> The label caption is written using -

>>> [text] & vbnewline & [text] & vbnewline & [text]

>>> but

>>> textbox1 = label1

>>> gives me the text seperated by "|" all on one line
>>> (even though the textbox is set multiline at design time).

>> I can't duplicate that with VB6 + SP5 on XP+SP2. Please post your
>> code. Here is the test I tried(with MultiLine is set to True):

>> Option Explicit

>> Private Sub Form_Load()
>>     Label1.Caption = "Line1" & vbNewLine & "Line2" & vbNewLine & "Line3"
>>     Text1.Text = Label1.Caption
>> End Sub

> Basically it is a form with lots of filled in labels (a control array).
> If the user wants to edit one they can right click, choose edit, and a
> small form comes up with a text box containing the label text. They
> edit, click Save, and the label changes.

> I have coded it so a public variable stores the label text on the mouse
> down event when the user right clicks to display the menu.

> Here's the simplified code.

> [Main form]
> Public CurrentLabelText As Object

> Private Sub MyLabel_MouseDown(.....)
> If (Button = vbRightButton) Then
>     Set CurrentLabelText = MyLabel(Index).caption
>     PopupMenu mnuOptions
> end if
> End Sub

> Private Sub mnuEdit_Click()
> SmallForm.show
> SmallForm.textbox1 = CurrentLabelText
> End Sub

>Sorry should read - > Public CurrentLabelText As STRING



Thu, 23 Jun 2011 03:12:38 GMT  
 transfer text from label to textbox preserving linebreaks
Quote:



>> (vb6) I want to write the text which appears in a label to a textbox while
>> keeping linebreaks.

>> The label caption is written using -

>> [text] & vbnewline & [text] & vbnewline & [text]

>> but

>> textbox1 = label1

>> gives me the text seperated by "|" all on one line
>> (even though the textbox is set multiline at design time).

> I can't duplicate that with VB6 + SP5 on XP+SP2. Please post your code. Here
> is the test I tried(with MultiLine is set to True):

> Option Explicit

> Private Sub Form_Load()
>     Label1.Caption = "Line1" & vbNewLine & "Line2" & vbNewLine & "Line3"
>     Text1.Text = Label1.Caption
> End Sub

Basically it is a form with lots of filled in labels (a control array).
If the user wants to edit one they can right click, choose edit, and a
small form comes up with a text box containing the label text. They
edit, click Save, and the label changes.

I have coded it so a public variable stores the control object on the
mouse down event when the user right clicks to display the menu.

Here's the simplified code -

[Main form]
Public CurrentControl As Object
Private Sub MyLabel_MouseDown(.....)
If (Button = vbRightButton) Then
     Set CurrentControl = MyLabel(Index)
     PopupMenu mnuOptions
End If
End Sub

Private Sub mnuEdit_Click()
SmallForm.show
SmallForm.textbox1 = CurrentControl.Caption
End Sub

I know public variables are not a good thing but the small form needs to
know which control to make the changes to on Save.



Thu, 23 Jun 2011 03:30:57 GMT  
 transfer text from label to textbox preserving linebreaks



Quote:




>>>> (vb6) I want to write the text which appears in a label to a textbox
>>>> while keeping linebreaks.

>>>> The label caption is written using -

>>>> [text] & vbnewline & [text] & vbnewline & [text]

>>>> but

>>>> textbox1 = label1

>>>> gives me the text seperated by "|" all on one line
>>>> (even though the textbox is set multiline at design time).

>>> I can't duplicate that with VB6 + SP5 on XP+SP2. Please post your code.
>>> Here is the test I tried(with MultiLine is set to True):

>>> Option Explicit

>>> Private Sub Form_Load()
>>>     Label1.Caption = "Line1" & vbNewLine & "Line2" & vbNewLine & "Line3"
>>>     Text1.Text = Label1.Caption
>>> End Sub

>> Basically it is a form with lots of filled in labels (a control array).
>> If the user wants to edit one they can right click, choose edit, and a
>> small form comes up with a text box containing the label text. They edit,
>> click Save, and the label changes.

>> I have coded it so a public variable stores the label text on the mouse
>> down event when the user right clicks to display the menu.

>> Here's the simplified code.

>> [Main form]
>> Public CurrentLabelText As Object

>> Private Sub MyLabel_MouseDown(.....)
>> If (Button = vbRightButton) Then
>>     Set CurrentLabelText = MyLabel(Index).caption
>>     PopupMenu mnuOptions
>> end if
>> End Sub

>> Private Sub mnuEdit_Click()
>> SmallForm.show
>> SmallForm.textbox1 = CurrentLabelText
>> End Sub

>> Sorry should read - > Public CurrentLabelText As STRING

As is asked before, *is* SmallForm.textbox1's Multiline really set to True?

/Henning



Thu, 23 Jun 2011 03:39:56 GMT  
 transfer text from label to textbox preserving linebreaks

Quote:







>>>>> (vb6) I want to write the text which appears in a label to a textbox
>>>>> while keeping linebreaks.

>>>>> The label caption is written using -

>>>>> [text] & vbnewline & [text] & vbnewline & [text]

>>>>> but

>>>>> textbox1 = label1

>>>>> gives me the text seperated by "|" all on one line
>>>>> (even though the textbox is set multiline at design time).
>>>> I can't duplicate that with VB6 + SP5 on XP+SP2. Please post your code.
>>>> Here is the test I tried(with MultiLine is set to True):

>>>> Option Explicit

>>>> Private Sub Form_Load()
>>>>     Label1.Caption = "Line1" & vbNewLine & "Line2" & vbNewLine & "Line3"
>>>>     Text1.Text = Label1.Caption
>>>> End Sub

>>> Basically it is a form with lots of filled in labels (a control array).
>>> If the user wants to edit one they can right click, choose edit, and a
>>> small form comes up with a text box containing the label text. They edit,
>>> click Save, and the label changes.

>>> I have coded it so a public variable stores the label text on the mouse
>>> down event when the user right clicks to display the menu.

>>> Here's the simplified code.

>>> [Main form]
>>> Public CurrentLabelText As Object

>>> Private Sub MyLabel_MouseDown(.....)
>>> If (Button = vbRightButton) Then
>>>     Set CurrentLabelText = MyLabel(Index).caption
>>>     PopupMenu mnuOptions
>>> end if
>>> End Sub

>>> Private Sub mnuEdit_Click()
>>> SmallForm.show
>>> SmallForm.textbox1 = CurrentLabelText
>>> End Sub

>>> Sorry should read - > Public CurrentLabelText As STRING

> As is asked before, *is* SmallForm.textbox1's Multiline really set to True?

> /Henning

The textbox is definitely multiline. I think the problem lies in some
preprocessing of the label text by a wordwrap function.

It seems to be introducing some strange character combinations which
produce line breaks in the label but the textbox doesn't recognise.
If I swap the textbox for a label the text displays multiline.

I stumbled upon a solution but don't understand why it works -

SmallForm.textbox1 = replace(CurrentLabelText,chr(13),vbnewline)

I thought chr(13) and vbnewline do the same thing?

The text is now multiline but with "|||" characters after it. Well it's
a start.



Thu, 23 Jun 2011 12:41:53 GMT  
 transfer text from label to textbox preserving linebreaks

Quote:
> >> Option Explicit

> >> Private Sub Form_Load()
> >>     Label1.Caption = "Line1" & vbNewLine & "Line2" & vbNewLine &
"Line3"
> >>     Text1.Text = Label1.Caption
> >> End Sub

(snip)

Quote:
> > Here's the simplified code.

> > [Main form]
> > Public CurrentLabelText As Object

> > Private Sub MyLabel_MouseDown(.....)
> > If (Button = vbRightButton) Then
> >     Set CurrentLabelText = MyLabel(Index).caption
> >     PopupMenu mnuOptions
> > end if
> > End Sub

> > Private Sub mnuEdit_Click()
> > SmallForm.show
> > SmallForm.textbox1 = CurrentLabelText
> > End Sub

 >Sorry should read - > Public CurrentLabelText As STRING

Quote:
> >     Set CurrentLabelText = MyLabel(Index).caption

This doesn't throw an "object required" error?

I would suggest explicitly specifying the properties, like...
    SmallForm.textbox1.Text = CurrentLabelText

I just threw together a quick little sample... works fine for me.

Public Holdd As String
Private Sub Command1_Click()
    Holdd = Label1.Caption
End Sub
Private Sub Command2_Click()
    Text1.Text = Holdd
End Sub
Private Sub Form_Load()
    Label1.Caption = "This is" & vbNewLine & "multiline text"
End Sub

So does this (two forms)...

[Form1]
Public Holdd As String
Private Sub Command1_Click()
    Holdd = Label1.Caption
    Form2.Show
End Sub
Private Sub Form_Load()
    Label1.Caption = "This is" & vbNewLine & "multiline text"
End Sub

[Form2]
Private Sub Form_Load()
    Text1.Text = Form1.Holdd
End Sub



Thu, 23 Jun 2011 14:55:41 GMT  
 transfer text from label to textbox preserving linebreaks
Quote:

>>>> Option Explicit

>>>> Private Sub Form_Load()
>>>>     Label1.Caption = "Line1" & vbNewLine & "Line2" & vbNewLine &
> "Line3"
>>>>     Text1.Text = Label1.Caption
>>>> End Sub

> (snip)

>>> Here's the simplified code.

>>> [Main form]
>>> Public CurrentLabelText As Object

>>> Private Sub MyLabel_MouseDown(.....)
>>> If (Button = vbRightButton) Then
>>>     Set CurrentLabelText = MyLabel(Index).caption
>>>     PopupMenu mnuOptions
>>> end if
>>> End Sub

>>> Private Sub mnuEdit_Click()
>>> SmallForm.show
>>> SmallForm.textbox1 = CurrentLabelText
>>> End Sub

>  >Sorry should read - > Public CurrentLabelText As STRING

>>>     Set CurrentLabelText = MyLabel(Index).caption

> This doesn't throw an "object required" error?

> I would suggest explicitly specifying the properties, like...
>     SmallForm.textbox1.Text = CurrentLabelText

> I just threw together a quick little sample... works fine for me.

> Public Holdd As String
> Private Sub Command1_Click()
>     Holdd = Label1.Caption
> End Sub
> Private Sub Command2_Click()
>     Text1.Text = Holdd
> End Sub
> Private Sub Form_Load()
>     Label1.Caption = "This is" & vbNewLine & "multiline text"
> End Sub

> So does this (two forms)...

> [Form1]
> Public Holdd As String
> Private Sub Command1_Click()
>     Holdd = Label1.Caption
>     Form2.Show
> End Sub
> Private Sub Form_Load()
>     Label1.Caption = "This is" & vbNewLine & "multiline text"
> End Sub

> [Form2]
> Private Sub Form_Load()
>     Text1.Text = Form1.Holdd
> End Sub

Thanks Beastfish,
I have acertained that the code above works in a separate project but
doesn't work with the particular characters in the labels in my project
when written to a textbox on another form (See previous post by me).

Yes, I could store just the text in a string variable but I want to save
the edited text back to the label on the original form so I need to know
the object it came from, hence the variable stores CurrentLabel as
object and can then write to CurrentLabel.caption. I am open to
suggextions on a better way to do it.
Your help is much appreciated.

Wal



Thu, 23 Jun 2011 16:20:14 GMT  
 transfer text from label to textbox preserving linebreaks
<snipped>

Quote:
>>>> Here's the simplified code.

>>>> [Main form]
>>>> Public CurrentLabelText As Object

>>>> Private Sub MyLabel_MouseDown(.....)
>>>> If (Button = vbRightButton) Then
>>>>     Set CurrentLabelText = MyLabel(Index).caption
>>>>     PopupMenu mnuOptions
>>>> end if
>>>> End Sub

>>>> Private Sub mnuEdit_Click()
>>>> SmallForm.show
>>>> SmallForm.textbox1 = CurrentLabelText
>>>> End Sub

>>>> Sorry should read - > Public CurrentLabelText As STRING

>> As is asked before, *is* SmallForm.textbox1's Multiline really set to
>> True?

>> /Henning

Try this

Add to a .bas module
Public CurrentLabelText As String
Public CurrentLabelIndex As Integer

Change
Private Sub MyLabel_MouseDown(.....)
 If (Button = vbRightButton) Then
    CurrentLabelText = MyLabel(Index).caption
    CurrentLabelIndex = Index
    PopupMenu mnuOptions
 end if
End Sub

Private Sub mnuEdit_Click()
 SmallForm.show
End Sub

In SmallForm

Private Sub Form_Load()
  Text1.Text = CurrentLabelText
End Sub

In SmallForm Ok button

Private Sub CmdOK_Click()
  Form1.MyLabel(CurrentLabelIndex).Caption = Text1.Text
  Unload Me
End Sub

Works here with SmallForm.Text1 Multiline property set to True.

/Henning



Thu, 23 Jun 2011 19:14:11 GMT  
 transfer text from label to textbox preserving linebreaks


Wed, 18 Jun 1902 08:00:00 GMT  
 transfer text from label to textbox preserving linebreaks
Sorry, found the problem.

The label caption was originally -

[text] & vbnewline & [text] & vbnewline & [text]

but is changed to

[text] & chr(13) & [text] & chr(13) [text]

by a word wrap function.

Textboxes and Labels display the above differently.

Try this (New form, a label and a textbox set to multiline)

Private Sub Form_Load()
Text1 = "text_1" & Chr(13) & "text_2"
Label1 = "text_1" & Chr(13) & "text_2"
End Sub



Thu, 23 Jun 2011 20:05:22 GMT  
 
 [ 26 post ]  Go to page: [1] [2]

 Relevant Pages 

1. transferring text from label to textbox control

2. Linebreak in label control caption

3. Howto force linebreak in label control caption

4. linebreak in multiline textbox

5. Linebreak in textbox

6. How to move text from a textbox to label

7. Textbox Text to Label Caption - Problem with ampersand

8. Textbox Text to Label Caption - Problem with ampersand

9. transparent and rotated label/textbox text

10. CrLf (newline) in Text for Label, Textbox, etc.

11. Turning a label or textbox text 90 degrees?

12. Textbox Text to Label Caption - Problem with ampersand

 

 
Powered by phpBB® Forum Software