Jump to content

Select ... Case ... EndSelect problem


RACooper
 Share

Recommended Posts

I have the following Select block in a script. Expected behavior would be to test the case, and if not TRUE then move to the next case. However, it seems to be ignoring the expression, and processing every case. If I take out the ContinueCase statements, only the first match gets processed. Can someone tell me what I'm doing wrong here?

I'm attaching the complete code if that will help.

; runinstall($label, $location, $source, $filename $instargs, $process, $check)
    Select
        Case GUICtrlRead($AcroRead) == 1; Acrobat Reader
            runinstall("Acrobat Reader", "web", "http://cis-web1/files/acroread811.exe", "acroread.exe", "", "acroread", "was not found")
            ContinueCase
        Case GUICtrlRead($JRE) == 1; Java Runtime
            runinstall("Java Runtime", "web", "http://cis-web1/files/Java6u3.exe", "jre.exe", "", "jre", "was not found")
            ContinueCase
        Case GUICtrlRead($Flash) == 1; Adobe Flash
            runinstall("Flash Player", "web", "http://cis-web1/files/flash_activex.exe", "flash.exe", "/s", "flash", "was not found")
            ContinueCase
        Case GUICtrlRead($iTunes) == 1; Apple iTunes
            runinstall("iTunes", "web", "http://cis-web1/files/iTunes75Setup.exe", "itunes.exe", "/quiet", "itunes", "ituneshelper")
            ContinueCase
        Case GUICtrlRead($Quicktime) == 1; Apple Quicktime
            runinstall("QuickTime", "web", "http://cis-web1/files/QuickTime73.exe", "quicktime.exe", "/quiet", "quicktime", "was not found")
            ContinueCase
        Case GUICtrlRead($Firefox) == 1; Mozilla Firefox
            runinstall("Firefox", "web", "http://cis-web1/files/Firefox_2.0.0.9.exe", "firefox.exe", "-ms", "firefox", "was not found")
            ContinueCase
        Case GUICtrlRead($NSCPP) == 1; Nagios NSClient++
            runinstall("NSClient++", "web", "http://cis-web1/files/NSCPP-OCSS.exe", "nscpp.exe", "", "nscpp", "was not found")
            ContinueCase
        Case GUICtrlRead($SAV) == 1; Symantec Antivirus client - always put this LAST becuase it may reboot the remote PC!
            runinstall("SAV Client", "unc", "", '"\\cis-sav\savclients$\av_only\setup.exe"', "", "setup", "was not found")
    EndSelect

adminpush2.au3

Link to comment
Share on other sites

I have the following Select block in a script. Expected behavior would be to test the case, and if not TRUE then move to the next case. However, it seems to be ignoring the expression, and processing every case. If I take out the ContinueCase statements, only the first match gets processed. Can someone tell me what I'm doing wrong here?

I'm attaching the complete code if that will help.

; runinstall($label, $location, $source, $filename $instargs, $process, $check)
    Select
        Case GUICtrlRead($AcroRead) == 1; Acrobat Reader
            runinstall("Acrobat Reader", "web", "http://cis-web1/files/acroread811.exe", "acroread.exe", "", "acroread", "was not found")
            ContinueCase
        Case GUICtrlRead($JRE) == 1; Java Runtime
            runinstall("Java Runtime", "web", "http://cis-web1/files/Java6u3.exe", "jre.exe", "", "jre", "was not found")
            ContinueCase
        Case GUICtrlRead($Flash) == 1; Adobe Flash
            runinstall("Flash Player", "web", "http://cis-web1/files/flash_activex.exe", "flash.exe", "/s", "flash", "was not found")
            ContinueCase
        Case GUICtrlRead($iTunes) == 1; Apple iTunes
            runinstall("iTunes", "web", "http://cis-web1/files/iTunes75Setup.exe", "itunes.exe", "/quiet", "itunes", "ituneshelper")
            ContinueCase
        Case GUICtrlRead($Quicktime) == 1; Apple Quicktime
            runinstall("QuickTime", "web", "http://cis-web1/files/QuickTime73.exe", "quicktime.exe", "/quiet", "quicktime", "was not found")
            ContinueCase
        Case GUICtrlRead($Firefox) == 1; Mozilla Firefox
            runinstall("Firefox", "web", "http://cis-web1/files/Firefox_2.0.0.9.exe", "firefox.exe", "-ms", "firefox", "was not found")
            ContinueCase
        Case GUICtrlRead($NSCPP) == 1; Nagios NSClient++
            runinstall("NSClient++", "web", "http://cis-web1/files/NSCPP-OCSS.exe", "nscpp.exe", "", "nscpp", "was not found")
            ContinueCase
        Case GUICtrlRead($SAV) == 1; Symantec Antivirus client - always put this LAST becuase it may reboot the remote PC!
            runinstall("SAV Client", "unc", "", '"\\cis-sav\savclients$\av_only\setup.exe"', "", "setup", "was not found")
    EndSelect

Try changing your Case checks to:

Case GUICtrlRead($var) = $GUI_CHECKED

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Try changing your Case checks to:

Case GUICtrlRead($var) = $GUI_CHECKED

Tried your suggestion....same effect. It continues into the next CASE even though it does not resolve TRUE. I may have to rewrite this as a bunch of If...EndIf sequences again....

Link to comment
Share on other sites

The working synthax is:

Case BitAND(GUICtrlRead($AcroRead), $GUI_CHECKED)

be aware of the following behaviour (from Help - Select)

Parameters

Case <expression> If the expression is true the following statements up to the next Case or EndSelect statement are executed. If more than one of the Case statements are true, only the first one is executed.

I guess you will have to change your Select with If's because they concern different software and once one case if found true you will quit the loop without executing other case statement.

EDIT: sorry - haven't noticed ContinueCase :P

Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

arrays are your friend

Dim $aSoft[9], $i ; change $aSoft array size if adding more programs to install

; replace existing checkbox list
;---- Installation CheckBox Array ---------------------------------------------
$aSoft[1] = GUICtrlCreateCheckbox("Acrobat Reader", 30, 170, 95, 20)
$aSoft[2] = GUICtrlCreateCheckbox("Firefox 2", 30, 200, 90, 20)
$aSoft[3] = GUICtrlCreateCheckbox("Quicktime", 30, 230, 90, 20)
$aSoft[4] = GUICtrlCreateCheckbox("iTunes", 30, 260, 90, 20)

$aSoft[5] = GUICtrlCreateCheckbox("Java Runtime", 190, 170, 90, 20)
$aSoft[6] = GUICtrlCreateCheckbox("Adobe Flash", 190, 200, 90, 20)
$aSoft[7] = GUICtrlCreateCheckbox("Symantec Antivirus", 190, 230, 110, 20)
$aSoft[8] = GUICtrlCreateCheckbox("Nagios Client", 190, 260, 110, 20)
;$aSoft[9]  = GuiCtrlCreateCheckbox("UltraVNC", 190, 260, 90, 20) ; change  $aSoft[9] to  $aSoft[10] if uncommented
$aSoft[0] = UBound($aSoft) - 1 ; add array element count to first element
;------------------------------------------------------------------------------

; replace existing Select/Endselect structure in Function PushInstall()
For $i = 1 To $aSoft[0] Step 1
    Switch GUICtrlRead($aSoft[$i])
        Case $GUI_CHECKED
            Switch $aSoft[$i]   ; runinstall($label, $location, $source, $filename, $instargs, $process, $check)
                Case $aSoft[1]  ; Acrobat Reader
                    runinstall("Acrobat Reader", "web", "http://cis-web1/files/acroread811.exe", "acroread.exe", "", "acroread", "was not found")
                Case $aSoft[2]  ; Java Runtime
                    runinstall("Java Runtime", "web", "http://cis-web1/files/Java6u3.exe", "jre.exe", "", "jre", "was not found")
                Case $aSoft[3]  ; Adobe Flash
                    runinstall("Flash Player", "web", "http://cis-web1/files/flash_activex.exe", "flash.exe", "/s", "flash", "was not found")
                Case $aSoft[4]  ; Apple iTunes
                    runinstall("iTunes", "web", "http://cis-web1/files/iTunes75Setup.exe", "itsetup.exe", "/quiet", "itsetup", "was not found")
                Case $aSoft[5]  ; Apple Quicktime
                    runinstall("QuickTime", "web", "http://cis-web1/files/QuickTime73.exe", "quicktime.exe", "/quiet", "quicktime", "was not found")
                Case $aSoft[6]  ; Mozilla Firefox
                    runinstall("Firefox", "web", "http://cis-web1/files/Firefox_2.0.0.9.exe", "firefox.exe", "-ms", "firefox", "was not found")
                Case $aSoft[7]  ; Nagios NSClient++
                    runinstall("NSClient++", "web", "http://cis-web1/files/NSCPP-OCSS.exe", "nscpp.exe", "", "nscpp", "was not found")
                Case $aSoft[8]  ; Symantec Antivirus client - always put this LAST becuase it may reboot the remote PC!
                    runinstall("SAV Client", "unc", "", '"\\cis-sav\savclients$\av_only\setup.exe"', "", "setup", "was not found")
            EndSwitch
    EndSwitch
Next

I see fascists...

Link to comment
Share on other sites

Well, a combination of the two helped!

Just FYI, the final working code...

For $i = 1 To $aSoft[0] Step 1
        If BitAND(GUICtrlRead($aSoft[$i]), $GUI_CHECKED) Then
            Switch $i   ; runinstall($label, $location, $source, $filename, $instargs, $process, $check)
                Case 1  ; Acrobat Reader
                    runinstall("Acrobat Reader", "web", "http://cis-web1/files/acroread811.exe", "acroread.exe", "", "acroread", "was not found")
                Case 2  ; Java Runtime
                    runinstall("Java Runtime", "web", "http://cis-web1/files/Java6u3.exe", "jre.exe", "", "jre", "was not found")
                Case 3  ; Adobe Flash
                    runinstall("Flash Player", "web", "http://cis-web1/files/flash_activex.exe", "flash.exe", "/s", "flash", "was not found")
                Case 4  ; Apple iTunes
                    runinstall("iTunes", "web", "http://cis-web1/files/iTunes75Setup.exe", "itsetup.exe", "/quiet", "itsetup", "was not found")
                Case 5  ; Apple Quicktime
                    runinstall("QuickTime", "web", "http://cis-web1/files/QuickTime73.exe", "quicktime.exe", "/quiet", "quicktime", "was not found")
                Case 6  ; Mozilla Firefox
                    runinstall("Firefox", "web", "http://cis-web1/files/Firefox_2.0.0.9.exe", "firefox.exe", "-ms", "firefox", "was not found")
                Case 7  ; Nagios NSClient++
                    runinstall("NSClient++", "web", "http://cis-web1/files/NSCPP-OCSS.exe", "nscpp.exe", "", "nscpp", "was not found")
                Case 8  ; Symantec Antivirus client - always put this LAST becuase it may reboot the remote PC!
                    runinstall("SAV Client", "unc", '\\cis-sav\savclients$\av_only\setup.exe', "savsetup.exe", "", "savsetup", "was not found")
            EndSwitch
        EndIf
    NextoÝ÷ ٩ݶP!Èb³«zÊ&zíêk¡¹^¬jëh×6$aSoft[1] = GUICtrlCreateCheckbox("Acrobat Reader", 30, 170, 95, 20)
$aSoft[6] = GUICtrlCreateCheckbox("Firefox 2", 30, 200, 90, 20)
$aSoft[5] = GUICtrlCreateCheckbox("Quicktime", 30, 230, 90, 20)
$aSoft[4] = GUICtrlCreateCheckbox("iTunes", 30, 260, 90, 20)

$aSoft[2] = GUICtrlCreateCheckbox("Java Runtime", 190, 170, 90, 20)
$aSoft[3] = GUICtrlCreateCheckbox("Adobe Flash", 190, 200, 90, 20)
$aSoft[8] = GUICtrlCreateCheckbox("Symantec Antivirus", 190, 230, 110, 20)
$aSoft[7] = GUICtrlCreateCheckbox("Nagios Client", 190, 260, 110, 20)

;$aSoft[9]  = GuiCtrlCreateCheckbox("UltraVNC", 190, 260, 90, 20) ; change  $aSoft[9] to  $aSoft[10] if uncommented
$aSoft[0] = UBound($aSoft) - 1 ; add array element count to first element

In case your can't tell from that, my ordering of elements was causing some of the confusion (since the order in the GUI was not the same as the order being processed).

Thanks to enaiman and rover -- it's been sorted!

Edited by RACooper
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...