Jump to content

Case statements with arrays? [RESOLVED]


Recommended Posts

I was wondering if it's possible to go through the full contents of an array with just a single case statement instead of having to hardcode something like $array[1] $array[2] etc. If so could anyone tell me how? Here's an example ripped from my project with a few things changed to keep it a bit of a secret ;).

$idMenuArray = GUICtrlCreateMenu("Array")
$files = _FileListToArray($dirpath)
For $n = 1 To UBound($files) - 1
    $idArray[$n] = GUICtrlCreateMenuItem(StringReplace($files[$n],".extension",""),$idMenuArray)
Next

...

Case For $n = $idArray[1] To $idArray[UBound($files) - 1]
MsgBox(0,"","Array index " & $n " was clicked")

This works but it just continually presents the messagebox instead of showing it once. What I need is to run through all of the possibilities, find which one was clicked, and (as an example) do something like

Run($files[$n])

and only do that once. Inside the file (and in the properties) I would have a url on the second or third line and I would like to navigate an open ie page to that location. I can do most of the latter I simply can't get it to run once as I need it to.

Edit: Also throwing out the same problem as soon as it loads fully, even before the menu item is clicked.

Edited by dbzfanatic
Link to comment
Share on other sites

I was wondering if it's possible to go through the full contents of an array with just a single case statement instead of having to hardcode something like $array[1] $array[2] etc. If so could anyone tell me how? Here's an example ripped from my project with a few things changed to keep it a bit of a secret ;).

$idMenuArray = GUICtrlCreateMenu("Array")
$files = _FileListToArray($dirpath)
For $n = 1 To UBound($files) - 1
    $idArray[$n] = GUICtrlCreateMenuItem(StringReplace($files[$n],".extension",""),$idMenuArray)
Next

...

Case For $n = $idArray[1] To $idArray[UBound($files) - 1]
MsgBox(0,"","Array index " & $n " was clicked")

This works but it just continually presents the messagebox instead of showing it once. What I need is to run through all of the possibilities, find which one was clicked, and (as an example) do something like

Run($files[$n])

and only do that once. Inside the file (and in the properties) I would have a url on the second or third line and I would like to navigate an open ie page to that location. I can do most of the latter I simply can't get it to run once as I need it to.

Edit: Also throwing out the same problem as soon as it loads fully, even before the menu item is clicked.

$idMenuArray = GUICtrlCreateMenu("Array")
$files = _FileListToArray($dirpath)
For $n = 1 To UBound($files) - 1
    $idArray[$n] = GUICtrlCreateMenuItem(StringReplace($files[$n], ".extension", ""), $idMenuArray)
Next

...
$Msg = GUIGetMsg()
Switch $Msg
    Case $idArray[1] To $idArray[UBound($idArray) - 1]
        Local $selected
        For $n = 1 To UBound($idArray) - 1
            If $idArray[$n] = $Msg Then
                $selected = $n
                ExitLoop
            EndIf
        Next
        
        MsgBox(0, "", "Array index " & $selected " was clicked")
EndSwitch
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

My code was 99% identical to yours and yet it didn't work, in fact it freezes the program in a sense. It causes it to continually check (I think) and the exit button does not work. Here's a direct unmodified cut from my script.

$idFavorites = GUICtrlCreateMenu("F&avorites")
GUICtrlCreateMenuItem("",$idFavorites)
$faves = _FileListToArray(@FavoritesDir,"*.url")
For $n = 1 To UBound($faves) - 1
    $idFaves[$n] = GUICtrlCreateMenuItem(StringReplace($faves[$n],".url",""),$idFavorites)
Next

...

        Case $idFaves[1] To $idFaves[UBound($faves) - 1]
            For $n = 1 To UBound($faves) - 1
                If $faves[$n] = $nMsg Then
                    MsgBox(0,"","");added to ensure the code is being executed (it is not)
                    $url = FileOpen($faves[$n],0)
                    $url = FileReadLine($url,2)
                    $url = StringReplace($url,"url=","")
                    ExitLoop
                EndIf
            Next
            _IENavigate($oIE,$url)

Yes I had built upon it since my first post.

Edit: Fixed it

Case $idFaves[1] To $idFaves[UBound($faves) - 1]
            For $n = 1 To UBound($faves) - 1
                If $idFaves[$n] = $nMsg Then
                    $url = FileOpen(@FavoritesDir & "\" & $faves[$n],0)
                    $url = FileReadLine($url,2)
                    $url = StringReplace($url,"url=","")
                    _IENavigate($oIE,$url)
                    GUICtrlSetData($txtAddressBar,$oIE.locationurl)
                    ExitLoop
                EndIf
            Next
Edited by dbzfanatic
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...