Sign in to follow this  
Followers 0
JonathanR

Ampersand Shortcut

4 posts in this topic

My script requires there to be an ampersand (&) within a list, which when selected, the name of the item is then pulled into a label. The issue being, in the list it displays as "Sweat&Sour", but in the label, it displays as "SweatSour" due to the ampersand triggering the Alt-shortcut. Is there anyway to prevent this from happening, besides doubling up the ampersand? As it would then display as "Sweat&&Sour" in the list, but "Sweat&Sour" in the input.

#include <GUIConstantsEx.au3>

GUICreate("Ampersand Shortcut", 200, 200)
$list = GUICtrlCreateList("", 10, 10, 180, 90)
GUICtrlSetData(-1, "Sweat&Sour|Sweat&&Sour")
$label = GUICtrlCreateLabel("", 25, 125, 150, 20)
GUISetState()

Do
    $msg = GUIGetMsg()
    If $msg = $list Then GUICtrlSetData($label, GUICtrlRead($list))
Until $msg = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites



Double up the ampersand when you read it from the list:

#include <GUIConstantsEx.au3>

GUICreate("Ampersand Shortcut", 200, 200)
$list = GUICtrlCreateList("", 10, 10, 180, 90)
GUICtrlSetData(-1, "Sweet&Sour|Thing|Yes & No")
$label = GUICtrlCreateLabel("", 25, 125, 150, 20)
GUISetState()

Do
    $msg = GUIGetMsg()
    If $msg = $list Then GUICtrlSetData($label, StringReplace(GUICtrlRead($list), "&", "&&"))
Until $msg = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites

There is a style called SS_NOPREFIX to suppress that ;)

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

GUICreate("Ampersand Shortcut", 200, 200)
$list = GUICtrlCreateList("", 10, 10, 180, 90)
GUICtrlSetData(-1, "Sweat&Sour|Sweat&&Sour")
$label = GUICtrlCreateLabel("", 25, 125, 150, 20, $SS_NOPREFIX)
GUISetState()

Do
    $msg = GUIGetMsg()
    If $msg = $list Then GUICtrlSetData($label, GUICtrlRead($list))
Until $msg = $GUI_EVENT_CLOSE

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Thank you, sirs. Two very good ways of accomplishing this. I don't know how, but I managed to look past the $SS_NOPREFIX style.

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