Jump to content

Loop 1 then 2nd then 3rd


whitts
 Share

Recommended Posts

Below i have 3 cases in a row all are the same (when i press the save button) I want to exicute the first one until everything is added in the array and then move to the second until everyting in the array is added then to the third. At the moment the program is excuting the first thing in the array for the first case then the first thing in the array for the seocnd an dthen the third and then starts again with the second thing in the array.

Anyone any ideas?

Thanks

CODE
#include <GUIConstants.au3>

#include <Array.au3>

#include <File.au3>

Global $Saved[1];This will be an array of 2 elements, but _ArrayAdd will take care of

;making it bigger as you add data.

GUICreate("", 273, 192, 217, 152)

$Input1 = GUICtrlCreateInput("Input1", 12, 14, 245, 21)

$Input2 = GUICtrlCreateInput("Input2", 12, 47, 245, 21)

$Input3 = GUICtrlCreateInput("Input3", 12, 80, 245, 21)

$Save = GUICtrlCreateButton("Save to memory", 22, 130, 105, 45, $BS_DEFPUSHBUTTON)

$Write = GUICtrlCreateButton("Write to file", 142, 130, 105, 45, 0)

GUISetState(@SW_SHOW)

_ArrayAdd($Saved,'ECHO.^<package^>>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO.>>"yes.wsf"')

_ArrayAdd($Saved, '')

_ArrayAdd($Saved, 'ECHO.^<job id="vbs"^>>>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO.>>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO. ^<script language="VBScript"^>>>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO.set WshShell = WScript.CreateObject("WScript.Shell")>>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO.WScript.Sleep 3000>>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO.WshShell.SendKeys "Y">>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO.^</script^>>>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO.^</job^>>>"yes.wsf"')

_ArrayAdd($Saved, 'ECHO.^</package^>>>"yes.wsf"')

_ArrayAdd($Saved, '')

_ArrayAdd($Saved, 'ECHO.Windows Registry Editor Version 5.00>"printer.reg"')

_ArrayAdd($Saved, 'ECHO.>>"printer.reg"')

_ArrayAdd($Saved, '')

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $GUI_EVENT_CLOSE

Exit

Case $Save

_ArrayAdd($Saved,'ECHO.[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ports]>>"printer.reg"')

_ArrayAdd($Saved,'ECHO."\\\\' &GUICtrlRead($Input1) & "\\" &GUICtrlRead($Input2)& '"="">"printer.reg">>"printer.reg"')

_ArrayAdd($Saved, '')

GUICtrlSetData($Input1,"")

GUICtrlSetData($Input2,"")

GUICtrlSetData($Input3,"")

Case $Save

_ArrayAdd($Saved, 'regedit /S printer.reg')

_ArrayAdd($Saved, '')

_ArrayAdd($Saved, 'net stop spooler')

_ArrayAdd($Saved, 'net start spooler')

Case $Save

_ArrayAdd($Saved,'start wscript yes.wsf')

_ArrayAdd($Saved,'')

_ArrayAdd($Saved, 'rundll32 /s printui.dll, PrintUIEntry /if /q /b "' &GUICtrlRead($Input2)& '" /f "c:\8220\Adduni.inf" /r "\\' &GUICtrlRead($Input1) & '\' &GUICtrlRead($Input2)& '" /m "Brother MFC-8220" w')

_ArrayAdd($Saved,'')

GUICtrlSetData($Input1,"")

GUICtrlSetData($Input2,"")

GUICtrlSetData($Input3,"")

Case $Write

;~ _ArrayDisplay($Saved)

_FileWriteFromArray("MyFile.txt",$Saved)

EndSwitch

WEnd

Link to comment
Share on other sites

Below i have 3 cases in a row all are the same (when i press the save button) I want to exicute the first one until everything is added in the array and then move to the second until everyting in the array is added then to the third. At the moment the program is excuting the first thing in the array for the first case then the first thing in the array for the seocnd an dthen the third and then starts again with the second thing in the array.

You could track the execution of the 'Save' cases with a global variable:

Global $SaveCnt = 1 ; Save counter

; ...

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Save
            Switch $SaveCnt
                Case 1
                    
                    ; ...
                    
                    $SaveCnt += 1
                Case 2
                    
                    ; ...
                    
                    $SaveCnt += 1
                Case 3
                    
                    ; ...
                    
                    $SaveCnt = 1
            EndSwitch
        Case $Write
            
            ; ...
            
    EndSwitch
WEnd

<_<

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Psalty, it sounds to me like he wants the Switch/Case inside of a loop, whereas your solution requires three presses of the "Save" button.

Dim $intCount = 1
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Save
            Do
                Switch $intCount
                    Case 1
                        ; Add array
                    Case 2
                        ; Add array again
                    Case 3
                        ; Third time is charm
                    Case Else
                        ExitLoop
                EndSwitch
                $intCount += 1
            Until $intCount > 3
        Case $Write
            ; ...
    EndSwitch
WEnd

Mine just loops three times.

Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache

Link to comment
Share on other sites

Blue_Drache your solution works in the correct order for me but only allows one press of the save button. PsaltyDS works but seems to put things in the array in strange places...

Thanks to you both for your input..

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