Discussion:
Unable to display non-breaking hyphen in VBA form
(too old to reply)
Dave Jenkins
2009-02-10 15:19:01 UTC
Permalink
Running on Office 2007 SP 1, Windows XP SP 3.

I am displaying text values in a textbox field on a form. When the text
contains a non-breaking hyphen (chr(173)) the hyphen doesn't display in the
form field. It's definitely in the data.

Do I have to do something special in the form field definition to allow the
hyphen to display?

Actually, you can reproduce this yourself by creating a simple form with a
textbox, and enter the 173 character into the text property.

Go here to see a screenshot of editor results of what I'm talking about:

http://screencast.com/t/xIazufU1G8o

Thanks
--
Dave Jenkins
K5KX
Steve Rindsberg
2009-02-10 19:44:35 UTC
Permalink
Repro'd in 2003.

The textbox retains the character, it just doesn't display it as a hyphen.

Private Sub UserForm_Activate()
Dim sText As String
sText = "123456" & Chr$(173) & "7890"

' assign the text to a couple of controls:
Me.TextBox1.Text = sText
Me.Label1.Caption = sText

' if it threw away the hyphen, we'd have ten characters:
Debug.Print Len(Me.TextBox1.Text)
' but we get 11

' if it threw away the hyphen, this'd give us the ascii val of 7
Debug.Print Asc(Mid$(Me.TextBox1.Text, 7, 1))
' but we get 173

End Sub

I'm guessing that it's a bug/side effect of the fact that text boxes don't do
hyphenation at all.

Since VBA's not going to break words anyhow, it seems that it'd be safe to

Me.TextBox1.Text = Replace(Me.TextBox1.Text, Chr$(173), "-")
Post by Dave Jenkins
Running on Office 2007 SP 1, Windows XP SP 3.
I am displaying text values in a textbox field on a form. When the text
contains a non-breaking hyphen (chr(173)) the hyphen doesn't display in the
form field. It's definitely in the data.
Do I have to do something special in the form field definition to allow the
hyphen to display?
Actually, you can reproduce this yourself by creating a simple form with a
textbox, and enter the 173 character into the text property.
http://screencast.com/t/xIazufU1G8o
Thanks
==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/
Chirag
2009-02-11 16:15:03 UTC
Permalink
At first I thought this to be a font issue but no, changing fonts does not
help. VBA TextBoxes can break long lines if you set MultiLine and WordWrap
as True. But I find that it breaks even at a non-breaking hyphen. It does
show the non-breaking hyphen when it breaks the line though. It also hides
the non-breaking hyphen when line goes back to unbroken state (when you
delete some characters).

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
Post by Steve Rindsberg
Repro'd in 2003.
The textbox retains the character, it just doesn't display it as a hyphen.
Private Sub UserForm_Activate()
Dim sText As String
sText = "123456" & Chr$(173) & "7890"
Me.TextBox1.Text = sText
Me.Label1.Caption = sText
Debug.Print Len(Me.TextBox1.Text)
' but we get 11
' if it threw away the hyphen, this'd give us the ascii val of 7
Debug.Print Asc(Mid$(Me.TextBox1.Text, 7, 1))
' but we get 173
End Sub
I'm guessing that it's a bug/side effect of the fact that text boxes don't do
hyphenation at all.
Since VBA's not going to break words anyhow, it seems that it'd be safe to
Me.TextBox1.Text = Replace(Me.TextBox1.Text, Chr$(173), "-")
Post by Dave Jenkins
Running on Office 2007 SP 1, Windows XP SP 3.
I am displaying text values in a textbox field on a form. When the text
contains a non-breaking hyphen (chr(173)) the hyphen doesn't display in the
form field. It's definitely in the data.
Do I have to do something special in the form field definition to allow the
hyphen to display?
Actually, you can reproduce this yourself by creating a simple form with a
textbox, and enter the 173 character into the text property.
http://screencast.com/t/xIazufU1G8o
Thanks
==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/
PPTools add-ins for PowerPoint
http://www.pptools.com/
Steve Rindsberg
2009-02-11 19:29:19 UTC
Permalink
Ah, that was the shove I needed, Chirag. Thanks.

Note that in CharacterMap and InsertSymbol, Chr$(173) is called a "Soft Hyphen"
not a non-breaking hyphen.

I think it's doing exactly what it's supposed to do.

A soft-hyphen is something the user can insert to suggest hyphenation points to
the line/word-breaking algorithm in the software that displays the text.

"Hyphenate the word si" & Chr$(173) "lly before rather than between the two l
characters, please."

They only appear IF the word needs to be broken/hyphenated.

ChrW(8209) or ChrW(&H2011) is what you want (and works!)

ChrW(&H2011) is probably simpler since you usually get the hex values of
Unicode characters back from reference sources, but VB wants decimal.
Post by Chirag
At first I thought this to be a font issue but no, changing fonts does not
help. VBA TextBoxes can break long lines if you set MultiLine and WordWrap
as True. But I find that it breaks even at a non-breaking hyphen. It does
show the non-breaking hyphen when it breaks the line though. It also hides
the non-breaking hyphen when line goes back to unbroken state (when you
delete some characters).
- Chirag
PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
Post by Steve Rindsberg
Repro'd in 2003.
The textbox retains the character, it just doesn't display it as a hyphen.
Private Sub UserForm_Activate()
Dim sText As String
sText = "123456" & Chr$(173) & "7890"
Me.TextBox1.Text = sText
Me.Label1.Caption = sText
Debug.Print Len(Me.TextBox1.Text)
' but we get 11
' if it threw away the hyphen, this'd give us the ascii val of 7
Debug.Print Asc(Mid$(Me.TextBox1.Text, 7, 1))
' but we get 173
End Sub
I'm guessing that it's a bug/side effect of the fact that text boxes don't do
hyphenation at all.
Since VBA's not going to break words anyhow, it seems that it'd be safe to
Me.TextBox1.Text = Replace(Me.TextBox1.Text, Chr$(173), "-")
Post by Dave Jenkins
Running on Office 2007 SP 1, Windows XP SP 3.
I am displaying text values in a textbox field on a form. When the text
contains a non-breaking hyphen (chr(173)) the hyphen doesn't display in the
form field. It's definitely in the data.
Do I have to do something special in the form field definition to allow the
hyphen to display?
Actually, you can reproduce this yourself by creating a simple form with a
textbox, and enter the 173 character into the text property.
http://screencast.com/t/xIazufU1G8o
Thanks
==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/
PPTools add-ins for PowerPoint
http://www.pptools.com/
==============================
PPT Frequently Asked Questions
http://www.pptfaq.com/

PPTools add-ins for PowerPoint
http://www.pptools.com/

Loading...