Jump to content

Function to select from a list


Recommended Posts

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"

Select_From_Menue.jpg.a48847bcdb4bfbc40f

 

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

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)

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

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

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!

 

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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

 

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