wirelesss Posted May 29, 2014 Posted May 29, 2014 (edited) Hi friends, I share you this script QuizEasy ( Quiz Easy ) v1.0.17 to random options of each question You have 2 ways to design your questions and answer options:Notes: 1. no limits to propose any total of options in each question2. one blank line before to begin next question Way 1: 1. Who is the King?@@Jesus Daemon The Prophets The Angels Notes:@@ indicates the correct answer Way 2: 2. Question with 2 fixed position words 1 and 4 and other options will be combined? @*word1 word2 word3 word4 @1,4 Notes:@* indicates the correct combination of words list@{any number1, ...number2, ...} indicates fixed positions that it won't be randomized EXAMPLE OF TEST FILE : --------------------------------- 1. Who is the King? @@Jesus Daemon The Prophets The Angels 2. Question with 2 fixed position words 1 and 4, then other options will be combined? @*word1 word2 word3 word4 @1,4 3. Question with 2 fixed position words 2 and 4, then other options will be combined? @*word1 word2 word3 word4 @2,4 4. Question without fixed positions of words, then all options will be combined? @*word1 word2 word3 word4 @ END OF LINE -------------------------------RUN TEST : Example in window: 1. Who is the King? A. The Prophets B. Daemon C. Jesus D. The Angeles To respond C option you can press "C" key or "3" key of your keyboard, then "Enter", "space" to skip next question 2. Question with 2 fixed position words 1 and 4, then other options will be combined? A. word1 word3 word2 word4 B. word1 word2 word3 word4 To respond B option you can press "B" key or "2" key of your keyboard, then "Enter", "space" to skip next question 3. Question with 2 fixed position words 2 and 4, then other options will be combined? A. word3 word2 word1 word4 B. word1 word2 word3 word4 To respond B option you can press "B" key or "2" key of your keyboard, then "Enter", "space" to skip next question 4. Question without fixed positions of words, then all options will be combined? A. word1 word4 word2 word3 B. word3 word1 word2 word4 C. word3 word2 word1 word4 D. word4 word3 word1 word2 E. word4 word2 word3 word1 F. word1 word2 word4 word3 G. word2 word3 word1 word4 H. word1 word3 word3 word4 I. word4 word2 word1 word3 J. word4 word1 word2 word3 K. word4 word1 word3 word2 L. word1 word4 word3 word2 M. word2 word4 word3 word1 N. word2 word4 word1 word3 O. word1 word3 word4 word2 P. word2 word1 word4 word3 Q. word4 word3 word2 word1 R. word3 word4 word1 word2 S. word2 word1 word3 word4 T. word1 word2 word3 word4 U. word3 word1 word4 word2 V. word2 word3 word4 word1 W. word3 word4 word2 word1 X. word3 word2 word4 word1 To respond T option you can press "T" key or "20" (keys "2" and "0") of your keyboard, then "Enter", "space" to skip next question ------------------------------ I hope you learn a lot!God bless you! Rodrigo QUIZ EASY - SCRIPT : file quiz_easy_v17_prod.au3: expandcollapse popup;----------- Quiz Easy - Easy Quiz ------ #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=quiz_easy_v1.0.17.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <Array.au3> #include <Misc.au3> #include <_ArrayRandom.au3> #include <_GUICtrlMenu_Recent.au3> #include <Timers.au3> #include <File.au3> Global $tot_archivos_recientes_leidos = 0 Global $nombre_archivos_recientes = @ScriptDir & "\archivosrecientes.ini" Global $MAX_HIST_ARCHIVOS = 20 Global Const $sFont = "Arial" Opt('MustDeclareVars', 1) Global $hDLL = DllOpen("user32.dll") Global $INICIANDO_QUIZ = True Global $LabAns,$aArrQues,$Input,$iQresult Global $GUI, $msg, $Lab, $LabAns, $Input, $But, $iQResult = 0, $QPercnt, $sTitles Global $resultados_tmp Global $resultadosArreglo[1] Global $respuestaGuardada = "" Global $tipoAlternativas Global $PREPARANDO_PREGUNTA = True Dim Const $PERMUTAR = "PERMUTAR", $DESORDENAR = "DESORDENAR" ;Ini Archivos Recientes Global $hGUI Global $sFilePath = '' Global $iFileMenu Global $iOpen Global $iOpenFile Global $iExitApp Global $iOpenFile Global $iOpcionesQuiz Global $iCloseQuiz Global $iReInicioQuiz Global $SALIR_QUIZ = False ; Create a variable to store the recent menu API information. Global $hRecentMenu = 0 ;Fin Archivos Recientes Global $TitleMainWindow = 'Quiz Easy v1.0.17' Global $TitleQuizWindow = 'QuizBrain - Quiz para Mejorar tus Conocimientos!' Global $QUIZ_ACTIVADO = False Global $BASE_POS_CONTROLES_QUIZ = 0 Main() Func Main() inicializar() crearMenus() loopPrincipal() EndFunc Func inicializar() If Not FileExists($nombre_archivos_recientes) Then If Not _FileCreate($nombre_archivos_recientes) Then MsgBox(0,"Archivo no creado","No se pudo crear el archivo en la siguiente ruta," & @CRLF & "por favor cree un archivo en blanco con el siguiente nombre:" & @CRLF & $nombre_archivos_recientes & @CRLF) Endif EndIf EndFunc Func loopPrincipal() Local $iMsg = 0 ;MsgBox(0,"loopPrincipal!","paso 01") While 1 $iMsg = GUIGetMsg() ConsoleWrite("-> iMsg = " & $iMsg & @CRLF) Switch $iMsg Case $GUI_EVENT_CLOSE ;MsgBox(0,"Fin Quiz Easy","Se cierra Quiz Easy $QUIZ_ACTIVADO:" & $QUIZ_ACTIVADO & ", $GUI=" & $GUI & @CRLF) ;ExitLoop; ;GUIDelete($GUI); Se cierra solo la ventana de quiz ;WinClose($TitleQuizWindow) ;WinSetState($TitleQuizWindow, $TitleQuizWindow, @SW_HIDE) If $QUIZ_ACTIVADO = False Then GUIDelete($GUI) $GUI = -1 EndIf Case $iExitApp ;MsgBox(0,"EXIT","EXIT $QUIZ_ACTIVADO:" & $QUIZ_ACTIVADO & ", $GUI=" & $GUI & @CRLF) If $QUIZ_ACTIVADO = False Then ;WinClose ( $TitleMainWindow ) ;ExitLoop; Se cierra la aplicacion / programa WinKill ($TitleMainWindow ) If Not($GUI>0) Then ExitLoop EndIf EndIf Case $iCloseQuiz ;WinClose($TitleQuizWindow) If $QUIZ_ACTIVADO = True Then GUIDelete($GUI); EndIf Case $iOpen,$iOpenFile ConsoleWrite("iMsg = " & $iMsg & ", iOpenFile=" & $iOpenFile & ", iOpen=" & $iOpen & @CRLF) $sFilePath = FileOpenDialog('Escoge un Archivo...', @ScriptDir, 'All (*.*)') If @error = 0 Then ; Check whether or not the filepath is currently in the recent menu. If it isn't then add to the recent menu. If Not _GUICtrlMenu_RecentIsInMenu($hRecentMenu, $sFilePath) Then ; If the button or open menu items are selected then add a filepath to the recent menu. _GUICtrlMenu_RecentAdd($hRecentMenu, $sFilePath, True) ; Display the text as short text. FileWriteLine($nombre_archivos_recientes,$sFilePath) EndIf $INICIANDO_QUIZ = True runQuiz($sFilePath) EndIf ;Case $iIncreaseItems ; If _GUICtrlMenu_RecentTotal($hRecentMenu, 20) Then ; MsgBox(4096, '', 'The recent menu list was increased to a maximum of 20 items.', 0, $hGUI) ; Else ; MsgBox(4096, '', 'The recent menu list wasn''t increased to a maximum of 20 items. An error occurred.', 0, $hGUI) ; EndIf Case Else ; Check if the message id returned by GUIGetMsg is present in the menu list. $sFilePath = _GUICtrlMenu_RecentSelected($hRecentMenu, $iMsg) If Not @error And $sFilePath Then runQuiz($sFilePath) ;MsgBox(4096, '', 'The recent menu was clicked and the following item was selected.' & @CRLF & _ ; @CRLF & _ ; $sFilePath, 0, $hGUI) EndIf EndSwitch WEnd ;MsgBox(0,"EXIT APP","EXIT $QUIZ_ACTIVADO:" & $QUIZ_ACTIVADO & @CRLF) GUIDelete($hGUI) EndFunc Func crearMenus() $hGUI = GUICreate($TitleMainWindow, 300, 200) ;Ini Archivos Recientes $iFileMenu = GUICtrlCreateMenu('&Archivo') $iOpen = GUICtrlCreateMenuItem('Abrir Test', $iFileMenu) GUICtrlSetState(-1, $GUI_DEFBUTTON) ; $iFileMenu = GUICtrlCreateMenu('&Archivo') ; $iOpen = GUICtrlCreateMenuItem('Abrir Test', $iFileMenu) ; GUICtrlSetState(-1, $GUI_DEFBUTTON) ;// Agregar items recientes desde archivo $tot_archivos_recientes_leidos = 0 _GUICtrlMenu_RecentCreate($hRecentMenu, 1, $iFileMenu, 'Archivos Recientes') ; Create a recent menu with a maximum of 5 displayed items. _GUICtrlMenu_RecentTotal($hRecentMenu, $MAX_HIST_ARCHIVOS) Local $file = FileOpen($nombre_archivos_recientes, 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "No se pudo abrir el archivo:" & @CR & $nombre_archivos_recientes) Exit EndIf ; Read in lines of text until the EOF is reached While 1 Local $line = FileReadLine($file) If @error = -1 Then ExitLoop ;Agrgegar items recientes desde archivo $tot_archivos_recientes_leidos += 1 if $tot_archivos_recientes_leidos<=$MAX_HIST_ARCHIVOS Then ;MsgBox(0, "Line read:", $line) _GUICtrlMenu_RecentAdd($hRecentMenu, $line, True) ; Display the text as short text. Else ExitLoop EndIf WEnd FileClose($file) ;// Fin Agregar items recientes desde archivo GUICtrlCreateMenuItem('', $iFileMenu) ; Seperator Line. GUICtrlCreateMenuItem('Guardar resultados', $iFileMenu) GUICtrlSetState(-1, $GUI_DISABLE) $iExitApp = GUICtrlCreateMenuItem('Salir', $iFileMenu) $iOpenFile = GUICtrlCreateButton('Abrir Test', 5, 10, 85, 25) ;MsgBox(0,"crearMenus ejecutado!","") GUISetState(@SW_SHOW, $hGUI) EndFunc Func runQuiz($ruta_test) $iQResult = 0 $GUI = GUICreate($TitleQuizWindow, 450, 520) ; will create a dialog box that when displayed is centered $QUIZ_ACTIVADO = True GUISetFont(12, 800); normal = 400 GUISetBkColor(0xFFFFE0) $aArrQues = StringSplit(StringStripWS(FileRead($ruta_test), 2), @CRLF & @CRLF, 1) ;_ArrayDisplay($aArrQues) $BASE_POS_CONTROLES_QUIZ = 430; $Lab = GUICtrlCreateLabel("", 10, 30, $BASE_POS_CONTROLES_QUIZ, 390);350 $Input = GUICtrlCreateInput("", 10, $BASE_POS_CONTROLES_QUIZ-10, 30, 20) $LabAns = GUICtrlCreateLabel("", 10, 375, $BASE_POS_CONTROLES_QUIZ, 40) $But = GUICtrlCreateButton("Responder", 50, $BASE_POS_CONTROLES_QUIZ-10, 120, 20) $iOpcionesQuiz = GUICtrlCreateMenu('&Opciones') $iReInicioQuiz = GUICtrlCreateMenuItem('Reiniciar Test', $iOpcionesQuiz) $iCloseQuiz = GUICtrlCreateMenuItem('Cerrar Test', $iOpcionesQuiz) ;Ejemplo Crear Boton con Fuente Personalizada ( Custom Font to Button ) ;$iBotonReInicioQuiz = GUICtrlCreateButton('Reiniciar Test', 150, 10, 85, 20) ;GUICtrlSetFont($iBotonReInicioQuiz, 9, 80, 0, $sFont, 0) GUISetState() Local $i Local $j For $i = 1 To $aArrQues[0] $PREPARANDO_PREGUNTA = True ;GUICtrlSetData($Lab, $aArrQues[$i]) $resultados_tmp = StringSplit($aArrQues[$i],@CRLF,1) ;_ArrayDisplay($resultados_tmp,"Previa Data:") ;if $resultados_tmp[0] = 3 Then ;permutarValores ;EndIf ConsoleWrite("total datos del arreglo:" & $resultados_tmp[0] & @CRLF) ;_ArrayDisplay($resultados_tmp,"Total datos del arreglo") _ArrayRandom($resultados_tmp, 2, Ubound($resultados_tmp)-1) ConsoleWrite("Total elementos array:" & Ubound($resultados_tmp) & @CRLF) $aArrQues[$i] = "" ConsoleWrite("resultados_tmp[0]=" & $resultados_tmp[0] & @CRLF) ConsoleWrite("resultados_tmp[1]=" & $resultados_tmp[1] & @CRLF) ConsoleWrite("resultados_tmp[2]=" & $resultados_tmp[2] & @CRLF) If Ubound($resultados_tmp)>3 Then ConsoleWrite("resultados_tmp[3]=" & $resultados_tmp[3] & @CRLF) $respuestaGuardada = "" $tipoAlternativas = "" If StringInStr($resultados_tmp[2],"@*",1)>0 Or StringInStr($resultados_tmp[3],"@*",1)>0 Then ConsoleWrite("-->IF: resultados_tmp[2]=" & $resultados_tmp[2] & ", resultados_tmp[3]=" & $resultados_tmp[3] & @CRLF) ;Guardar respuesta correcta: Dim $respuesta_alternativa = "" Dim $patron_respuestafija = "" IF StringInStr($resultados_tmp[2],"@*",1)>0 Then $respuesta_alternativa = $resultados_tmp[2] $patron_respuestafija = $resultados_tmp[3] ConsoleWrite("$respuesta_alternativa_if=" & $respuesta_alternativa & @CRLF) ConsoleWrite("$patron_respuestafija_if=" & $patron_respuestafija & @CRLF) Else $respuesta_alternativa = $resultados_tmp[3] $patron_respuestafija = $resultados_tmp[2] ConsoleWrite("$respuesta_alternativa_else=" & $respuesta_alternativa & @CRLF) ConsoleWrite("$patron_respuestafija_else=" & $patron_respuestafija & @CRLF) EndIf IF $respuestaGuardada == "" Then $tipoAlternativas = $PERMUTAR $respuesta_alternativa = StringStripWS($respuesta_alternativa,7) $respuesta_alternativa = StringReplace($respuesta_alternativa,"@*","",0,1) $respuestaGuardada = $respuesta_alternativa EndIf ConsoleWrite("-->respuestaGuardada:" & $respuestaGuardada & @CRLF) Dim $patron_elemPosicionesFijas = StringReplace($patron_respuestafija,"@","",0,1) Dim $elemposicionesfijas = StringSplit($patron_elemPosicionesFijas,",",1) ;_ArrayDisplay($elemposicionesfijas,"Elementos posiciones fijas") Dim $resultados_tmp_opciones $resultados_tmp_opciones = StringSplit($respuesta_alternativa," ",1) Dim $total_opciones = $resultados_tmp_opciones[0] Dim $opcionesposicionespermutadas = StringSplit(StringLeft("1,2,3,4,5,6,7,8,9,0",$total_opciones*2),",",1) Dim $k For $k = $total_opciones+1 to $opcionesposicionespermutadas[0] _ArrayDelete($opcionesposicionespermutadas, $k); eliminar el primero elemento que contiene el total de elementos de data del arreglo Next _ArrayDelete($opcionesposicionespermutadas, 0); eliminar el primero elemento que contiene el total de elementos de data del arreglo ;_ArrayDisplay($opcionesposicionespermutadas,"POSICIONES-OPCIONES ANTES DE PERMUTAR") Dim $array_opcionesposicionespermutadas = _ArrayPermute($opcionesposicionespermutadas, ",") ;_ArrayDisplay($array_opcionesposicionespermutadas,"array_opcionesposicionespermutadas") ;_ArrayDisplay($resultados_tmp_opciones,"resultados_tmp_opciones") _ArrayDelete($resultados_tmp_opciones, 0); eliminar el primero elemento que contiene el total de elementos de data del arreglo Dim $resultados_permutados = _ArrayPermute($resultados_tmp_opciones, " ") ;_ArrayDisplay($resultados_permutados,"$resultados_permutados") ConsoleWrite("$resultados_permutados[0]=" & $resultados_permutados[0] & @CRLF) Dim $patronPermutado Dim $contElementosPatron = 0 Dim $cont_opciones = 0 $aArrQues[$i] = $resultados_tmp[1] & @CRLF; se guarda la pregunta If $resultados_permutados[0]>1 Then For $j =1 to Ubound($resultados_permutados)-1 ConsoleWrite("posicion dada: " & $array_opcionesposicionespermutadas[$j] & @CRLF) ConsoleWrite("posicionpermutada[" & $j & "]=" & $array_opcionesposicionespermutadas[$j] & @CRLF) $patronPermutado = StringSplit($array_opcionesposicionespermutadas[$j],",") $contElementosPatron = 0 ConsoleWrite("patronPermutado[0] = " & $patronPermutado[0] & @CRLF) ConsoleWrite("elemposicionesfijas[0] = " & $elemposicionesfijas[0] & @CRLF) ConsoleWrite("-->patron_respuestafija = " & $patron_respuestafija & @CRLF) If $patron_respuestafija<>"@" Then For $k = 1 to $elemposicionesfijas[0] ConsoleWrite("elemposicionesfijas[" & $k & "]=" & $elemposicionesfijas[$k] & @CRLF) ConsoleWrite("$patronPermutado[" & $elemposicionesfijas[$k] & "] =? " & ($elemposicionesfijas[$k]-1) & @CRLF) If($patronPermutado[$elemposicionesfijas[$k]] = ($elemposicionesfijas[$k])) Then $contElementosPatron += 1 ConsoleWrite("j=" & $j & ",k=" & $k & ",$contElementosPatron=" & $contElementosPatron & @CRLF) EndIf Next If $contElementosPatron = $elemposicionesfijas[0] Then $cont_opciones += 1 ConsoleWrite("j=" & $j & ",k=" & $k & ",$cont_opciones=" & $cont_opciones & @CRLF) $aArrQues[$i] &= $resultados_permutados[$j] & @CRLF If $respuestaGuardada = $resultados_permutados[$j] Then $respuestaGuardada = $resultados_permutados[$j] EndIf ConsoleWrite("j=" & $j & ",k=" & $k & ",$aArrQues[" & $i & "]=" & $aArrQues[$i] & @CRLF) EndIf Else ConsoleWrite("-->elemposicionesfijas[0] == 0: True" & @CRLF) $cont_opciones += 1 $aArrQues[$i] &= $resultados_permutados[$j] & @CRLF EndIf Next If $patron_respuestafija="@" Then $respuestaGuardada = $resultados_permutados[1] EndIf EndIf ConsoleWrite("Respuesta Guardada @*:" & $respuestaGuardada & @CRLF) Else ConsoleWrite("-->ELSE: resultados_tmp[2]=" & $resultados_tmp[2] & ", resultados_tmp[3]=" & $resultados_tmp[3] & @CRLF) For $j =1 to $resultados_tmp[0] ConsoleWrite("Leyendo: j="& $j &"[" & $resultados_tmp[$j] & "] buscar @* :" & StringInStr($resultados_tmp[$j],"@*",1) & ", buscar @@ :" & StringInStr($resultados_tmp[$j],"@@",1) & @CRLF) If $j>1 Then Select Case StringInStr($resultados_tmp[$j],"@@",1)>0 IF $respuestaGuardada == "" Then $tipoAlternativas = $DESORDENAR $respuestaGuardada = StringReplace($resultados_tmp[$j],"@@","",0,1) & @CRLF EndIf $aArrQues[$i] &= $respuestaGuardada ConsoleWrite("Respuesta Guardada @@:" & $respuestaGuardada & @CRLF) Case Else $aArrQues[$i] &= $resultados_tmp[$j] & @CRLF EndSelect ConsoleWrite("j=" & $j & ",$aArrQues["&$i&"]="&$aArrQues[$i]&",$resultados_tmp[$j]="&$resultados_tmp[$j]&@CRLF) Else $aArrQues[$i] &= $resultados_tmp[$j] & @CRLF EndIf Next EndIf Else $tipoAlternativas = $DESORDENAR ConsoleWrite("1 respuesta: -->$aArrQues[$i]=" & $aArrQues[$i] & @CRLF) ConsoleWrite("1 respuesta: -->$resultados_tmp[0]=" & $resultados_tmp[0] & @CRLF) $resultados_tmp[0] = StringStripWS( StringReplace($resultados_tmp[0],"@*","",0,1), 3) $resultados_tmp[0] = StringStripWS( StringReplace($resultados_tmp[0],"@@","",0,1), 3) $resultados_tmp[0] = StringStripWS( StringReplace($resultados_tmp[0],"@","",0,1), 3) $respuestaGuardada = $resultados_tmp[0] & @CRLF $aArrQues[$i] = $resultados_tmp[1] & @CRLF & $resultados_tmp[0] & @CRLF ConsoleWrite("1 respuesta: --> result: $aArrQues[$i]=" & $aArrQues[$i] & @CRLF) ConsoleWrite("1 respuesta: --> result: respuestaGuardada=[" & $respuestaGuardada & "]" & @CRLF) EndIf ; Ini: ALEATORIZAR ALTERNATIVAS / OPCIONES Dim $OpcionesDePregunta = $aArrQues[$i] ConsoleWrite("OpcionesDePregunta :" & $OpcionesDePregunta & @CRLF) Dim $OpcionesArrayDePregunta = StringSplit(StringStripWS($OpcionesDePregunta, 2), @CRLF, 1) ConsoleWrite("Total OpcionesArrayDePregunta :" & $OpcionesArrayDePregunta[0] & @CRLF) _ArrayRandom($OpcionesArrayDePregunta,2) Dim $OpcionesAleatorizadas = "" Dim $cont_opciones = 0 For $j =2 to $OpcionesArrayDePregunta[0] ConsoleWrite("Leyendo: j="& $j &"[" & $OpcionesArrayDePregunta[$j] & "], $respuestaGuardada=[" & $respuestaGuardada & "]" & @CRLF) ConsoleWrite("Leyendo: j= StringStripWS "& $j &"[" & StringStripWS($OpcionesArrayDePregunta[$j],7) & "] ,7), StringStripWS $respuestaGuardada=[" & StringStripWS($respuestaGuardada,7) & "] ,7)" & @CRLF) $cont_opciones += 1 If StringStripWS($respuestaGuardada,7) = StringStripWS($OpcionesArrayDePregunta[$j],7) Then $respuestaGuardada = Chr(64+$cont_opciones) & ". " & $OpcionesArrayDePregunta[$j] & @CRLF ConsoleWrite("--> .. $respuestaGuardada=" & $respuestaGuardada & @CRLF) EndIf $OpcionesAleatorizadas &= Chr(64+$cont_opciones) & ". " & $OpcionesArrayDePregunta[$j] & @CRLF Next If $OpcionesAleatorizadas="" Then $OpcionesAleatorizadas = Chr(64+1) & ". " & $respuestaGuardada & @CRLF $respuestaGuardada = Chr(64+1) & ". " & $respuestaGuardada & @CRLF ConsoleWrite("--> ... $respuestaGuardada=" & $respuestaGuardada & @CRLF) EndIf ;Se concatena Pregunta y Todas las Respuestas ConsoleWrite("-->Fin Aleatorizar: $OpcionesArrayDePregunta[1]="& $OpcionesArrayDePregunta[1] &", $OpcionesAleatorizadas=" & $OpcionesAleatorizadas & "]" & @CRLF) $aArrQues[$i] = $OpcionesArrayDePregunta[1] & @CRLF & $OpcionesAleatorizadas ; Fin: ALEATORIZAR ALTERNATIVAS / OPCIONES ;AJUSTAR SIZE FONT depend Total Options Local $sizeFont = Int(18-Sqrt($OpcionesArrayDePregunta[0])*2) ConsoleWrite("sizeFont :" & $sizeFont & @CRLF) GUICtrlSetFont($Lab, $sizeFont, 80, 0, $sFont, 0) If $tipoAlternativas = "" And $PREPARANDO_PREGUNTA = True Then MsgBox(0,"Error al leer alternativas en archivo","Error en definicion de alternativas, por favor revise su archivo de preguntas y respuestas") Exit EndIf ;MsgBox(0,"Pregunta:",$aArrQues[$i]) GUICtrlSetData($Lab, $aArrQues[$i]) GUICtrlSetData($LabAns, "") GUICtrlSetState($Input, $GUI_FOCUS) If _IsPressed("0D", $hDLL) Then ; Wait until key is released. While _IsPressed("10", $hDLL) Sleep(250) WEnd EndIf Local $starttime = _Timer_Init() Do If $INICIANDO_QUIZ = True Then If _Timer_Diff($starttime)>1000 Then $INICIANDO_QUIZ = False EndIf EndIf $msg = GUIGetMsg() If $msg = $iCloseQuiz Then ;WinClose($TitleQuizWindow) $SALIR_QUIZ = True EndIf If $msg = $iReInicioQuiz Then GUIDelete($GUI); Se cierra solo la ventana de quiz $INICIANDO_QUIZ = True runQuiz($sFilePath) EndIf If $msg = $But Then ConsoleWrite("msg = But -> mostrarResultadoPregunta(...)" & @CRLF) mostrarResultadoPregunta($i) ExitLoop Else If _IsPressed("0D", $hDLL) Then If $INICIANDO_QUIZ = False Then ConsoleWrite("_IsPressed - Enter Key was pressed." & @CRLF) ; Wait until key is released. While _IsPressed("10", $hDLL) Sleep(250) WEnd ConsoleWrite("_IsPressed - Enter Key was released." & @CRLF) mostrarResultadoPregunta($i) ExitLoop EndIf ElseIf _IsPressed("1B", $hDLL) Then MsgBox(0, "_IsPressed", "Tecla Esc fue presionada, por lo tanto se cierra el Quiz.") ExitLoop ElseIf _IsPressed("20", $hDLL) Then ConsoleWrite("_IsPressed - Tecla Espacio fue presionada, por lo tanto se avanza a siguiente pregunta.") ; Wait until key is released. While _IsPressed("20", $hDLL)<>0 Sleep(250) WEnd GUICtrlSetData($LabAns, "") ConsoleWrite("_IsPressed - Space Key was released." & @CRLF) GUICtrlSetData($Input, "") $PREPARANDO_PREGUNTA = False ExitLoop EndIf EndIf If $msg = -3 Then Exit Until 0 Or $SALIR_QUIZ = True If $SALIR_QUIZ = True Then ExitLoop EndIf Next If $SALIR_QUIZ = False Then #cs 1. Good (on 1-25%) 2. Better (on 26-50%) 3. Best (on 51-75%) 4. Excellent, Marvelous - You Won! (on 76-100%) #ce ConsoleWrite("Total Preguntas:" & $aArrQues[0] & @CRLF) $QPercnt = 100 * $iQResult / $aArrQues[0] Switch $QPercnt Case 0 To 25 $sTitles = "Regular rendimiento" Case 26 To 50 $sTitles = "Mediano rendimiento" Case 51 To 75 $sTitles = "Buen rendimiento" Case 76 To 89 $sTitles = "Casi estupendo!" Case 90 To 99 $sTitles = "Excelente!";"Excellent, Marvelous - You Won! " Case 100 $sTitles = "Eres un Genio!";"Excellent, Marvelous - You Won! " EndSwitch MsgBox(0, "Resultado Final del Quiz", $QPercnt & "% correcto, " & $sTitles, 0, $GUI) ;ControlFocus($TitleQuizWindow,"",$iOpcionesQuiz) $SALIR_QUIZ = False $QUIZ_ACTIVADO = False WinClose($TitleQuizWindow) ;GUICtrlSetState($iOpcionesQuiz, $GUI_FOCUS) ;GUIDelete($GUI); Return Else $SALIR_QUIZ = False $QUIZ_ACTIVADO = False WinClose($TitleQuizWindow) Return EndIf EndFunc ;==>Quiz Func permutarValores($aArray,$simboloConcatenar) $aArray = _ArrayPermute($aArray, $simboloConcatenar) ;Using Default Parameters ;_ArrayDisplay($aArray, "Arreglo permutado") EndFunc Func mostrarResultadoPregunta($i) GUICtrlSetData($LabAns, "Respuesta correcta es:- " & @CRLF & $respuestaGuardada) ConsoleWrite("RespuestaCorrecta1 i=" & $i & "," & StringLeft($respuestaGuardada,1) & ", es:" & StringLower(StringLeft($respuestaGuardada, 1)) & ", MiRespuesta:" & StringLower(GUICtrlRead($Input)) & @CRLF) ConsoleWrite("RespuestaCorrecta2 i=" & $i & "," & StringLeft($respuestaGuardada,1) & ", es:" & Asc(StringLower(StringLeft($respuestaGuardada, 1))) & ", MiRespuesta:" & (96 + Int(StringLower(GUICtrlRead($Input)))) & @CRLF) If StringLower(StringLeft($respuestaGuardada, 1)) = StringLower(GUICtrlRead($Input)) Or _ Asc(StringLower(StringLeft($respuestaGuardada, 1))) = (96 + Int(StringLower(GUICtrlRead($Input)))) Then $PREPARANDO_PREGUNTA = False MsgBox(0, "Resultado", "Correcto", 1, $GUI) $iQResult += 1 Else $PREPARANDO_PREGUNTA = False MsgBox(0, "Resultado", "Incorrecto", 1, $GUI) EndIf LoopIfNotKeyPress(3000) GUICtrlSetData($Input, "") EndFunc Func LoopIfNotKeyPress($tiempoEsperaSiguientePregunta) Local $ContinuarLoop = True Local $begin = TimerInit() Local $dif While $ContinuarLoop If _IsPressed("20", $hDLL) Then ConsoleWrite("_IsPressed - Tecla Espacio fue presionada, por lo tanto se avanza a siguiente pregunta..") ; Wait until key is released. While _IsPressed("20", $hDLL)<>0 Sleep(250) WEnd GUICtrlSetData($LabAns, "") ConsoleWrite("_IsPressed - Space Key was released.." & @CRLF) GUICtrlSetData($Input, "") $ContinuarLoop = False $PREPARANDO_PREGUNTA = False Else $dif = TimerDiff($begin) If $dif>$tiempoEsperaSiguientePregunta Then $ContinuarLoop = False $PREPARANDO_PREGUNTA = False EndIf EndIf Wend EndFunc file _ArrayRandom.au3 : expandcollapse popup; #FUNCTION# ==================================================================================================================== ; Name...........: _ArrayRandom ; Description ...: Randomize the row order of (part of) a 1D or 2D array. ; Syntax.........: _ArrayRandom(ByRef $avArray, $iStart = 0, $iEnd = 0) ; Parameters ....: $avArray - Array to randomize ; $iStart - [optional] Index of array to start at ; $iEnd - [optional] Index of array to stop at ; Return values .: Success - 1 ; Failure - 0, sets @error: ; |1 - $avArray is not an array ; |2 - $iStart is greater than $iEnd ; Author ........: Tom Vernooij ; Modified.......: ; Remarks .......: Based on Yashied's method ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ArrayRandom(ByRef $avArray, $iStart=0, $iEnd=0) If Not IsArray($avArray) Then Return SetError(1,0,0) Local $iRow, $iCol, $rRow, $Temp, $numCols = UBound($avArray,2), $Ubound = UBound($avArray) -1 ; Bounds checking If $iEnd < 1 Or $iEnd > $UBound Then $iEnd = $UBound If $iStart < 0 Then $iStart = 0 If $iStart > $iEnd Then Return SetError(2, 0, 0) ; for 2 dimentional arrays: If $numCols Then For $iRow = $iStart To $iEnd ;for each row... $rRow = Random($iStart, $iEnd, 1) ;...select a random row For $iCol = 0 To $numCols -1 ;swich the values for each cell in the rows $Temp = $avArray[$iRow][$iCol] $avArray[$iRow][$iCol] = $avArray[$rRow][$iCol] $avArray[$rRow][$iCol] = $Temp Next Next ; for 1 dimentional arrays: Else For $iRow = $iStart To $iEnd ;for each cell... $rRow = Random($iStart, $iEnd, 1) ;...select a random cell $Temp = $avArray[$iRow] ;switch the values in the cells $avArray[$iRow] = $avArray[$rRow] $avArray[$rRow] = $Temp Next EndIf Return 1 EndFunc file _GUICtrlMenu_Recent.au3 : expandcollapse popup#include-once ; #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ; #INDEX# ======================================================================================================================= ; Title .........: _GUICtrlMenu_Recent ; AutoIt Version : v3.2.2.0 or higher ; Language ......: English ; Description ...: Create a recent menu to add previously opened files or other text items to. ; Author(s) .....: guinness ; =============================================================================================================================== ; #INCLUDES# ========================================================================================================= #include <WinAPI.au3> #include <WindowsConstants.au3> ; #GLOBAL VARIABLES# ================================================================================================= ; None ; #CURRENT# ===================================================================================================================== ; _GUICtrlMenu_RecentAdd: Add an item to the recent menu that was created with _GUICtrlMenu_RecentCreate. ; _GUICtrlMenu_RecentCreate: Create a recent menu that is added to an existing menu created with GUICtrlCreateMenu. ; _GUICtrlMenu_RecentDelete: Delete an item in the recent menu that was created with _GUICtrlMenu_RecentCreate. ; _GUICtrlMenu_RecentIsInMenu: Search if a filepath or text is currently in the menu list. ; _GUICtrlMenu_RecentSelected: Retrieve the text of a selected menu item and delete from the menu list. ; _GUICtrlMenu_RecentTotal: Change the total number of items to be displayed in the recent menu. ; =============================================================================================================================== ; #INTERNAL_USE_ONLY#============================================================================================================ ; __GUICtrlMenu_RecentDelete ; =============================================================================================================================== ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlMenu_RecentAdd ; Description ...: Add an item to the recent menu that was created with _GUICtrlMenu_RecentCreate. ; Syntax ........: _GUICtrlMenu_RecentAdd(Byref $aAPI, $sText) ; Parameters ....: $aAPI - [in/out] API created by _GUICtrlMenu_RecentCreate. ; $sText - Text to be added to the recent menu. ; $fShortText - [optional] Display the text as short text e.g. 'C:\Example...\Test.au3'. Default is False. ; Return values .: Success - ControlID from GUICtrlCreateMenuItem ; Failure - Returns 0 & sets @error to none-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlMenu_RecentAdd(ByRef $aAPI, $sText, $fShortText = False) Local Enum $iAPICount, $iAPIColumns, $iAPITotal, $iAPIMenu, $iAPIMax #forceref $iAPIMax If $aAPI[0][$iAPIMenu] = -1 Then Return SetError(1, 0, 0) EndIf _GUICtrlMenu_RecentIsInMenu($aAPI, $sText) Local Const $iIndex = @extended If $iIndex Then __GUICtrlMenu_RecentDelete($aAPI, $aAPI[0][$iAPITotal], $iIndex, $aAPI[0][$iAPICount], $aAPI[0][$iAPIColumns]) EndIf If $aAPI[0][$iAPICount] = $aAPI[0][$iAPITotal] Then __GUICtrlMenu_RecentDelete($aAPI, $aAPI[0][$iAPITotal], 1, $aAPI[0][$iAPICount], $aAPI[0][$iAPIColumns]) EndIf Local $sShortText = $sText If $fShortText Then $sShortText = StringRegExpReplace($sText, '(^.{3,11}\\|.{11})(.*)(\\.{6,27}|.{27})$', '\1...\3') ; Thanks to AZJIO for the regular expression. EndIf $aAPI[0][$iAPITotal] += 1 $aAPI[$aAPI[0][$iAPITotal]][0] = GUICtrlCreateMenuItem($sShortText, $aAPI[0][$iAPIMenu], 0) $aAPI[$aAPI[0][$iAPITotal]][1] = $sText $aAPI[$aAPI[0][$iAPITotal]][2] = $sShortText Return $aAPI[$aAPI[0][$iAPITotal]][0] EndFunc ;==>_GUICtrlMenu_RecentAdd ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlMenu_RecentCreate ; Description ...: Create a recent menu that is added to an existing menu created with GUICtrlCreateMenu. ; Syntax ........: _GUICtrlMenu_RecentCreate(Byref $aAPI, $iTotal, $iMenu, $sTitle[, $iMenuEntry = -1]) ; Parameters ....: $aAPI - [in/out] Variable to be used to store the API information. ; $iTotal - Maximum total number of recent menu items to be displayed. If this is exceeded then old values will be overwritten. ; $iMenu - Existing menu id created with GUICtrlCreateMenu. ; $sTitle - Title of the recent menu. ; Return values .: Success - API to be passed to _GUICtrlMenu_RecentAdd, _GUICtrlMenu_RecentIsInMenu or _GUICtrlMenu_RecentSelected. ; Failure - None ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlMenu_RecentCreate(ByRef $aAPI, $iTotal, $iMenu, $sTitle) Local Enum $iAPICount, $iAPIColumns, $iAPITotal, $iAPIMenu, $iAPIMax If $iTotal < 1 Then $iTotal = 10 EndIf Local $aArray[$iTotal + 1][$iAPIMax] $aArray[0][$iAPICount] = $iTotal ; Total number of rows. $aArray[0][$iAPIColumns] = $iAPIMax ; Total number of columns. $aArray[0][$iAPITotal] = 0 ; Total number of items. $aArray[0][$iAPIMenu] = $iMenu ; Menu controlid for the recent list. $aArray[0][$iAPIMenu] = GUICtrlCreateMenu($sTitle, $aArray[0][$iAPIMenu]) $aAPI = $aArray EndFunc ;==>_GUICtrlMenu_RecentCreate ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlMenu_RecentDelete ; Description ...: Delete an item in the recent menu that was created with _GUICtrlMenu_RecentCreate. ; Syntax ........: _GUICtrlMenu_RecentDelete(Byref $aAPI, $vIndex) ; Parameters ....: $aAPI - [in/out] API created by _GUICtrlMenu_RecentCreate. ; $vIndex - Value to be deleted. This can either be an integer of the API index (see _GUICtrlMenu_RecentIsInMenu and remarks) ; or a string value of the item. ; Return values .: Success - True ; Failure - False and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlMenu_RecentDelete(ByRef $aAPI, $vIndex) Local Enum $iAPICount, $iAPIColumns, $iAPITotal, $iAPIMenu, $iAPIMax #forceref $iAPIMenu, $iAPIMax If IsString($vIndex) Then _GUICtrlMenu_RecentIsInMenu($aAPI, $vIndex) $vIndex = @extended EndIf If $vIndex <= 0 Or $vIndex > $aAPI[0][$iAPICount] Then Return SetError(1, 0, False) EndIf Return __GUICtrlMenu_RecentDelete($aAPI, $aAPI[0][$iAPITotal], $vIndex, $aAPI[0][$iAPICount], $aAPI[0][$iAPIColumns]) EndFunc ;==>_GUICtrlMenu_RecentDelete ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlMenu_RecentIsInMenu ; Description ...: Search if a filepath or text is currently in the menu list. ; Syntax ........: _GUICtrlMenu_RecentIsInMenu(Byref $aAPI, $sText) ; Parameters ....: $aAPI - [in/out and const] API created by _GUICtrlMenu_RecentCreate. ; $sText - Text to search for. This is a case-sensitive search. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Remarks .......: @extended is set to the index position in the API handle. This is useful if using GUICtrlMenu_RecentDelete. ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlMenu_RecentIsInMenu(ByRef Const $aAPI, $sText) Local Enum $iAPICount, $iAPIColumns, $iAPITotal, $iAPIMenu, $iAPIMax #forceref $iAPIColumns, $iAPITotal, $iAPIMenu, $iAPIMax For $i = 1 To $aAPI[0][$iAPICount] If ($sText == $aAPI[$i][1]) Or ($sText == $aAPI[$i][2]) Then Return SetExtended($i, True) EndIf Next Return SetExtended(0, False) EndFunc ;==>_GUICtrlMenu_RecentIsInMenu ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlMenu_RecentSelected ; Description ...: Retrieve the text of a selected menu item and delete from the menu list. ; Syntax ........: _GUICtrlMenu_RecentSelected(Byref $aAPI, $iMsg) ; Parameters ....: $aAPI - [in/out] API created by _GUICtrlMenu_RecentCreate. ; $iMsg - Message id returned by GUIGetMsg. ; Return values .: Success - Text of the selected menu. ; Failure - Blank string and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlMenu_RecentSelected(ByRef $aAPI, $iMsg) Local Enum $iAPICount, $iAPIColumns, $iAPITotal, $iAPIMenu, $iAPIMax #forceref $iAPIMenu, $iAPIMax If $iMsg <= 0 Then Return SetError(1, 0, '') EndIf Local $sFilePath = '' For $i = 1 To $aAPI[0][$iAPICount] If $iMsg = $aAPI[$i][0] Then $sFilePath = $aAPI[$i][1] __GUICtrlMenu_RecentDelete($aAPI, $aAPI[0][$iAPITotal], $i, $aAPI[0][$iAPICount], $aAPI[0][$iAPIColumns]) ExitLoop EndIf Next Return $sFilePath EndFunc ;==>_GUICtrlMenu_RecentSelected ; #FUNCTION# ==================================================================================================================== ; Name ..........: _GUICtrlMenu_RecentTotal ; Description ...: Change the total number of items to be displayed in the recent menu. ; Syntax ........: _GUICtrlMenu_RecentTotal(Byref $aAPI, $iTotal) ; Parameters ....: $aAPI - [in/out] API created by _GUICtrlMenu_RecentCreate. ; $iTotal - Maximum total number of recent menu items to be displayed. If this is exceeded then old values will be overwritten. ; Return values .: Success - True ; Failure - False and sets @error to non-zero. ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _GUICtrlMenu_RecentTotal(ByRef $aAPI, $iTotal) Local Enum $iAPICount, $iAPIColumns, $iAPITotal, $iAPIMenu, $iAPIMax #forceref $iAPIMenu, $iAPIMax If $iTotal < 1 Or $iTotal = $aAPI[0][$iAPICount] Then Return SetError(1, 0, False) EndIf If $iTotal < $aAPI[0][$iAPICount] Then For $i = 1 To ($aAPI[0][$iAPITotal] - $iTotal) GUICtrlDelete($aAPI[$i][0]) Next Local $iIndex = ($aAPI[0][$iAPITotal] - $iTotal) + 1 For $i = 1 To $iTotal For $j = 0 To $aAPI[0][$iAPIColumns] - 1 $aAPI[$i][$j] = $aAPI[$iIndex][$j] Next $iIndex += 1 Next $aAPI[0][$iAPITotal] = $iTotal EndIf $aAPI[0][$iAPICount] = $iTotal ReDim $aAPI[$aAPI[0][$iAPICount] + 1][$aAPI[0][$iAPIColumns]] Return True EndFunc ;==>_GUICtrlMenu_RecentTotal ; #INTERNAL_USE_ONLY#============================================================================================================ Func __GUICtrlMenu_RecentDelete(ByRef $aAPI, ByRef $iTotal, $iIndex, $iCount, $iColumns) Local $iReturn = GUICtrlDelete($aAPI[$iIndex][0]) For $i = $iIndex To $iCount - 1 For $j = 0 To $iColumns - 1 $aAPI[$i][$j] = $aAPI[$i + 1][$j] $aAPI[$i + 1][$j] = '' Next Next $iTotal -= 1 Return $iReturn = 1 EndFunc ;==>__GUICtrlMenu_RecentDelete I hope you learn a lot!God bless you! Rodrigo Edited June 2, 2014 by wirelesss Added code tags
Moderators Melba23 Posted May 29, 2014 Moderators Posted May 29, 2014 wirelesss,Welcome to the AutoIt forums. When you post code please use Code tags - see here how to do it. Then you get a scrolling box and syntax colouring as you can see above now I have added the tags. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
wirelesss Posted June 2, 2014 Author Posted June 2, 2014 I published Quiz Easy v1.0.17: -fix bug about file .ini
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now