Sign in to follow this  
Followers 0
Vaeb

Script takes wrong Case!?!?

10 posts in this topic

#1 ·  Posted (edited)

Hello!

I've got this Problem:

When i check a checkbox i always get the msgbox with the title "1".

But when I click on $gui_check_3 there should appear the msgbox "3".

Func Check()
    GUISetState(@SW_HIDE, $Gui1)
    $Check = GUICreate ("Default","701", "641")
    Opt("GUICloseOnESC", 1)
    
    $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
            For $i = 1 To $linkname[0]
                $pr = StringInStr($linkname[$i], " ", 1)
                $prLen = StringLen($linkname[$i])
                $pr3 = $prLen - $pr
                $pr2 = StringTrimRight($linkname[$i], $pr3)
                $srv = StringInStr($linkname[$i], " ", 1, 1)
                $srv2 = StringTrimLeft($linkname[$i], $srv + 3)
                $srv3 = StringTrimRight($srv2, 4)
                Opt("GUICloseOnESC", 1)
                Dim $gui_check_[$linkname[0] + 1]
                $gui_check_[$i] = GUICtrlCreateCheckbox($pr2 & $srv3 ,10,-10 + $i*20,680,20)
        Next

        $buttoninst = GUICtrlCreateButton("Install", 135, 350)
            GUISetState()

                While 1
                            $Msg = GUIGetMsg()
                                Switch $Msg
                                    Case $GUI_EVENT_CLOSE
                                        Exit
                                    Case $buttoninst
                                        While 1
                                            $Msg = GUIGetMsg()
                                            Switch $Msg
                                                    Case BitAnd(GUICtrlRead($gui_check_1),$GUI_CHECKED) = $GUI_CHECKED
                                                        MsgBox (0, "1", "xD")
                                                        $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
                                                        $pr = StringInStr($linkname[1], " ", 1)
                                                        $prLen = StringLen($linkname[1])
                                                        $pr3 = $prLen - $pr
                                                        $pr2 = StringTrimRight($linkname[1], $pr3)
                                                        $srv = StringInStr($linkname[1], " ", 1, 1)
                                                        $srv2 = StringTrimLeft($linkname[1], $srv + 3)
                                                        $srv3 = StringTrimRight($srv2, 4)
                                                        RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2)
                                                        RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2 & "/y")
                                                        
                                                    Case BitAnd(GUICtrlRead($gui_check_2),$GUI_CHECKED) = $GUI_CHECKED
                                                        MsgBox (0, "2", "xD")
                                                        $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
                                                        $pr = StringInStr($linkname[2], " ", 1)
                                                        $prLen = StringLen($linkname[2])
                                                        $pr3 = $prLen - $pr
                                                        $pr2 = StringTrimRight($linkname[2], $pr3)
                                                        $srv = StringInStr($linkname[2], " ", 1, 1)
                                                        $srv2 = StringTrimLeft($linkname[2], $srv + 3)
                                                        $srv3 = StringTrimRight($srv2, 4)
                                                        RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2)
                                                        RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2 & "/y")
                                                        
                                                    Case BitAnd(GUICtrlRead($gui_check_3),$GUI_CHECKED) = $GUI_CHECKED
                                                        MsgBox (0, "3", "xD")
                                                        $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
                                                        $pr = StringInStr($linkname[3], " ", 1)
                                                        $prLen = StringLen($linkname[3])
                                                        $pr3 = $prLen - $pr
                                                        $pr2 = StringTrimRight($linkname[3], $pr3)
                                                        $srv = StringInStr($linkname[3], " ", 1, 1)
                                                        $srv2 = StringTrimLeft($linkname[3], $srv + 3)
                                                        $srv3 = StringTrimRight($srv2, 4)
                                                        RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2)
                                                        RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2 & "/y")
                                            EndSwitch
                                                    
                                                        Sleep (1000)
                                        WEnd
                                EndSwitch
                WEnd
            GUISetState(@SW_SHOW, $Check)
EndFunc

Can anyone help me please?

Greets

Vaeb

EDIT: I DID IT ANOTHER WAY - THX!

Edited by Vaeb

Share this post


Link to post
Share on other sites



Try replacing $gui_check_1 with $gui_check_[1] and other $gui_check_...-s too.

Share this post


Link to post
Share on other sites

oh my god... i think î'm goin crazy about that function i need...

Thank you poisonkiller... but it still doesn't work.

now it does nothing when i push the button... : (

Func Check()
    GUISetState(@SW_HIDE, $Gui1)
    $Check = GUICreate("Default", "701", "641")
    Opt("GUICloseOnESC", 1)
    $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
    For $i = 1 To $linkname[0]
        $pr = StringInStr($linkname[$i], " ", 1)
        $prLen = StringLen($linkname[$i])
        $pr3 = $prLen - $pr
        $pr2 = StringTrimRight($linkname[$i], $pr3)
        $srv = StringInStr($linkname[$i], " ", 1, 1)
        $srv2 = StringTrimLeft($linkname[$i], $srv + 3)
        $srv3 = StringTrimRight($srv2, 4)
        Opt("GUICloseOnESC", 1)
        Dim $gui_check_[$i + 1]
        $gui_check_[$i] = GUICtrlCreateCheckbox($pr2 & $srv3, 10, -10 + $i * 20, 680, 20)
        Dim $read[$i + 1]
        $read[$i] = GUICtrlRead($gui_check_[$i])
        $buttoninst = GUICtrlCreateButton("Install", 135, 350)
        GUISetState(@SW_SHOW, $Check)
    While 1 
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $buttoninst
                While 1
                    $Msg = GUIGetMsg()
                    Switch $Msg
                        Case BitAND($read[$i], $GUI_CHECKED) = $GUI_CHECKED
                            $pr = StringInStr($read[$i], " ", 1);abstand des strings
                            $prLen = StringLen($read[$i]);länge des strings
                            $pr3 = $prLen - $pr;abstand andere seite
                            $pr2 = StringTrimRight($read[$i], $pr3);server
                            $srv = StringInStr($read[$i], " ", 1);abstand des strings
                            $srv2 = StringTrimLeft($read[$i], $srv)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv2 & "\" & $pr2)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv2 & "\" & $pr2 & "/y")
                            MsgBox(0, "1", $srv3)

                        Case BitAND(GUICtrlRead($gui_check_[2]), $GUI_CHECKED) = $GUI_CHECKED
                            MsgBox(0, "2", "xD")
                            $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
                            $pr = StringInStr($linkname[2], " ", 1)
                            $prLen = StringLen($linkname[2])
                            $pr3 = $prLen - $pr
                            $pr2 = StringTrimRight($linkname[2], $pr3)
                            $srv = StringInStr($linkname[2], " ", 1, 1)
                            $srv2 = StringTrimLeft($linkname[2], $srv + 3)
                            $srv3 = StringTrimRight($srv2, 4)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2 & "/y")

                        Case BitAND(GUICtrlRead($gui_check_[3]), $GUI_CHECKED) = $GUI_CHECKED
                            MsgBox(0, "3", "xD")
                            $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
                            $pr = StringInStr($linkname[3], " ", 1)
                            $prLen = StringLen($linkname[3])
                            $pr3 = $prLen - $pr
                            $pr2 = StringTrimRight($linkname[3], $pr3)
                            $srv = StringInStr($linkname[3], " ", 1, 1)
                            $srv2 = StringTrimLeft($linkname[3], $srv + 3)
                            $srv3 = StringTrimRight($srv2, 4)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2 & "/y")

                        Case BitAND(GUICtrlRead($gui_check_[4]), $GUI_CHECKED) = $GUI_CHECKED
                            MsgBox(0, "4", "xD")
                            $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
                            $pr = StringInStr($linkname[4], " ", 1)
                            $prLen = StringLen($linkname[4])
                            $pr3 = $prLen - $pr
                            $pr2 = StringTrimRight($linkname[4], $pr3)
                            $srv = StringInStr($linkname[4], " ", 1, 1)
                            $srv2 = StringTrimLeft($linkname[4], $srv + 3)
                            $srv3 = StringTrimRight($srv2, 4)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2 & "/y")

                        Case BitAND(GUICtrlRead($gui_check_[5]), $GUI_CHECKED) = $GUI_CHECKED
                            MsgBox(0, "5", "xD")
                            $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
                            $pr = StringInStr($linkname[5], " ", 1)
                            $prLen = StringLen($linkname[5])
                            $pr3 = $prLen - $pr
                            $pr2 = StringTrimRight($linkname[5], $pr3)
                            $srv = StringInStr($linkname[5], " ", 1, 1)
                            $srv2 = StringTrimLeft($linkname[5], $srv + 3)
                            $srv3 = StringTrimRight($srv2, 4)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv3 & "\" & $pr2 & "/y")
                    EndSwitch
                    Sleep(100)
                WEnd
        EndSwitch
        WEnd
    Next
EndFunc   ;==>Check

why the hell doesn't it work?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

You are using Swicth then testing a condition but you should use Select.

Also you have used the variable $i in places where I think you shouldn't, ie outside of the For/Next loop

EDIT: strikeout second line because I was wrong.

Edited by martin

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.

Share this post


Link to post
Share on other sites

Try if this works, I can't test it right now...

Func Check()
    GUISetState(@SW_HIDE, $Gui1)
    $Check = GUICreate("Default", 701, 641)
    Opt("GUICloseOnESC", 1)
    $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
    Dim $gui_check_[$linkname[0] + 1]
    Dim $read[$linkname[0] + 1]
    For $i = 1 To $linkname[0]
        $pr = StringInStr($linkname[$i], " ", 1)
        $prLen = StringLen($linkname[$i])
        $pr3 = $prLen - $pr
        $pr2 = StringTrimRight($linkname[$i], $pr3)
        $srv = StringInStr($linkname[$i], " ", 1, 1)
        $srv2 = StringTrimLeft($linkname[$i], $srv + 3)
        $srv3 = StringTrimRight($srv2, 4)
        $gui_check_[$i] = GUICtrlCreateCheckbox($pr2 & $srv3, 10, -10 + $i * 20, 680, 20)
        $read[$i] = GUICtrlRead($gui_check_[$i])
        Next
        $buttoninst = GUICtrlCreateButton("Install", 135, 350)
        GUISetState(@SW_SHOW, $Check)
    While 1 
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $buttoninst
                For $i = 1 to $linkname[0]
                    Switch $i
                        Case GUICtrlRead($gui_check_[$i]) = $GUI_CHECKED
                            $pr = StringInStr($read[$i], " ", 1);abstand des strings
                            $prLen = StringLen($read[$i]);länge des strings
                            $pr3 = $prLen - $pr;abstand andere seite
                            $pr2 = StringTrimRight($read[$i], $pr3);server
                            $srv = StringInStr($read[$i], " ", 1);abstand des strings
                            $srv2 = StringTrimLeft($read[$i], $srv)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv2 & "\" & $pr2)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv2 & "\" & $pr2 & "/y")
                            MsgBox(0, $i, $srv3)
                    EndSwitch
                    Next
        EndSwitch
        WEnd
EndFunc   ;==>Check

Share this post


Link to post
Share on other sites

Try if this works, I can't test it right now...

Func Check()
    GUISetState(@SW_HIDE, $Gui1)
    $Check = GUICreate("Default", 701, 641)
    Opt("GUICloseOnESC", 1)
    $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
    Dim $gui_check_[$linkname[0] + 1]
    Dim $read[$linkname[0] + 1]
    For $i = 1 To $linkname[0]
        $pr = StringInStr($linkname[$i], " ", 1)
        $prLen = StringLen($linkname[$i])
        $pr3 = $prLen - $pr
        $pr2 = StringTrimRight($linkname[$i], $pr3)
        $srv = StringInStr($linkname[$i], " ", 1, 1)
        $srv2 = StringTrimLeft($linkname[$i], $srv + 3)
        $srv3 = StringTrimRight($srv2, 4)
        $gui_check_[$i] = GUICtrlCreateCheckbox($pr2 & $srv3, 10, -10 + $i * 20, 680, 20)
        $read[$i] = GUICtrlRead($gui_check_[$i])
        Next
        $buttoninst = GUICtrlCreateButton("Install", 135, 350)
        GUISetState(@SW_SHOW, $Check)
    While 1 
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $buttoninst
                For $i = 1 to $linkname[0]
                    Switch $i
                        Case GUICtrlRead($gui_check_[$i]) = $GUI_CHECKED
                            $pr = StringInStr($read[$i], " ", 1);abstand des strings
                            $prLen = StringLen($read[$i]);länge des strings
                            $pr3 = $prLen - $pr;abstand andere seite
                            $pr2 = StringTrimRight($read[$i], $pr3);server
                            $srv = StringInStr($read[$i], " ", 1);abstand des strings
                            $srv2 = StringTrimLeft($read[$i], $srv)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv2 & "\" & $pr2)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv2 & "\" & $pr2 & "/y")
                            MsgBox(0, $i, $srv3)
                    EndSwitch
                    Next
        EndSwitch
        WEnd
EndFunc   ;==>Check

Did you see the post before yours?

This won't work

Switch $i
                        Case GUICtrlRead($gui_check_[$i]) = $GUI_CHECKED

; it is equivalent to
  Switch $i
                        Case True;if checked

;it is equivalent to 
  Switch $i
                        Case False;if not checked

What's needed is just an if then I think.

Func Check()
    GUISetState(@SW_HIDE, $Gui1)
    $Check = GUICreate("Default", 701, 641)
    Opt("GUICloseOnESC", 1)
    $linkname = _FileListToArray("\\srv\root\Group\Public\Printers\zh\" & $n & "Obergeschoss\" & $ort, '*.lnk', 1)
    Dim $gui_check_[$linkname[0] + 1]
    Dim $read[$linkname[0] + 1]
    For $i = 1 To $linkname[0]
        $pr = StringInStr($linkname[$i], " ", 1)
        $prLen = StringLen($linkname[$i])
        $pr3 = $prLen - $pr
        $pr2 = StringTrimRight($linkname[$i], $pr3)
        $srv = StringInStr($linkname[$i], " ", 1, 1)
        $srv2 = StringTrimLeft($linkname[$i], $srv + 3)
        $srv3 = StringTrimRight($srv2, 4)
        $gui_check_[$i] = GUICtrlCreateCheckbox($pr2 & $srv3, 10, -10 + $i * 20, 680, 20)
        $read[$i] = GUICtrlRead($gui_check_[$i])
    Next
    
        $buttoninst = GUICtrlCreateButton("Install", 135, 350)
        GUISetState(@SW_SHOW, $Check)
    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case $GUI_EVENT_CLOSE
                Exit
            Case $buttoninst
                For $i = 1 to $linkname[0]
                    If GUICtrlRead($gui_check_[$i]) = $GUI_CHECKED
                            $pr = StringInStr($read[$i], " ", 1);abstand des strings
                            $prLen = StringLen($read[$i]);länge des strings
                            $pr3 = $prLen - $pr;abstand andere seite
                            $pr2 = StringTrimRight($read[$i], $pr3);server
                            $srv = StringInStr($read[$i], " ", 1);abstand des strings
                            $srv2 = StringTrimLeft($read[$i], $srv)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv2 & "\" & $pr2)
                            RunWait("rundll32 printui.dll,PrintUIEntry /in /n \\" & $srv2 & "\" & $pr2 & "/y")
                            MsgBox(0, $i, $srv3)
                   
                    Next
        EndSwitch
        WEnd
EndFunc  ;==>Check

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.

Share this post


Link to post
Share on other sites

Actually, I tested my code, and everything worked as I expected. Btw, I did use Switch $i and nothing went wrong... Maybe using If...EndIf saves some lines, but I used Switch...EndSwitch, so if in the future he wants to add something, it's easier.

Share this post


Link to post
Share on other sites

Actually, I tested my code, and everything worked as I expected. Btw, I did use Switch $i and nothing went wrong... Maybe using If...EndIf saves some lines, but I used Switch...EndSwitch, so if in the future he wants to add something, it's easier.

Yes I shouldn't have said it won't work because in your example where you only have one Case I'm sure it does. But you can't have more than two Case statements if you test for a condition using Switch. Comparing a number to a condition does work. However the logic is a bit strange because your are looking for Case $i which is a number then putting a condition to test, so it the same as writing

For $i = 1 to $linkname[0]
                    Switch True
                        Case GUICtrlRead($gui_check_[$i]) = $GUI_CHECKED

You are limited to 2 Cases which can be either true of false, so the option of being able to add something in the future is limited to one extra case which must be false. If you use Select then you can have any number of conditional checks.


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.

Share this post


Link to post
Share on other sites

Thanks a lot to both for your great help.

I used your script, poisonkiller.

$gui_check_[$i] is 8201 when i click on Checkbox 1.

$gui_check_[$i] is 8202 when i click on Checkbox 2.

$gui_check_[$i] is 8203 when i click on Checkbox 3...

So I guess thats the indentifier. (820X)

There is one problem:

I would like to get the text of the Checkbox returned.

When i use GUICtrlRead ($gui_check_[$i]) it returns 1.

How can i get the Text of the Checkbox?

Greets

Vaeb

Share this post


Link to post
Share on other sites

@martin: Ah, whatever, the only important thing is, that it works. If Vaeb wants, he can use If...EndIf.

@Vaeb: I don't really know, how to return text of a checkbox (if it's even possible), but one workaround is to add

Dim $gui_check_text[$linkname[0] + 1]oÝ÷ ÚéÝz¶®¶­sdFÒb33c¶wVö6V6µõ²b33c¶Ææ¶æÖU³Ò²ÐoÝ÷ ٩ݶ§jëh×6$gui_check_text[$i] = $pr2 & $srv3

Share this post


Link to post
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
Sign in to follow this  
Followers 0