Jump to content



Photo

Problem with "&" sign in string


  • Please log in to reply
8 replies to this topic

#1 roboz

roboz

    Seeker

  • Active Members
  • 17 posts

Posted 13 July 2005 - 10:23 AM

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, 13 July 2005 - 10:24 AM.






#2 GaryFrost

GaryFrost

    I don't need your attitude. I have one of my own

  • Developers
  • 7,854 posts

Posted 13 July 2005 - 11:07 AM

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.


#3 sandyd

sandyd

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 254 posts

Posted 13 July 2005 - 11:09 AM

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 ]---

#4 roboz

roboz

    Seeker

  • Active Members
  • 17 posts

Posted 13 July 2005 - 11:39 AM

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

#5 LxP

LxP

    Real satisfaction in every glass.

  • Active Members
  • PipPipPipPipPipPip
  • 1,619 posts

Posted 13 July 2005 - 11:52 AM

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, 13 July 2005 - 11:53 AM.


#6 roboz

roboz

    Seeker

  • Active Members
  • 17 posts

Posted 13 July 2005 - 11:53 AM

I'll do that. Thanks

#7 LxP

LxP

    Real satisfaction in every glass.

  • Active Members
  • PipPipPipPipPipPip
  • 1,619 posts

Posted 13 July 2005 - 11:58 AM

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)


#8 seandisanti

seandisanti

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 2,927 posts

Posted 14 July 2005 - 08:55 PM

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

#9 roboz

roboz

    Seeker

  • Active Members
  • 17 posts

Posted 16 July 2005 - 03:51 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users