Jump to content
ternal

Need some help with GUI Accelerators

Recommended Posts

Posted (edited)

Hi,

I am learning a bit about GUI in autoit. For this I am writing a little program (in dutch  sorry) to give simple math problems to my kid.

To enter the solutions I would like to use GUI accelerators and the enter key.I am already using GUI accelerators for the login window.

However no matter what I do I cannot seem to get the enter key to work.
My other solution is always keeping the window on top and using hotkeys.

I have tried messing around with the scopes and when in the program I set the accelerators.

Could someone point out what I am doing wrong here(in regard to the accelerators)?

the accelerator function DOES return 1 so perhaps something with my dummy?

I am a beginner so bear with me please :).

 

When you run the program , just enter anything , press enter or "inloggen"

then press "optellen" and try solving an equation.

I declare the array passed to the gui accelerator as global so it should be accesible everywhere(Region globals).

 

I assign values to the array right after declaring the dummy control(rekenenGUI).

The function from where the dummy control function should run is B_optellen()

 

sorry for the messy script as this is the process  of home taught scripting  and a few houres of trying to debug (ie calling the accelerator function  everytime in the for loop and such) 

 

 

Full Program:

#Region Headers
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>


#EndRegion

#Region Options
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

#EndRegion

#Region Globals
Global $sUser = ""
Global $aLijsten
Global $bVrijgave = False
Global $iCorrect = 0
Global $bReturnCorrect = True
Global $aVerkeerdeAntwoorden = "nvt"
Global $accel_rekenen[1][2]
;parameters
Global $DisplayTijdms = 500
#EndRegion

#Region GUI

#Region MenuGUI
Global $Menu = GUICreate ("Rekenen", 365, 182, 351, 224)
Global $StatusBarMain = _GUICtrlStatusBar_Create($Menu, -1, "")
Global $B_Optellen = GUICtrlCreateButton("Optellen", 40, 60, 75, 25)
Global $B_Aftrekken = GUICtrlCreateButton("Aftrekken", 222, 58, 75, 25)
GUISetOnEvent($B_Optellen, "B_Optellen")
GUISetOnEvent($B_Aftrekken, "B_Aftrekken")
#EndRegion

#Region InlogGUI
Global $Inlog = GUICreate("Login", 365, 182, 351, 224, $WS_EX_DLGMODALFRAME, -1 ,$Menu)
Local $LoginLabel = GUICtrlCreateLabel("Gelieve eerst in te loggen", 10, 12, 182, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
Local $LGebruiker = GUICtrlCreateLabel("Gebruikersnaam :", 10, 42, 126, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
Global $IB_User = GUICtrlCreateInput("", 136, 40, 121, 21)
Local $B_Inloggen = GUICtrlCreateButton("Inloggen", 102, 76, 75, 25)
Local $B_Exit = GUICtrlCreateButton("Afsluiten", 180, 76, 75, 25)
GUICtrlSetOnEvent($B_Inloggen, "B_Inloggen")
GUICtrlSetOnEvent($B_Exit, "B_Exit")
#EndRegion



#Region RekenGUI
Global $Rekenen = GUICreate("Rekenen", 365, 182, 351, 224, $WS_EX_DLGMODALFRAME, -1 ,$Menu)
Global $StatusBarRekenen = _GUICtrlStatusBar_Create($Rekenen)
Global $L_Getal1 = GUICtrlCreateLabel("XX", 34, 50, 34, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
Global $L_Operation = GUICtrlCreateLabel("+", 74, 50, 16, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
Global $L_Getal2 = GUICtrlCreateLabel("XX", 92, 50, 34, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
Local $L_Equal = GUICtrlCreateLabel("=", 136, 50, 16, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
Global $Input_Antwoord = GUICtrlCreateInput("", 162, 52, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
Global $B_Controle = GUICtrlCreateButton("", 34, 82, 150, 28)
Global $fDummyCompare = GUICtrlCreateDummy()
$accel_rekenen[0][0] = "{ENTER}"; global var.
$accel_rekenen[0][1] = $fDummyCompare; global var.
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
#EndRegion

#Region UIFunctions
Func B_Inloggen ()
    $sUser = GUICtrlRead($IB_User)
    _LogWrite($sUser & " is net aangemeld.")
    GUISetState($Inlog, @SW_HIDE)
    GUIDelete($Inlog)
    GUISwitch($Menu)
    _GUICtrlStatusBar_SetText($StatusBarMain, "Ingelogt als " & $sUser & ".")
    GUICtrlSetOnEvent($B_Optellen, "B_Optellen")
    GUICtrlSetOnEvent($B_Aftrekken, "B_Aftrekken")
    GUISetOnEvent($GUI_EVENT_CLOSE, "TitleBarFunctions")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "TitleBarFunctions")
    GUISetState(@SW_SHOW)
EndFunc


Func B_Exit ()
    _LogWrite("App afgesloten door Afsluitknop in het inlogscherm")
    Exit
EndFunc

Func B_Optellen()
    Local $aLijsten = _GenerateList( 25, 0, 10, 2, False)
    GUISwitch($Menu)
    GUISetState(@SW_HIDE)
    GUISwitch($Rekenen)
    GUISetState(@SW_SHOW)
    GUICtrlSetOnEvent($fDummyCompare, "_Compare")
    GUICtrlSetData($L_Operation, "+")
    GUISetAccelerators($accel_rekenen, $Rekenen)
    For $i = 1 to UBound($aLijsten, 1)
        _GUICtrlStatusBar_SetText($StatusBarRekenen, "Optellen, " & $i & " van de " & UBound($aLijsten, 1) - 1)
        GUICtrlSetData($L_Getal1, $aLijsten[$i][0])
        GUICtrlSetData($L_Getal2, $aLijsten[$i][1])
        $aLijsten[$i][2] = $aLijsten[$i][0] + $aLijsten[$i][1]
        $iCorrect = $aLijsten[$i][2]
        While $bVrijgave = False
            GUISetAccelerators($accel_rekenen, $Rekenen)
            Sleep(50)
        WEnd
        $aLijsten[$i][3] = $aVerkeerdeAntwoorden
        $aVerkeerdeAntwoorden ="nvt"
    Next
EndFunc

Func B_Aftrekken()
    Local $aLijsten = _GenerateList( 25, 0, 10, 2, True)
    GUISwitch($Menu)
    GUISetState(@SW_HIDE)
    GUISwitch($Rekenen)
    GUISetState(@SW_SHOW)
    GUICtrlSetData($L_Operation, "-")
    GUICtrlSetOnEvent($fDummyCompare, "_Compare")
    GUISetAccelerators($accel_rekenen, $Rekenen)
    For $i = 1 to UBound($aLijsten, 1)
        _GUICtrlStatusBar_SetText($StatusBarRekenen, "Aftrekken, " & $i & " van de " & UBound($aLijsten, 1) - 1)
        GUICtrlSetData($L_Getal1, $aLijsten[$i][0])
        GUICtrlSetData($L_Getal2, $aLijsten[$i][1])
        $aLijsten[$i][2] = $aLijsten[$i][0] - $aLijsten[$i][1]
        $iCorrect = $aLijsten[$i][2]
        $bVrijgave = False
        While $bVrijgave = False
            Sleep(50)
        WEnd
        $aLijsten[$i][3] = $aVerkeerdeAntwoorden
        $aVerkeerdeAntwoorden ="nvt"
    Next
EndFunc

Func _Compare()
    _LogWrite("hier")
    Local $iInput = GUICtrlRead($Input_Antwoord)
    If $iInput <> $iCorrect Then
        $bReturnCorrect = False
        GUICtrlSetBkColor($B_Controle, "0xFF000")
        Sleep($DisplayTijdms)
        GUICtrlSetBkColor($B_Controle,_WinAPI_GetSysColor($COLOR_MENU))
        _AddFault($iInput)
    Else
        $bReturnCorrect = True
        GUICtrlSetBkColor($B_Controle, "0x00FF00")
        Sleep($DisplayTijdms)
        GUICtrlSetBkColor($B_Controle,_WinAPI_GetSysColor($COLOR_MENU))
        $bVrijgave = True
    EndIf

EndFunc
#EndRegion

#Region TitleBarFunctions
Func TitleBarFunctions()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            _LogWrite("Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
             _LogWrite("minimize Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
    EndSelect
EndFunc
#EndRegion

#EndRegion

#Region Main
GUISwitch($Inlog)
GUISetState(@SW_SHOW)
Local $accel_Inlog[1][2]
$accel_Inlog[0][0] = "{ENTER}"
$accel_Inlog[0][1] = $B_Inloggen

GUISetAccelerators($accel_Inlog, $Inlog)
while 1
    Sleep(50)
WEnd
#EndRegion

#Region Additional Functions
Func _AddFault ($iNewFault)
    If Not IsArray($aVerkeerdeAntwoorden) Then
        Local $array[1]
        $aVerkeerdeAntwoorden = $array
        $aVerkeerdeAntwoorden[0] = $iNewFault
    Else
        Local $array[UBound($aVerkeerdeAntwoorden) + 1]
        For $i = 0 to UBound($aVerkeerdeAntwoorden) - 1
            $array[$i] = $aVerkeerdeAntwoorden[$i]
        Next
        $array[UBound($aVerkeerdeAntwoorden) ] = $iNewFault
        $aVerkeerdeAntwoorden = $array
    EndIf
EndFunc
Func _LogWrite($sTxt, $iFlag = 0)
    ConsoleWrite($sTxt & "          Flag : " & $iFlag & @CRLF)
    Local $Logfile = @WorkingDir & "\" & @ScriptName & ".log"
    Local $errorFile = $Logfile
    Local $LogTime = @HOUR & ":" & @MIN & ":" & @SEC
    Local $hFileOpen = FileOpen($errorFile, 9)
    FileWriteLine($hFileOpen, $LogTime & " " & $sTxt & "          Flag : " & $iFlag & @CRLF)
    FileClose($hFileOpen)
EndFunc

Func _GenerateList($iAantalGetallen, $iMin = 0, $iMax = 10, $iMaxNullen = 3, $bMoetKleinerZijnDan = False)
    Local $aLijsten[$iAantalGetallen + 1][4]
    Local $iNulCounter = 0
    $aLijsten[0][0] = "Getal 1"
    $aLijsten[0][1] = "Getal 2"
    $aLijsten[0][2] = "Uitkomst"
    $aLijsten[0][3] = "Fouten"

    For $i = 1 To $iAantalGetallen

        $aLijsten[$i][0] = Random($iMin, $iMax, 1)
        If $aLijsten[$i][0] = 0 Then
            $iNulCounter += 1
        EndIf
        While $aLijsten[$i][0] = 0 And $iNulCounter > $iMaxNullen
            $aLijsten[$i][0] = Random($iMin, $iMax, 1)
        WEnd

        $aLijsten[$i][1] = Random($iMin, $iMax, 1)
        If $bMoetKleinerZijnDan = True And $aLijsten[$i][0] <> 0 Then
            If $aLijsten[$i][0] <> 0 Then
                While $aLijsten[$i][1] > $aLijsten[$i][0]
                    $aLijsten[$i][1] = Random($iMin, $iMax, 1)
                WEnd
            EndIf
        EndIf

        Return $aLijsten
    Next
EndFunc
#EndRegion

 

Full flow:

The program starts, declares globals, declares GUI (what I made global for most part to avoid errors)

The GUI consists of $menu with 2 childs $inlog and $rekenen

Then it starts by popping up the $inlog GUI

GUIset_accelerators works fine here.

there is a loop to avoid termination.

 

During declaration there were 2 guictrlsetonevents made that link the 2 buttons ($b_inloggen and $B_exit) to their functions.

This is where the program continues.

the function B_inloggen(Linked to the button) hides and deletes the $inlog GUI

then switches to $Menu.

here 2 new buttons get their functions. For now let's focus on $B_Optellen.

this runs a new function (with a new loop) B_optellen()

this is where the GUIsetaccelertors fails to work. when tested it DOES return 1

is my dummy wrong?

Func B_Optellen()
    Local $aLijsten = _GenerateList( 25, 0, 10, 2, False)
    GUISwitch($Menu)
    GUISetState(@SW_HIDE)
    GUISwitch($Rekenen)
    GUISetState(@SW_SHOW)
    GUICtrlSetOnEvent($fDummyCompare, "_Compare")
    GUICtrlSetData($L_Operation, "+")
    GUISetAccelerators($accel_rekenen, $Rekenen)
    For $i = 1 to UBound($aLijsten, 1)
        _GUICtrlStatusBar_SetText($StatusBarRekenen, "Optellen, " & $i & " van de " & UBound($aLijsten, 1) - 1)
        GUICtrlSetData($L_Getal1, $aLijsten[$i][0])
        GUICtrlSetData($L_Getal2, $aLijsten[$i][1])
        $aLijsten[$i][2] = $aLijsten[$i][0] + $aLijsten[$i][1]
        $iCorrect = $aLijsten[$i][2]
        While $bVrijgave = False
            GUISetAccelerators($accel_rekenen, $Rekenen)
            Sleep(50)
        WEnd
        $aLijsten[$i][3] = $aVerkeerdeAntwoorden
        $aVerkeerdeAntwoorden ="nvt"
    Next
EndFunc

 

Edited by ternal

Share this post


Link to post
Share on other sites

terna,

The big problem with that script is that you are trying to fire a function within a running function - see the Interrupting a running function tutorial in the Wiki to see why this is the case.

I will try and rework the script so that you can get around the problem - but as I hate coding in OnEvent mode this might take a while!

M23

 


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Posted (edited)

No need to,  I would  like to try it myself..  Thanks for pointing  out  my mistake!!!! 

 

 

edit:

I understand now that I cannot terminate an function that was called by on- event trigger.

 

For the dutch people under us.

IF you would like your copy to make your kids do math excercises please feel free to adjust /use it as you please !!

#Region Headers
#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WinAPISysWin.au3>
#include <WindowsConstants.au3>


#EndRegion

#Region Options
Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

#EndRegion

#Region Globals
Global $sUser = ""
Global $aLijsten
Global $bVrijgave = False
Global $iCorrect = 0
Global $bReturnCorrect = True
Global $aVerkeerdeAntwoorden = "nvt"
Global $accel_rekenen[1][2]
Global $iRekenen = 0
Global $iOperation = 0 ;0= optellen, 1=aftrekken, 2= mixed
;parameters
Global $DisplayTijdms = 500
#EndRegion

#Region GUI

#Region MenuGUI
Global $Menu = GUICreate ("Rekenen", 365, 182, 351, 224)
Global $StatusBarMain = _GUICtrlStatusBar_Create($Menu, -1, "")
Global $B_Optellen = GUICtrlCreateButton("Optellen", 40, 60, 75, 25)
Global $B_Aftrekken = GUICtrlCreateButton("Aftrekken", 222, 60, 75, 25)
Global $B_Mixed = GUICtrlCreateButton("Mixed", 131, 60, 75, 25)
GUICtrlSetOnEvent($B_Optellen, "B_Optellen")
GUICtrlSetOnEvent($B_Aftrekken, "B_Aftrekken")
GUICtrlSetOnEvent($B_Mixed, "B_Mixed")
#EndRegion

#Region InlogGUI
Global $Inlog = GUICreate("Login", 365, 182, 351, 224, $WS_EX_DLGMODALFRAME, -1 ,$Menu)
Local $LoginLabel = GUICtrlCreateLabel("Gelieve eerst in te loggen", 10, 12, 182, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
Local $LGebruiker = GUICtrlCreateLabel("Gebruikersnaam :", 10, 42, 126, 20)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
Global $IB_User = GUICtrlCreateInput("", 136, 40, 121, 21)
Local $B_Inloggen = GUICtrlCreateButton("Inloggen", 102, 76, 75, 25)
Local $B_Exit = GUICtrlCreateButton("Afsluiten", 180, 76, 75, 25)
GUICtrlSetOnEvent($B_Inloggen, "B_Inloggen")
GUICtrlSetOnEvent($B_Exit, "B_Exit")
#EndRegion



#Region RekenGUI
Global $Rekenen = GUICreate("Rekenen", 365, 182, 351, 224, $WS_EX_DLGMODALFRAME, -1 ,$Menu)
Global $StatusBarRekenen = _GUICtrlStatusBar_Create($Rekenen)
Global $L_Getal1 = GUICtrlCreateLabel("XX", 34, 50, 34, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
Global $L_Operation = GUICtrlCreateLabel("+", 74, 50, 16, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
Global $L_Getal2 = GUICtrlCreateLabel("XX", 92, 50, 34, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
Local $L_Equal = GUICtrlCreateLabel("=", 136, 50, 16, 28)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
Global $Input_Antwoord = GUICtrlCreateInput("", 162, 52, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
Global $B_Controle = GUICtrlCreateButton("", 34, 82, 150, 28)
Global $fDummyCompare = GUICtrlCreateDummy()
$accel_rekenen[0][0] = "{ENTER}"; global var.
$accel_rekenen[0][1] = $fDummyCompare; global var.
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
#EndRegion

#Region UIFunctions
Func B_Inloggen ()
    $sUser = GUICtrlRead($IB_User)
    _LogWrite($sUser & " is net aangemeld.")
    GUISetState($Inlog, @SW_HIDE)
    GUIDelete($Inlog)
    GUISwitch($Menu)
    _GUICtrlStatusBar_SetText($StatusBarMain, "Ingelogt als " & $sUser & ".")
    GUISetOnEvent($GUI_EVENT_CLOSE, "TitleBarFunctions")
    GUISetOnEvent($GUI_EVENT_MINIMIZE, "TitleBarFunctions")
    GUISetState(@SW_SHOW)
EndFunc


Func B_Exit ()
    _LogWrite("App afgesloten door Afsluitknop in het inlogscherm")
    Exit
EndFunc

Func B_Optellen()
    GUISwitch($Menu)
    GUISetState(@SW_HIDE)
    GUISwitch($Rekenen)
    GUICtrlSetOnEvent($fDummyCompare, "_Compare")
    GUICtrlSetData($L_Operation, "+")
    $iRekenen = 1
    $iOperation = 0
    GUISetAccelerators($accel_rekenen, $Rekenen)
EndFunc

Func B_Aftrekken()
    GUISwitch($Menu)
    GUISetState(@SW_HIDE)
    GUISwitch($Rekenen)
    GUICtrlSetOnEvent($fDummyCompare, "_Compare")
    $iRekenen = 1
    $iOperation = 1
    GUISetAccelerators($accel_rekenen, $Rekenen)
EndFunc

Func B_Mixed()
    GUISwitch($Menu)
    GUISetState(@SW_HIDE)
    GUISwitch($Rekenen)
    GUICtrlSetOnEvent($fDummyCompare, "_Compare")
    $iRekenen = 1
    $iOperation = 2
    GUISetAccelerators($accel_rekenen, $Rekenen)
EndFunc

Func _Compare()
    Local $iInput = GUICtrlRead($Input_Antwoord)
    If not ($iInput = $iCorrect) Then
        $bReturnCorrect = False
        GUICtrlSetBkColor($B_Controle, "0xFF0000")
        Sleep($DisplayTijdms)
        GUICtrlSetBkColor($B_Controle,_WinAPI_GetSysColor($COLOR_MENU))
        _AddFault($iInput)
    Else
        $bReturnCorrect = True
        GUICtrlSetBkColor($B_Controle, "0x00FF00")
        Sleep($DisplayTijdms)
        GUICtrlSetBkColor($B_Controle,_WinAPI_GetSysColor($COLOR_MENU))
        $bVrijgave = True
    EndIf
    GUICtrlSetData($Input_Antwoord, "")
EndFunc
#EndRegion

#Region TitleBarFunctions
Func TitleBarFunctions()
    Select
        Case @GUI_CtrlId = $GUI_EVENT_CLOSE
            _LogWrite("Close Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
            Exit
        Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE
             _LogWrite("minimize Pressed", "ID=" & @GUI_CtrlId & " WinHandle=" & @GUI_WinHandle)
    EndSelect
EndFunc
#EndRegion

#EndRegion

#Region Main
GUISwitch($Inlog)
GUISetState(@SW_SHOW)
Local $accel_Inlog[1][2]
$accel_Inlog[0][0] = "{ENTER}"
$accel_Inlog[0][1] = $B_Inloggen

GUISetAccelerators($accel_Inlog, $Inlog)
while 1
    Switch $iRekenen
        Case 0
            Sleep(500)
        Case 1
            If $iOperation = 0 Then Local $aLijsten = _GenerateList( 25, 0, 10, 2, False, False)
            If $iOperation = 1 Then Local $aLijsten = _GenerateList( 25, 0, 10, 2, True, False)
            If $iOperation = 2 Then Local $aLijsten = _GenerateList( 25, 0, 10, 2, False, True)
            GUISetState(@SW_SHOW, $Rekenen)
            For $i = 1 to UBound($aLijsten, 1) -1
                _GUICtrlStatusBar_SetText($StatusBarRekenen, "Optellen, " & $i & " van de " & UBound($aLijsten, 1) - 1)
                GUICtrlSetData($L_Getal1, $aLijsten[$i][0])
                GUICtrlSetData($L_Getal2, $aLijsten[$i][1])
                If $aLijsten[$i][2] = "+" Then
                    $aLijsten[$i][3] = $aLijsten[$i][0] + $aLijsten[$i][1]
                    GUICtrlSetData($L_Operation, "+")
                EndIf
                If $aLijsten[$i][2] = "-" Then
                    $aLijsten[$i][3] = $aLijsten[$i][0] - $aLijsten[$i][1]
                    GUICtrlSetData($L_Operation, "-")
                EndIf
                $iCorrect = $aLijsten[$i][3]
                $bVrijgave = False
                While $bVrijgave = False
                    Sleep(50)
                WEnd
                If IsArray($aVerkeerdeAntwoorden) Then
                    $aLijsten[$i][4] = $aVerkeerdeAntwoorden[0]
                    For $j = 1 To UBound($aVerkeerdeAntwoorden, 1) -1
                        $aLijsten[$i][4]  = $aLijsten[$i][4] & "/" & $aVerkeerdeAntwoorden[$j]
                    Next
                    Else
                        $aLijsten[$i][4] = $aVerkeerdeAntwoorden
                    EndIf
                $aVerkeerdeAntwoorden ="nvt"
            Next
            _WriteArrToCSV($aLijsten)
            $iRekenen = 0
            GUISetState(@SW_HIDE)
            GUISwitch($menu)
            GUISetState(@SW_SHOW)
    EndSwitch
WEnd
#EndRegion

#Region Additional Functions
Func _AddFault ($iNewFault)
    If Not IsArray($aVerkeerdeAntwoorden) Then
        Local $array[1]
        $aVerkeerdeAntwoorden = $array
        $aVerkeerdeAntwoorden[0] = $iNewFault
    Else
        Local $array[UBound($aVerkeerdeAntwoorden) + 1]
        For $i = 0 to UBound($aVerkeerdeAntwoorden) - 1
            $array[$i] = $aVerkeerdeAntwoorden[$i]
        Next
        $array[UBound($aVerkeerdeAntwoorden) ] = $iNewFault
        $aVerkeerdeAntwoorden = $array
    EndIf
EndFunc
Func _LogWrite($sTxt, $iFlag = 0)
    ConsoleWrite($sTxt & "          Flag : " & $iFlag & @CRLF)
    Local $Logfile = @WorkingDir & "\" & @ScriptName & ".log"
    Local $errorFile = $Logfile
    Local $LogTime = @HOUR & ":" & @MIN & ":" & @SEC
    Local $hFileOpen = FileOpen($errorFile, 9)
    FileWriteLine($hFileOpen, $LogTime & " " & $sTxt & "          Flag : " & $iFlag & @CRLF)
    FileClose($hFileOpen)
EndFunc

Func _GenerateList($iAantalGetallen, $iMin = 0, $iMax = 10, $iMaxNullen = 3, $bMoetKleinerZijnDan = False, $bMixed = False)
    Local $aLijsten[$iAantalGetallen + 1][5]
    Local $iNulCounter = 0
    Local $iSameCounter = 0
    Local $bSame = False
    Local $bTeveelNullen = False
    Local $iRandom = 0
    $aLijsten[0][0] = "Getal 1"
    $aLijsten[0][1] = "Getal 2"
    $aLijsten[0][2] = "Bewerking"
    $aLijsten[0][3] = "Uitkomst"
    $aLijsten[0][4] = "Fouten"
    For $i = 1 To $iAantalGetallen
        If $bMixed = True Then
            If Random(0, 1, 0) > 0.5 Then
                $bMoetKleinerZijnDan = True
            Else
                $bMoetKleinerZijnDan = False
            EndIf
        EndIf
        Select
            Case $bMoetKleinerZijnDan = True
                Do
                    $aLijsten[$i][0] = Random(1, $iMax, 1)
                    If $aLijsten[$i][0] = 0 Then $iNulCounter += 1
                    If $iNulCounter > 3 Then $bTeveelNullen = True
                    While $aLijsten[$i][0] = 0 And $bTeveelNullen = False
                        $aLijsten[$i][0] = Random(1, $iMax, 1)
                    WEnd
                    If $aLijsten[$i][1] = 0 Then $iNulCounter += 1
                    $aLijsten[$i][1] = Random(0, $aLijsten[$i][0], 1)
                    While $bTeveelNullen = True And $aLijsten[$i][1] = 0
                        $aLijsten[$i][1] = Random(1, $aLijsten[$i][0], 1)
                    WEnd
                    If $aLijsten[$i][0] = $aLijsten[$i][1] Then $iSameCounter += 1
                    Select
                        Case $aLijsten[$i][0] = $aLijsten[$i][1]
                            $bSame =True
                        Case Else
                            $bSame = False
                    EndSelect
                    $aLijsten[$i][2] = "-"
                Until $bSame = False or $iSameCounter < 4
            Case $bMoetKleinerZijnDan = False
                $aLijsten[$i][0] = Random($iMin, $iMax, 1)
                If $aLijsten[$i][0] = 0 Then $iNulCounter += 1
                If $iNulCounter > 3 Then $bTeveelNullen = True
                While $aLijsten[$i][0] = 0
                    $aLijsten[$i][0] = Random($iMin, $iMax, 1)
                WEnd
                $aLijsten[$i][1] = Random($iMin, $iMax, 1)
                $aLijsten[$i][2] = "+"
        EndSelect
    Next
    Return $aLijsten
EndFunc

Func _WriteArrToCSV(ByRef $array)
    Local $CSVFile =  @WorkingDir & "\" & $sUser & ".csv"
    _FileWriteFromArray($CSVFile, $array, Default, Default, ";")
EndFunc
#EndRegion

 

 

 

Edited by ternal
solution

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

×
×
  • Create New...