Jump to content

How To ReStart The Script


 Share

Recommended Posts

Hi there

first sorry for my english

I want to know how could I reset the scripts with click on button3 .. ?!

#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <Array.au3>
#include <Excel.au3>
 
Global $NameAndFamily
 
input()
 
Func main()
Dim $i = 1 , $j = 0, $k = 1
Dim $begin = TimerInit()
Local $answerArray[41]
$answerArray[0] = "Answer"
Local $timeArray[41]
$timeArray[0] = "Time"
Local $testAnswerArray[41][2]
 
#Region Main GUI
$Form1 = GUICreate("Sym. Test", 846, 530, 515, 205)
$Pic1 = GUICtrlCreatePic("photo\1n.jpg", 24, 56, 374, 410)
$Pic2 = GUICtrlCreatePic("photo\1n.jpg", 448, 56, 374, 410)
$Button1 = GUICtrlCreateButton("Show Result", 480, 488, 105, 25)
$Button2 = GUICtrlCreateButton("Export To Excel", 600, 488, 105, 25)
$Button3 = GUICtrlCreateButton("Start New Test", 720, 488, 105, 25)
_GUICtrlButton_Enable($Button1, False)
_GUICtrlButton_Enable($Button2, False)
GUISetState(@SW_SHOW)
#EndRegion
 
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Pic1
   If $i < 5 Then
    $dif = TimerDiff($begin)
    ConsoleWrite($i & " = Normal, Time = " & $dif & @CRLF)
    $answerArray[$i] = 1
    $timeArray[$i] = $dif
    $i+=1
    GUICtrlSetImage($Pic1, "photo\" & $i & "n.jpg")
    GUICtrlSetImage($Pic2, "photo\" & $i & "s.jpg")
    $begin = TimerInit()
   ElseIf $i = 5 Then
    $dif = TimerDiff($begin)
    ConsoleWrite($i & " = Normal, Time = " & $dif & @CRLF)
    $answerArray[$i] = 1
    $timeArray[$i] = $dif
    $i+=1
    _GUICtrlButton_Enable($Button1, True)
    _GUICtrlButton_Enable($Button2, True)
   EndIf
  Case $Pic2
   If $i < 5 Then
    $dif = TimerDiff($begin)
    ConsoleWrite($i & " = Symmetry, Time = " & $dif & @CRLF)
    $answerArray[$i] = 2
    $timeArray[$i] = $dif
    $i+=1
    GUICtrlSetImage($Pic1, "photo\" & $i & "n.jpg")
    GUICtrlSetImage($Pic2, "photo\" & $i & "s.jpg")
    $begin = TimerInit()
   ElseIf $i = 5 Then
    $dif = TimerDiff($begin)
    ConsoleWrite($i & " = Normal, Time = " & $dif & @CRLF)
    $answerArray[$i] = 1
    $timeArray[$i] = $dif
    $i+=1
    _GUICtrlButton_Enable($Button1, True)
    _GUICtrlButton_Enable($Button2, True)
   EndIf
  
  Case $Button1
   For $j = 0 To 40 Step 1
    $testAnswerArray[$j][0] = $answerArray[$j]
    $testAnswerArray[$j][1] = $timeArray[$j]
   Next
   _ArrayDisplay($testAnswerArray)
  Case $Button2
   $oExcel = _ExcelBookNew()
   _ExcelWriteArray ($oExcel, 1, 1, $answerArray, 1)
   _ExcelWriteArray ($oExcel, 1, 2, $timeArray, 1)
   _ExcelBookSaveAs($oExcel, @ScriptDir &"\results\" & $NameAndFamily & ".xls", "xls", 0, 1)
   _ExcelBookClose($oExcel)
  
  Case $Button3
   Exit
EndSwitch
WEnd
 
EndFunc
 
Func input()
#Region InPut GUI
$Form2 = GUICreate("Input Name And Family", 236, 112, 780, 380)
$Input1 = GUICtrlCreateInput("", 72, 16, 145, 21)
$Input2 = GUICtrlCreateInput("", 72, 48, 145, 21)
$Label1 = GUICtrlCreateLabel("Name", 16, 16, 37, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS")
$Label2 = GUICtrlCreateLabel("Family", 16, 48, 43, 22)
GUICtrlSetFont(-1, 10, 400, 0, "Comic Sans MS")
$Button1 = GUICtrlCreateButton("OK", 16, 80, 201, 25)
GUISetState(@SW_SHOW)
#EndRegion
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
   If String(GUICtrlRead($Input1)) <> "" And String(GUICtrlRead($Input2)) <> "" Then
    If StringIsSpace(String(GUICtrlRead($Input1))) Or StringIsSpace(String(GUICtrlRead($Input2))) Then
    MsgBox(0,"", "Please Fill All Forms")
    Else
    $NameAndFamily = String(GUICtrlRead($Input1)) & " " & String(GUICtrlRead($Input2))
    GUISetState(@SW_HIDE, $Form2)
    main()
    Exit
    EndIf
   Else
    MsgBox(0,"", "Please Fill All Forms")
   EndIf
EndSwitch
WEnd
EndFunc

script.rar

Link to comment
Share on other sites

Try adding input() after the button to restart the script.

thanks ..

it doesn't work , it run duplicate form and don't exit first form ..

Maybe will help

thanks JohnOne

I put _ScriptRestart() after the button and everything seems be ok

is it true .. ?!

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