Jump to content

Problem with "&" sign in string


Recommended Posts

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
Link to comment
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.

 

Link to comment
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 ]---
Link to comment
Share on other sites

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
Link to comment
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)
Link to comment
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...

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...