Sign in to follow this  
Followers 0
roboz

Problem with "&" sign in string

9 posts in this topic

#1 ·  Posted (edited)

Hi,

I've got a problem with displaying the "&" sign properly. Here's a short example:

$album = "Lock, Stock & Two Smoking Barrels"

GuiCreate("test", 600, 210)  
  
$abc = GUICtrlCreateLabel ($album, 20, 80, 400, 80)
   
GUISetState()

MsgBox(4096,'debug:' , '$album:' & $album)


While 1
   
   Sleep (100)
   
WEnd

The label created with GUICtrlCreateLabel shows:

Lock, Stock_Two Smoking Barrels

The message window shows the correct:

Lock, Stock & Two Smoking Barrels

When I replace "&" with "&&" in the string it shows one "&" in the label. Can aynone please explain why this happens? Using v3.1.1 by the way

Thanks

Edited by roboz

Share this post


Link to post
Share on other sites



for GUI it would be to identify a shortcut key for example an OK button

Select Alt+o and see what happens

#include <GuiConstants.au3>

$album = "Lock, Stock && Two Smoking Barrels"

GuiCreate("test", 600, 210)  
  
$abc = GUICtrlCreateLabel ($album, 20, 80, 400, 80)
$Button = GUICtrlCreateButton ("&OK",  10, 30, 50)

GUISetState()

While 1
   $msg = GUIGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button
        MsgBox(4096,'debug:' , '$album:' & $album)
    EndSelect
WEnd

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Windows standard for controls is to use the & to indicate an accelerator key.

e.g. If you give a button the text of Can&cel the button will show Canc el.

This means that if you press ALT+c the button is clicked.

Labels can be attached to Edits to allow the same thing to happen. If you press the ALT key and the accelerator key, the focus is moved to the Edit relating to the Label.

The message box is just showing the string literaly.

Hope that helps.


----[ SandyD ]---

Share this post


Link to post
Share on other sites

Thanks for the quick replies. So is there an easy way to show the string in the label literally?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

The best way would be to StringReplace() any '&' occurences in your data with '&&' while displaying on the GUI:

$album = "Lock, Stock & Two Smoking Barrels"

guiCreate("test", 600, 210)  
$abc = guiCtrlCreateLabel(stringReplace($album, "&", "&&"), 20, 80, 400, 80)
guiSetState()
Edited by LxP

Share this post


Link to post
Share on other sites

I'll do that. Thanks

Share this post


Link to post
Share on other sites

Probably an even better solution would be to create your label with the $SS_NOPREFIX style included:

$abc = guiCtrlCreateLabel($album, 20, 80, 400, 80, $SS_NOPREFIX)

Share this post


Link to post
Share on other sites

Probably an even better solution would be to create your label with the $SS_NOPREFIX style included:

$abc = guiCtrlCreateLabel($album, 20, 80, 400, 80, $SS_NOPREFIX)

<{POST_SNAPBACK}>

another alternative would be to use chr(38) inplace of your &...

ex: "Lock, Stock, " & chr(38) & " 2 smoking barrels"... in notepad you could just press control h, and replace '&' with '" & chr(38) & "' without the surrounding single quotes... that way you can have a hotkey AND and a '&' in your string...


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

Thanks for all the help. I think I'll go with the $SS_NOPREFIX because I'm reading the information directly from iTunes through the COM interface, so that's probably the easiest way.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0