Blaxxun Posted March 4, 2016 Posted March 4, 2016 (edited) Hello Forum, Iam looking for an elegant way to select points in a menu (see below). In this menu one can go up and down with the arrow keys and select with enter. There is also a "Done" field when the points are selected. To cover all possibilities i thought it might be wise to use something like Func select($mode) where $mode is a number which represents a menu point. Lets say i wanna select B and D then the number would be 10. After selection the cursor moves to "Done" My problem now is how to split up the given number back into the single numbers. Im sure there is a name for this process. I just dont know how it is called or what i should look for. Thankfull for every hint. Edited March 5, 2016 by Blaxxun
Moderators Melba23 Posted March 4, 2016 Moderators Posted March 4, 2016 Blaxxun, Quote My problem now is how to split up the given number back into the single numbers You can use BitAnd to check if a single number is present within the given number. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Blaxxun Posted March 4, 2016 Author Posted March 4, 2016 Oh wow, that was quick. Thank you. This means with BitAND i can extract 7 numbers from 127 ? Okay, i have to check that out.
Blaxxun Posted March 4, 2016 Author Posted March 4, 2016 It WORKS!!!! Func BitAndTest() Local $Mode = 21 If BitAND($Mode, 1) Then ConsoleWrite("1 is in" & @CRLF) If BitAND($Mode, 2) Then ConsoleWrite("2 is in" & @CRLF) If BitAND($Mode, 4) Then ConsoleWrite("4 is in" & @CRLF) If BitAND($Mode, 8) Then ConsoleWrite("8 is in" & @CRLF) If BitAND($Mode, 16) Then ConsoleWrite("16 is in" & @CRLF) If BitAND($Mode, 32) Then ConsoleWrite("32 is in" & @CRLF) If BitAND($Mode, 64) Then ConsoleWrite("64 is in" & @CRLF) EndFunc ;==>BitAndTest THANK YOU!!!!
Moderators Melba23 Posted March 4, 2016 Moderators Posted March 4, 2016 Blaxxun, Of course it works - that is how Windows decides which out of the many styles we choose to apply to GUIs and controls. But it will only work if the numbers in question are powers of 2, of course. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
Blaxxun Posted March 4, 2016 Author Posted March 4, 2016 Cool, thanks. Never used that command before. But i was on the right way with my powers of two.
AutoBert Posted March 4, 2016 Posted March 4, 2016 You can solve this i a function like this: #include <Array.au3> Do $iVar = InputBox('number to check', 'Please enter number', '', '', 3) If Not @error Then $aVar = _GetSetBits($iVar) _ArrayDisplay($aVar) Else $iVar=999 EndIf Until $iVar=999 Func _GetSetBits($iToCheck) ConsoleWrite('checking: '&$iToCheck&@CRLF) Local $aBits[8] For $x = 0 to 7 If BitAND(2 ^ $x, $iToCheck) Then $aBits[$x] = 1 ConsoleWrite('Bit: '&$x&' is set (2^'&$x&' is in '&$iVar&')') Else $aBits[$x] = 0 ConsoleWrite('Bit: '&$x&' isn''t set (2^'&$x&' isn''t in '&$iVar&')') EndIf ConsoleWrite(@CRLF) Next ConsoleWrite(@CRLF) Return $aBits EndFunc ;==>_GetSetBits
Blaxxun Posted March 4, 2016 Author Posted March 4, 2016 (edited) Cool AutoBert, Isnt that a so called "Bit Viewer" ? Or kind of. Nice attempt. Thank you for that! In the meanwhile i was able to finalize my "menu chooser" with button control. expandcollapse popupFunc SetMenue($Mode) ; The "s" key moves the cursor one menue item down Local $AZ = 1 Send("{SPACE}") ; Press Menue Button to open menue Sleep(200) If BitAND($Mode, 1) Then ;ConsoleWrite("Punkt 1 gewählt" & @CRLF) Send("{SPACE}") $AZ = 1 EndIf If BitAND($Mode, 2) Then ;ConsoleWrite("Punkt 2 gewählt" & @CRLF) Send("s") Send("{SPACE}") $AZ = 2 EndIf If BitAND($Mode, 4) Then ;ConsoleWrite("Punkt 4 gewählt" & @CRLF) Send("{s " & 3 - $AZ & "}") Send("{SPACE}") $AZ = 3 EndIf If BitAND($Mode, 8) Then ;ConsoleWrite("Punkt 8 gewählt" & @CRLF) Send("{s " & 4 - $AZ & "}") Send("{SPACE}") $AZ = 4 EndIf If BitAND($Mode, 16) Then ;ConsoleWrite("Punkt 16 gewählt" & @CRLF) Send("{s " & 5 - $AZ & "}") Send("{SPACE}") $AZ = 5 EndIf If BitAND($Mode, 32) Then ;ConsoleWrite("Punkt 32 gewählt" & @CRLF) Send("{s " & 6 - $AZ & "}") Send("{SPACE}") $AZ = 6 EndIf If BitAND($Mode, 64) Then ;ConsoleWrite("Punkt 64 gewählt" & @CRLF) Send("{s " & 7 - $AZ & "}") Send("{SPACE}") $AZ = 7 EndIf Send("{BACKSPACE}"); Exit Menue EndFunc ;==>SetMenue Edited March 5, 2016 by Blaxxun
AutoBert Posted March 4, 2016 Posted March 4, 2016 (edited) The logic behind you can also use for your menu chooser: Func SetMenue($Mode) ; The "s" key moves the cursor one menue item down Local $AZ = 1 Send("{SPACE}") ; Press Menue Button to open menue Sleep(200) For $x= 1 to 7 If BitAND($Mode, $2^x) Then ;ConsoleWrite("Punkt "&$x&" gewählt" & @CRLF) if $x< 3 Then ;müßte logisch eigentlich < 2 bzw. =1 sein Send("{SPACE}") ;warum diese Sonderbehandlung vom 1. und 2. Menüeintrag? ;vom Original übernommen aber nicht verstanden warum auch der 2. Eintrag ;ein anderes Send benötigt. Else Send("{s " & $x - $AZ & "}") EndIf EndIf $AZ = $x Next Send("{BACKSPACE}"); Exit Menue EndFunc ;==>SetMenue Edited March 4, 2016 by AutoBert
Blaxxun Posted March 4, 2016 Author Posted March 4, 2016 Oh nice. Thanks AutoBert! I thought already that my code could have been more compressed but since it worked fine i just left it as it is. The reason behind the special treatment of menu 1 is that the cursor is always on it when you enter the menu. So it doesnt need a cursor down. The second entry needs only 1 move downwards, so i used Send("s") only without variable. I guess it would also work with Send("{s " & $x - $AZ & "}") when $x = 0 Ill check it out. Thank you! Vielen Dank!
Blaxxun Posted March 4, 2016 Author Posted March 4, 2016 I checked it out but i cant seem to make it work properly. The first problem was that my list started with 1,2,4,8,16,32,64 but 2^$x starts with 2. If i set $mode to 254 it selects everything which is correct, but if i set it to 192 it selects the first 3 entrys instead of the last 2. Func SetMenue($Mode) ; The "s" key moves the cursor one menue item down Local $AZ = 1 Send("{SPACE}") ; Press Menue Button to open menue Sleep(200) For $x= 1 to 7 If BitAND($Mode, 2^$x) Then Send("{s" & $x - $AZ & "}") Send("{SPACE}") EndIf $AZ = $x Next Send("{BACKSPACE}"); Exit Menue EndFunc ;==>SetMenue I get the idea, but have to look into it further. Thanks a lot
AutoBert Posted March 4, 2016 Posted March 4, 2016 Sorry, the for $x must start with0: Func SetMenue($Mode) ; The "s" key moves the cursor one menue item down Local $AZ = 1 Send("{SPACE}") ; Press Menue Button to open menue Sleep(200) For $x= 0 to 7 If BitAND($Mode, 2^$x) Then Send("{s" & $x+1-$AZ & "}") Send("{SPACE}") EndIf $AZ = $x+1 Next Send("{BACKSPACE}"); Exit Menue EndFunc ;==>SetMenue
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now