Jump to content
Sign in to follow this  
Xeroskill

I am new to loops and need help

Recommended Posts

Xeroskill

I am very new to to auto it, and I ran into a small snag while creating back buttons between windows opening. I want to do a While loop that goes through another while loop on both sides of the loop. If that makes any sense. Let me give an example:

*While Loop A starts*

(loop a)Window 1 opens,

(loop a)User clicks next button.

(loop a)Window 1 closes,

*While Loop B starts*

(loop a & b)Window 2 opens

*Window 2 has 2 buttons a 'Next' button and a 'Back' button.*

*Back button closes window 2, then it hit ends the end of the 'While Loop A' to go back to the 1st window where loop a started.*

*Next button closes window 2, and completes the condition set in loop A*

(loop a & :) User clicks next button

(loop ;) Window 2 closes

(loop ;) Window 3 opens.

*Window 3 also has 2 buttons a 'Next' button and a 'Back' button.*

*Back button closes window 3, then it hit ends the end of the 'While Loop B' to go back to the 2nd window where loop b started.*

*Next button closes window 2, and completes the condition set in loop B*

How can i make this work? or is there a better way to go about this? (if there was a goto line command, that would be ideal, but i believe they took that out of autoit)

Thanks in advanced.

Dave

(if you want to see my actual code without loop b added, it is pretty ugly i know, but here)

; Enables GUI
#include <GDIPlus.au3>
#include <GuiConstantsEx.au3>
Opt("MustDeclareVars", 1)
;
; AutoIt Version: 3.0
; Language:    English
; Platform:    Win9x/NT
; Author:        Jonathan Bennett (jon@hiddensoft.com)
;
; Script Function:
;   Demo of using functions
;

; Prompt the user to attach the usb bluetooth device -
Local $bLoop = 1
While $bLoop = 1
   Local $usbattached = MsgBox(35, "Intermec Scanner Setup", "Is the Bluetooth Adapter attached to the workstation?")
   If $usbattached = 2 Then
   Exit
   ElseIf $usbattached = 7 Then
   Local $attached = MsgBox(1, "Intermec Scanner Setup", "Please attach the Bluetooth Adapater then click OK")
   If $attached = 2 Then
   Exit
   Else
   $bLoop = 2
   EndIf
   EndIf
   $bloop = $bLoop - 1
WEnd

;This section inputs the GUI for the first barcode
;
;
Global $Firstloop
$Firstloop = 2
While $Firstloop <> 1
Global $hGUIOne, $hImageOne, $hGraphicOne
; Create GUI
$hGUIOne = GUICreate("Intermec Scanner Setup", 250, 250)
GUISetState()
; Load PNG image
_GDIPlus_StartUp()
$hImageOne   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\SF51.jpg")
; Draw PNG image
$hGraphicOne = _GDIPlus_GraphicsCreateFromHWND($hGUIOne)
_GDIPlus_GraphicsDrawImage($hGraphicOne, $hImageOne, 34, 0)
;Next Button
Local $nextbuttonone
$nextbuttonone = GUICtrlCreateButton("Next", 90, 220, 70, 20)
;text box containing the first step in setting up the scanner
Local $labelone
$labelone = GUICtrlCreateLabel("Scan the barcode above.  An audible alert will confirm a successful scan.  Click 'Next' once completed", 20, 145, 230, 50)
; Loop of menu items
Local $separator1, $msgone
   While 1
  $msgone = GUIGetMsg()
  Select
   Case $msgone = $GUI_EVENT_CLOSE
      _GDIPlus_GraphicsDispose($hGraphicOne)
      _GDIPlus_ImageDispose($hImageOne)
      _GDIPlus_ShutDown()
    Exit
   Case $msgone = $nextbuttonone
      ExitLoop
  
   Case $msgone = $GUI_EVENT_MOUSEMOVE
      $hGraphicone = _GDIPlus_GraphicsCreateFromHWND($hGUIone)
      _GDIPlus_GraphicsDrawImage($hGraphicone, $hImageone, 34, 0)
  EndSelect
WEnd
; Loop until user exits

GUIDelete()
; NEXT UI
;
;
Global $secondloop
$secondloop = 2

Global $hGUItwo, $hImagetwo, $hGraphictwo
; Create GUI
$hGUItwo = GUICreate("Intermec Scanner Setup", 710, 250)
GUISetState()
; Load PNG image
_GDIPlus_StartUp()
$hImagetwo   = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\Bluetooth.jpg")
; Draw PNG image
$hGraphictwo = _GDIPlus_GraphicsCreateFromHWND($hGUItwo)
_GDIPlus_GraphicsDrawImage($hGraphictwo, $hImagetwo, 1, 0)
; Declares Variables
Global $steptwo, $backbuttontwo, $Helpbuttontwo, $labeltwo
;Next Button
$steptwo = GUICtrlCreateButton("Next", 310, 220, 70, 20)
;Back Button
$backbuttontwo = GUICtrlCreateButton("Back", 230, 220, 70, 20)
;Help Button
$Helpbuttontwo = GUICtrlCreateButton("Help", 390, 220, 70, 20)
;text box containing the first step in setting up the scanner
$labeltwo = GUICtrlCreateLabel("Scan the barcode above.  An audible alert will confirm a successful scan.  Click 'Next' once completed", 120, 165, 670, 35)
;
;Do
;Until GUIGetMsg() = $GUI_EVENT_CLOSE
;Loop of menu items
Global $test
$test = 2
   While $test <> 1
   Global $msg = GUIGetMSG()
  Switch $msg
   Case $GUI_EVENT_CLOSE
      _GDIPlus_GraphicsDispose($hGraphictwo)
      _GDIPlus_ImageDispose($hImagetwo)
      _GDIPlus_ShutDown()
      Exit
   Case $steptwo
      $firstloop = 1
      ExitLoop
  
   Case $backbuttontwo
      _GDIPlus_GraphicsDispose($hGraphictwo)
      _GDIPlus_ImageDispose($hImagetwo)
      _GDIPlus_ShutDown()
      GUIDelete()
      ExitLoop
     
   Case $Helpbuttontwo
      MsgBox(0, "Help", "Try to scan the barcode from further away")
      $hGraphictwo = _GDIPlus_GraphicsCreateFromHWND($hGUItwo)
      _GDIPlus_GraphicsDrawImage($hGraphictwo, $hImagetwo, 1, 0)
  
   Case $GUI_EVENT_MOUSEMOVE
      $hGraphictwo = _GDIPlus_GraphicsCreateFromHWND($hGUItwo)
      _GDIPlus_GraphicsDrawImage($hGraphictwo, $hImagetwo, 1, 0)
     
   EndSwitch
  
 
WEnd
; Loop until user exits
;
WEnd
GUIDelete()
;next window
;
;
;
Global $hGUIthree
; Create GUI
$hGUIthree = GUICreate("Intermec Scanner Setup", 710, 250)
GUISetState()
; Declares Variables
Global $stepthree, $backbuttonthree, $labelthree
;Next Button
$stepthree = GUICtrlCreateButton("Continue", 310, 220, 70, 20)
;Back Button
$backbuttonthree = GUICtrlCreateButton("Back", 230, 220, 70, 20)
;text box containing the first step in setting up the scanner
$labelthree = GUICtrlCreateLabel("Click Continue to run the Automated Intermec Installation Tool", 120, 165, 670, 35)
;
;Do
;Until GUIGetMsg() = $GUI_EVENT_CLOSE
;Loop of menu items
Global $testthree
$testthree = 2
   While $testthree <> 1
   Global $msgthree = GUIGetMSG()
  Switch $msgthree
   Case $GUI_EVENT_CLOSE
       _GDIPlus_ShutDown()
      Exit
   Case $stepthree
      $secondloop = 1
      ExitLoop
  
   Case $backbuttonthree
      _GDIPlus_ShutDown()
      GUIDelete()
      ExitLoop
        
   EndSwitch
WEnd
;Back button triggers this While

MsgBox(0, "Exit", "Exiting Properly")
;Exits at end of script  
; Clean up resources
_GDIPlus_GraphicsDispose($hGraphicOne)
_GDIPlus_ImageDispose($hImageOne)
_GDIPlus_GraphicsDispose($hGraphictwo)
_GDIPlus_ImageDispose($hImagetwo)
_GDIPlus_Shutdown()
Exit

Share this post


Link to post
Share on other sites
JLogan3o13

Hi, XeroSkill. If I read your post correctly you want to be able to move back and forth through several different screens in a GUI? Attached is a script I wrote for a User State Migration app that does this. It may provide you with a better way to accomplish this.


√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post


Link to post
Share on other sites
Xeroskill

Thanks, I was able to get it to work using the GUISetState(@SW_Hide) command from your example. Thanks a lot.

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  

×