Jump to content

Fill dynamic switch [SOLVED]


Recommended Posts

I have this switch, and the $MenuSelect will return me numbers. I need to take this number and call another var matching this number, but the var amount will change and need to be dynamic...

Switch $MenuSelect ;Above function returns the index number of the selected button from the provided buttons array.
            Case "0"
                ConsoleWrite("Returned 0 = Button 1 clicked." & @CRLF)
            Case "1"
                ConsoleWrite("Returned 1 = Button 2 clicked." & @CRLF)
            Case "2"
                ConsoleWrite("Returned 2 = Button 3 clicked." & @CRLF)
            Case "3"
                ConsoleWrite("Returned 3 = Button 4 clicked." & @CRLF)
        EndSwitch


Something like:

case $MenuSelect  is 0

do something about  $SomeVarThatAreTheFileNameSameAsBeforeTurnToMenuSelectAndIsTheFirstOption[$MenuSelect] & ".txt"

$menu select returns 3 and so on...

My script search a folder, turn the files into a list, and I need after choose his name on the list, open or read him to fill another program or vars...

If I'm not clear please let me know...Thank you!

 

Edited by edumanilha
Link to comment
Share on other sites

1 hour ago, Danp2 said:

Clear as mud! 😜

func mobile()
    If _Metro_ToggleIsChecked($Togglechoose) Then
        Local $MenuButtonsArray = _FileListToArray(@ScriptDir & "\Dados\Comandos\", "*")
        _ArrayDelete($MenuButtonsArray, 0) ;~ Delete the first item (file count).
        _ArraySort($MenuButtonsArray)

        For $i = 0 To UBound($MenuButtonsArray) - 1
$MenuButtonsArray[$i] = StringRegExpReplace($MenuButtonsArray[$i], '^.*\\|\.[^.]*$', "")
        Next

        ; Open the rightclick Menu. See decleration of $MenuButtonsArray above.
        Local $MenuSelect = _Metro_RightClickMenu($Form1, 200, $MenuButtonsArray)
;===================================================================================================
switch $MenuSelect
        case "0"
MsgBox($MB_SYSTEMMODAL, "CAMPO EM BRANCO!!!",$MenuButtonsArray[$menu],10)
EndSwitch

The script read a list of files into a folder...Convert then to array...I fill my menu with the names os the files ($MenuButtonsArray)

But the script uses metroGUI and when it arrives to the metroGUI return, I got back numbers... (1 to 10 lets supose) and I don't want to make a switch because I don't want to make case 0, case 1, case 3, and the list of files will increase, that way if I make a 10 options case, tomorrow could be 20...

Something like:

case $MenuSelect  is 0 (obviously some var result as 0)

do something about  $SomeVarThatAreTheFileNameSameAsBeforeTurnToMenuSelectAndIsTheFirstOption[$MenuSelect] & ".txt" (obviously some var bla bla bla [0] same as var above)

$menu select (var again) returns 3 and so on... (result 3)

My script search a folder, turn the files into a list (file list to array you must be familiar), and I need after choose his name on the list (Array again) , open or read him (read the named files I uploaded to array, I'll get his name again and put .txt) to fill another program or vars...(do this do that...)

I read my explanation again and I find understandable...Maybe because I'm more familiar to it...I could did a better explanation but maybe a lack of good will?... :(

Anyway...I think its better explained...Thanks...

Edited by edumanilha
typo
Link to comment
Share on other sites

Sorry... but still not sure that I follow you. You are filling the menu from an array, then you make a selection from the menu. Then what? You want to launch the file?

Perhaps you need to maintain two separate arrays, one modified for the menu and one unmodified so that you can act on the menu selection.

Link to comment
Share on other sites

11 hours ago, Danp2 said:

Sorry... but still not sure that I follow you. You are filling the menu from an array, then you make a selection from the menu. Then what? You want to launch the file?

Perhaps you need to maintain two separate arrays, one modified for the menu and one unmodified so that you can act on the menu selection.

Yes I need to launch the file, I still don't get into this part, maybe like I use today
 

$CMD = @ScriptDir & "\putty -ssh -pw PASSWORD USER@" & $Final & " -m " & @ScriptDir & "\Dados\Comandos\" & $Comando

Or maybe FileReadLine and pauses...Because with putty and -m I think its too fast...

I got this far:

I have the file folder, that will change with time:

image.png.4634e7ff53d8879ac79db4651b687f7b.png

The script read the files and create the menu :

image.png.7d58343af2f74298df80c32b321717de.png

But when I select the menu option, this part of the script of Metro template, turn my option into numbers:
 

Local $MenuSelect = _Metro_RightClickMenu($Form1, 200, $MenuButtonsArray)

First option in the menu will return me $MenuSelect  = 0, but I know $MenuButtonsArray[0] still have the file name, and I want  to call him, without a limited switch.

Dummy example:

Switch $MenuSelect  ( returns 0)
Case $MenuSelect (case 0)
$CMD = @ScriptDir & "\putty -ssh -pw PASSWORD USER@" & $Final & " -m " & @ScriptDir & "\Dados\Comandos\" & $MenuButtonsArray[$MenuSelect] &+.txt"(Call first file name)"
EndSwitch

Can you please exemplify your sugestion?

Thanks for you support!

Link to comment
Share on other sites

11 hours ago, Danp2 said:

Sorry... but still not sure that I follow you. You are filling the menu from an array, then you make a selection from the menu. Then what? You want to launch the file?

Perhaps you need to maintain two separate arrays, one modified for the menu and one unmodified so that you can act on the menu selection.

Man...Nevermind...The dummy example worked! LOL...Thanks for you time!

Now I can have as many files as I need without  recompile the executable...

Edited by edumanilha
more info
Link to comment
Share on other sites

4 minutes ago, Danp2 said:

Just ditch the Switch / Endswitch all together as it isn't needed. Use the value of $MenuSelect to retrieve the original filename from the array.

Better yet! Thanks! Now its time to develop the read line part, and send it to putty or plink, I still don't know! Probably I'll be back soon! 😂

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