Page 1 of 1

Trouble with Ampersand Character

Posted: Sat Dec 15, 2012 5:54 pm
by wxdude
Does any one know if the Ampersand character (&) needs to be escaped when used in some circumstances?

For example with the code below, the form caption displays the & character correctly, yet the button caption does not. Seems that the & and a space is replaced with an underscore.

Image

The answer is probably simple but I cannot for the life of me figure out how to get the ampersand to display properly on the button...can anyone provide some guidance?

Thanks.

Code: Select all

Option Explicit

Dim Form, Btn
Sub OnStartup
	Script.RegisterEvent SDB, "OnPlay", "OnPlaybackStart"
End Sub

Sub OnPlaybackStart

	Set Form = SDB.UI.NewForm
	Form.Common.SetRect 100, 100, 500, 400
	Form.Caption = "Title with an & ampersand"
	 
	Set Btn = SDB.UI.NewButton(Form)
	Btn.Caption = "Close & exit"
	Btn.Common.SetRect 10, 10, 100, 20
	 
	Form.ShowModal

End Sub

Re: Trouble with Ampersand Character

Posted: Sat Dec 15, 2012 10:30 pm
by Lowlander

Re: Trouble with Ampersand Character

Posted: Sun Dec 16, 2012 1:37 am
by wxdude
Thanks for that Lowlander.

I knew it had to be easy and I tried every other escape sequence I knew of....guess I'm just unsure why it has to be escaped in button text, but not the form text.

Re: Trouble with Ampersand Character

Posted: Mon Dec 17, 2012 3:43 pm
by Lowlander
In the button a single & is used to indicate the shortcut key to access the button. ie. If you have a button text like Click H&ere the e is used as shortcut key (Alt+E or if that's wrong Ctrl+E).

Re: Trouble with Ampersand Character

Posted: Tue Dec 18, 2012 6:15 pm
by wxdude
Now it's starting to make sense to me.....thanks again Lowlander.