Jump to content

Works fine the first time, not the second one


jlnovat
 Share

Recommended Posts

This script is a simulation of flash cards and work just fine until it finishes and starts over again. Then it gets stuck on the:

While 1

            $idMsg1 =  GUIGetMsg()

             Select...

 

routine, and it lets me select the options, but pressing the "Next" botton or the close xindow "X"  don't work.

 

 

Here is the script:

 

Demo.au3

Edited by jlnovat
Link to comment
Share on other sites

  • Developers

The attach file isn't available, but please just post your code in the post in a CODEBOX (<>)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

#include <File.au3>
#include <MsgBoxConstants.au3>
#include <GUIConstantsEx.au3>
#include <AutoItConstants.au3>

While 1
SelectArea()
WEnd
Func SelectArea()
Opt("GUICoordMode", 1)
    GUICreate("Area", 650, 550)
        Local $idSiguiente = GUICtrlCreateButton("Next", 530, 280, 100, 40)
        GUICtrlCreateGroup("Choose an area to study", 30, 30, 450, 450)
            GUIStartGroup()
                Local $Area1  = GUICtrlCreateRadio("Area 1", 60, 60, 270, 20)
                Local $Area2  = GUICtrlCreateRadio("Area 2", 60, 90, 270, 20)
                Local $Area3 = GUICtrlCreateRadio("Area 3", 60, 120, 270, 20)




    GUISetState(@SW_SHOW)  ; Muestra el cuadro

    Global $iArea = 1   ; Si no se selecciona ninguna opción, empezamos por ATA 21

    Local $idMsg1 = 0
    ; In this message loop we use variables to keep track of changes to the radios, another
    ; way would be to use GUICtrlRead() at the end to read in the state of each control

    While 1

        $idMsg1 = GUIGetMsg()
        Select
            Case $idMsg1 = -3
                Exit

            Case $idMsg1 = -4

            Case $idMsg1 = $idSiguiente
                GUIDelete()
                ExitLoop

            Case $idMsg1 = $Area1
                $iArea = 1

            Case $idMsg1 = $Area2
                $iArea = 2

            Case $idMsg1 = $Area2
                $iArea = 2



        EndSelect
    WEnd

    Global $Matriz3, $sFilePath = @ScriptDir & "\Data\Matriz3.txt"
    _FileReadToArray($sFilePath, $Matriz3, Default, ",")
    Global $Matriz3_2 = _ArrayFindAll($Matriz3, $iArea, Default, Default, Default, Default, 2)

     Local $iRows = UBound($Matriz3_2, 1) ; Total number of rows. In this example it will be 10.

    Global $MatrizATA[$iRows+1][2]

    ; Fill the array with data.
    $MatrizATA[0][0] = 0
    $MatrizATA[0][1] = 0
    Local $i2 = 1
    For $u = $Matriz3_2[0] To $Matriz3_2[0] + $iRows - 1
        For $j = 0 To 1
            $MatrizATA[$i2][$j] = $Matriz3[$u][$j]
        Next
        $i2=$i2+1
    Next

Empezar()

EndFunc


Func Empezar()
    ; Calculamos la cantidad de fichas que hay de cada tipo (Sabidas, no sabidas o dudosas)
    Global $PregTipo_1 = UBound(_ArrayFindAll($MatrizATA, 1, Default, Default, Default, Default, 1))
    Global $PregTipo_4 = UBound(_ArrayFindAll($MatrizATA, 4, Default, Default, Default, Default, 1))
    Global $PregTipo_3 = UBound(_ArrayFindAll($MatrizATA, 3, Default, Default, Default, Default, 1))

    ; Creamos el cuadro para preguntar qué fichas queremos estudiar
    Opt("GUICoordMode", 1)
    GUICreate("¿Qué Preguntas quieres estudiar?", 400, 280)
        Global $idEmpezar = GUICtrlCreateButton("Empezar", 200, 140, 120, 40)
        GUICtrlCreateGroup("Preguntas", 30, 90, 165, 160)
            GUIStartGroup()
                Global $idNo_sabidas = GUICtrlCreateRadio("No sabidas (" & $PregTipo_1 & ")", 50, 120, 100, 20)
                Global $idDudosas = GUICtrlCreateRadio("Dudosas (" & $PregTipo_4 & ")", 50, 150, 90, 20)
                Global $idSabidas = GUICtrlCreateRadio("Sabidas (" & $PregTipo_3 & ")", 50, 180, 90, 20)
    GUISetState(@SW_SHOW)  ; Muestra el cuadro

    Global $iTipoPreg = 1   ; Si no se selecciona ninguna opción, empezamos por las fichas que no nos sabemos

    Local $idMsg2 = 0
    ; In this message loop we use variables to keep track of changes to the radios, another
    ; way would be to use GUICtrlRead() at the end to read in the state of each control
    While 1
        $idMsg2 = GUIGetMsg()
        Select
            Case $idMsg2 = -3
                Exit

            Case $idMsg2 = -4

            Case $idMsg2 = $idEmpezar
                GUIDelete()
                ExitLoop

            Case $idMsg2 = $idNo_sabidas
                $iTipoPreg = 1

            Case $idMsg2 = $idDudosas
                $iTipoPreg = 4          ; Por algún motivo que desconozco, si en vez de 4 uso 2, no funciona

            Case $idMsg2 = $idSabidas
                $iTipoPreg = 3

        EndSelect
    WEnd

ShowImg()

EndFunc


Func ShowImg()

    Global $aResult = _ArrayFindAll($MatrizATA, $iTipoPreg, Default, Default, Default, Default, 1)
    Global $iMax = UBound($aResult)
    Global $i=0
    Global $Numero = $aResult[$i] + $Matriz3_2[1]-2

        Global $sDestination = @ScriptDir & "\Data\Pregunta_" & $Numero & ".jpg"
        Global $sDestination2 = @ScriptDir & "\Data\Respuesta_" & $Numero & ".jpg"
        Global $Imagen = $sDestination

    SplashImageOn("", $Imagen,1000,750,0,0,3)

    Opt("GUICoordMode", 2)
    Opt("GUIResizeMode", 1)
    Opt("GUIOnEventMode", 1)

    Global $hGUI = GUICreate("Options",250,70,1000,100)
    GUISetOnEvent(-3, "Salir")

    GUICtrlCreateButton("Turn", 10, 30, 50)
    GUICtrlSetOnEvent(-1, "Turn")

    GUICtrlCreateButton("Unknown", 0, -1, 80)
    GUICtrlSetOnEvent(-1, "Unknown")

    GUICtrlCreateButton("Doubt",0,-1, 40)
    GUICtrlSetOnEvent(-1, "Doubt")

    GUICtrlCreateButton("Known", 0, -1, 60)
    GUICtrlSetOnEvent(-1, "Known")

    GUISetState(@SW_SHOW, $hGUI)

    While $i < $iMax
    WEnd

EndFunc

Func Turn()
    $sDestination = @ScriptDir & "\Data\Pregunta_" & $Numero & ".jpg"
    $sDestination2 = @ScriptDir & "\Data\Respuesta_" & $Numero & ".jpg"
    Select
        Case $Imagen = $sDestination
            $Imagen = $sDestination2

        Case $Imagen = $sDestination2
            $Imagen = $sDestination
    EndSelect

    SplashImageOn("", $Imagen,1000,750,0,0,3)

EndFunc

Func Unknown()
    _FileWriteToLine(@ScriptDir & "\Data\Matriz3.txt", $Numero, $Numero & ",1," & $iATA,True)
    _Next()
EndFunc

Func Doubt()
    _FileWriteToLine(@ScriptDir & "\Data\Matriz3.txt", $Numero, $Numero & ",4," & $iATA,True)
    _Next()
EndFunc

Func Known()
    _FileWriteToLine(@ScriptDir & "\Data\Matriz3.txt", $Numero, $Numero & ",3," & $iATA,True)
    _Next()
EndFunc

Func _Next()
    if $i = $iMax  - 1 Then
        $i = $i + 1
        GUIDelete($hGUI)
        SplashOff()
        MsgBox(0,"","Finished")
    Else
        $i = $i + 1
        $Numero = $aResult[$i]+ $Matriz3_2[1]-2
        $sDestination = @ScriptDir & "\Data\Pregunta_" & $Numero & ".jpg"
        $sDestination2 = @ScriptDir & "\Data\Respuesta_" & $Numero & ".jpg"
        $Imagen = $sDestination

        SplashImageOn("", $Imagen,1000,750,0,0,2)
    EndIf
EndFunc

Func Salir()
            Exit
EndFunc

 

Link to comment
Share on other sites

The code is barely testable, because of the missing data (matriz3.txt)

But i managed to notice something, later in one function, you are switching the behavior of the Autoit script with

    Opt("GUIOnEventMode", 1)
 

but you are not changing it back anywhere. (which is needed for the 1st gui)

 

you could do something like

While 1
    Opt("GUIOnEventMode", 0)
    SelectArea()
WEnd

or 

Func SelectArea()
   Opt("GUIOnEventMode", 0)

 

Some of my script sourcecode

Link to comment
Share on other sites

Can't run your code because $iATA is undefined. If I comment out the _FileWriteToLine lines, it crashes the first time I click Next --

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\danpollak\Dropbox\webdriver\test3.au3" /UserParams    
+>11:01:30 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0)  Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\danpollak\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\danpollak\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\danpollak\Dropbox\webdriver\test3.au3
+>11:01:30 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\danpollak\Dropbox\webdriver\test3.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
"C:\Users\danpollak\Dropbox\webdriver\test3.au3" (69) : ==> Subscript used on non-accessible variable.:
For $u = $Matriz3_2[0] To $Matriz3_2[0] + $iRows - 1
For $u = $Matriz3_2^ ERROR
->11:01:36 AutoIt3.exe ended.rc:1
+>11:01:36 AutoIt3Wrapper Finished.
>Exit code: 1    Time: 6.403

 

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