xPloit Posted September 20, 2010 Posted September 20, 2010 (edited) I have a few questions/problems that I could use some help with. I am in school (college) for Air Traffic Control and there is a bunch of acronyms/words/definitions that I need to memorize on at a very fast pace. So what I've been doing so far is using notecards to make myself some flash cards. However, in a month and a half, I have already gone through over 500 cards! They're not expensive or anything, but they add up (not to mention the clutter!) So I decided I would try to make some sort of program that made flash cards for me. I have all the GUI stuff done, I just need to write the code that adds new words/definitions and then quizes me on them. My main problem is how to write/read them. I made a GUI with 2 boxes (1 for the word, 1 for the definition) but I'm not sure how to write them into a file. I think I know how to write things into a file, but I need some way of declaring that the first word is an acronym and everything after that is a defintion. What would be the best way of doing that? And then, I obviously dont want the definition displayed when it reads the file, I only want to see the word. So how should I go about making it only read the first part and then comparing my answer to the true answer? A secondary problem(request) I have is that I would like to be able to load cards by class/chapter so that I'm not studying 500 words for a test that only needs ~100 of them...how do I "save" and "load" only certain cards? Sorry for asking all these questions! I hope somebody can help me out! It would save me alot of time and space! ***EDIT*** Posted my code for reference...it might help, lol expandcollapse popup#Include <GUIConstants.au3> AutoItSetOption("MustDeclareVars",1) AutoItSetOption("GUIOnEventMode",1) Global $GUI = GUICreate("Flash Card Tester",280,50) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $StartQuiz = GUICtrlCreateButton("Start Quiz",10,10,70,30) GUICtrlSetOnEvent($StartQuiz,"_Quiz") Global $AddNew = GUICtrlCreateButton("Add New Cards",90,10,90,30) GUICtrlSetOnEvent($AddNew,"_AddNew") Global $Exit = GUICtrlCreateButton("Exit",210,10,50,30) GUICtrlSetOnEvent($Exit,"_Close") Global $AddGUI = GUICreate("Add New",200,100) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $NewWord = GUICtrlCreateInput("Word",10,10,180,20) Global $NewDef = GUICtrlCreateInput("Definition",10,40,180,20) Global $AddDone = GUICtrlCreateButton("Add",30,70,50,20) GUICtrlSetOnEvent($AddDone,"_AddDone") Global $Return0 = GUICtrlCreateButton("Return",90,70,50,20) GUICtrlSetOnEvent($Return0,"_Return") Global $TestGUI = GUICreate("Flash Card Tester",280,100) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $Word = GUICtrlCreateLabel("WORD HERE -- ",10,10,120,50) Global $Def = GUICtrlCreateInput("",100,8,170,20) Global $NumCorrect = GUICtrlCreateLabel("Correct -- ",10,40,70,30) ;GUICtrlSetData somehow... ;GUICtrlSetData($NumCorrect,GUICtrlRead($Correct)) Global $NumWrong = GUICtrlCreateLabel("Wrong -- ",10,55,70,30) ;GUICtrlSetData somehow... ;GUICtrlSetData($NumCorrect,GUICtrlRead($Wrong)) Global $Percentage = GUICtrlCreateLabel("% Correct -- ",10,70,150,30) GUICtrlSetData($Percentage,100 * (GUICtrlRead($NumCorrect) / GUICtrlRead($NumWrong))) Global $Submit = GUICtrlCreateButton("Submit",100,35,170,20) GUICtrlSetOnEvent($Submit,"_Submit") Global $Return = GUICtrlCreateButton("Return",190,70,80,20) GUICtrlSetOnEvent($Return,"_Return") GUISetState(1,$GUI) Global $Correct = 0 Global $Wrong = 0 While 1 Sleep(10) WEnd Func _Quiz() GUISetState(0,$GUI) GUISetState(1,$TestGUI) EndFunc Func _AddNew() GUISetState(0,$GUI) GUISetState(1,$AddGUI) EndFunc Func _AddDone() ;Add new word and new definition to list EndFunc Func _Return() GUISetState(0) GUISetState(1,$GUI) EndFunc Func _Submit() ;Compare GUICtrlRead($Def) and to the respective word's definition in the list ;Keep track of # correct/wrong ;+1 to respective stat ;Make a % based on above statement ;Move on to next word EndFunc Func _Close() Exit EndFunc Edited September 20, 2010 by xPloit 00101101011110000101000001101100011011110110100101110100
darkjohn20 Posted September 20, 2010 Posted September 20, 2010 (edited) Personally I would write it to a .ini file. The section name would be a word, and the key "Definition" would contain the definition. You could even add a hint in there if you felt like it. Then you could read the section names to an array, and randomly select one. As for creating chapters/classes, I would just make a new file for each one.Inside it could look like:[Word1] Definition="Word1's Definition" Hint="Word1's Hint" [Word2] Definition="Word2's Definition" Hint="Word2's Hint"Would you really want the program to accept an input for the answer, or just see if you know it yourself, click "Show Answer" and compare?In my opinion it would be difficult to compare answers.To save the card, the pseudo-code could look like:IniWrite("filename.ini", GuiCtrlRead($TheWord), "Definition", GuiCtrlRead($TheDefinition)) Edited September 20, 2010 by darkjohn20
xPloit Posted September 20, 2010 Author Posted September 20, 2010 My initial thought was that I wanted it to compare, which can be done -- If StringLower(GUICtrlRead($Input)) = GUICtrlRead($Answer) Then blah blah... But I could always do a 'show answer' with 2 button choices (correct/wrong) and then which button I push determines how it tracks the stats. That's something I wanted for sure...a percentage of how many I got right I was thinking a .ini would work well too, but how would I make it randomly select a word/def pair? I want it to be 100% random and repeating so the same word may come up more than once 00101101011110000101000001101100011011110110100101110100
MvGulik Posted September 20, 2010 Posted September 20, 2010 1) Stick to the "Correct/Wrong" buttons. (and maybe a "Maybe" button.) 2) Go for a simple random shuffle per sequence. strait and easy in use and coding. 3) (if using ini) Use the ini sections to save different card selections. --> needs a section selection at the "save cart" part. (save word and answer in a single ini key. Use something like the '|' to separate the two. 'definition|answer') 4) stats ... don't got a good idea, someone else maybe. "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...Â
xPloit Posted September 21, 2010 Author Posted September 21, 2010 I dont do "Hints." Not my style. But I decided to go with the Correct/Incorrect buttons via MsgBox and that works out well I'm not getting the random shuffle part to work... I did manage the get the writting to a .ini working the way I wanted it to And the stats work, but I'm failing at updating them properly...if I change the =0 to =8 or something, they work perfectly, so it's the math part down below that is messing up. Here is my new code. I dont have any sort of "load" function added, but I'll deal with that once I get it working properly for one set of cards. There are like 4 lines that I commented out (3 of which are in the _ShowAnswer func...lol) Those are the ones that aren't working right...if somebody could take a look and explain what's wrong with them, I would greatly appreciate it! expandcollapse popup#Include <GUIConstants.au3> AutoItSetOption("MustDeclareVars",1) AutoItSetOption("GUIOnEventMode",1) Global $Correct = 0 Global $Wrong = 0 Global $CardsShown = 0 Global $GUI = GUICreate("Flash Card Tester",280,50) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $StartQuiz = GUICtrlCreateButton("Start Quiz",10,10,70,30) GUICtrlSetOnEvent($StartQuiz,"_Quiz") Global $AddNew = GUICtrlCreateButton("Add New Cards",90,10,90,30) GUICtrlSetOnEvent($AddNew,"_AddNew") Global $Exit = GUICtrlCreateButton("Exit",210,10,50,30) GUICtrlSetOnEvent($Exit,"_Close") Global $AddGUI = GUICreate("Add New",200,100) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $NewWord = GUICtrlCreateInput("Word",10,10,180,20) Global $NewDef = GUICtrlCreateInput("Definition",10,40,180,20) Global $AddDone = GUICtrlCreateButton("Add",30,70,50,20) GUICtrlSetOnEvent($AddDone,"_AddDone") Global $Return0 = GUICtrlCreateButton("Return",90,70,50,20) GUICtrlSetOnEvent($Return0,"_Return") Global $TestGUI = GUICreate("Flash Card Tester",280,100) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") ;Global $Key = IniRead("FlashCards.ini","Intro_to_ATC_2",Random(),0) ;Random() doesn't get a random key... Global $Word = GUICtrlCreateLabel(IniRead("FlashCards.ini","Intro_to_ATC_2",$Key,0),10,10,120,50) Global $Def = GUICtrlCreateInput("",100,8,170,20) Global $NumCorrect = GUICtrlCreateLabel("Correct -- " & $Correct,10,40,70,30) Global $NumWrong = GUICtrlCreateLabel("Wrong -- " & $Wrong,10,55,70,30) Global $Percentage = GUICtrlCreateLabel("% Correct -- " & (100 * ($Correct / $CardsShown)),10,70,150,30) Global $Submit = GUICtrlCreateButton("Show Answer",100,35,170,20) GUICtrlSetOnEvent($Submit,"_ShowAnswer") Global $Return = GUICtrlCreateButton("Return",190,70,80,20) GUICtrlSetOnEvent($Return,"_Return") GUISetState(1,$GUI) While 1 Sleep(10) WEnd Func _Quiz() GUISetState(0,$GUI) GUISetState(1,$TestGUI) EndFunc Func _AddNew() GUISetState(0,$GUI) GUISetState(1,$AddGUI) EndFunc Func _AddDone() IniWrite("FlashCards.ini","Intro_To_ATC_2",GUICtrlRead($NewWord),GUICtrlRead($NewDef)) GUICtrlSetData($NewWord,"Word") GUICtrlSetData($NewDef,"Definition") TrayTip("Flash Card Tester","Flash card has been added",5) EndFunc Func _Return() GUISetState(0) GUISetState(1,$GUI) EndFunc Func _ShowAnswer() $CardsShown += 1 Global $Choice = MsgBox(4,"Answer","The answer is :" & IniRead("FlashCards.ini","Intro_to_ATC_2",$Key,0) & @CRLF & @CRLF & "Did you get it right?") ;The IniRead() has a problem because of $Key, so if it is fixed above, I can fix it here If $Choice = 6 Then ;$Correct += 1 ;Doesn't add 1 to the $Correct label... ElseIf $Choice = 7 Then ;$Wrong += 1 ;Doesn't add 1 to the $Wrong label... EndIf EndFunc Func _Close() Exit EndFunc 00101101011110000101000001101100011011110110100101110100
MvGulik Posted September 21, 2010 Posted September 21, 2010 I dont do "Hints." Not my style.Thats ok, I don't do code. To much work.I'm not getting the random shuffle part to work...I could hint at something very useful ... but than again, you don't do hint. (You seem to be doing fine, and there are plenty of other helpers around here. So I'm out.) "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ...Â
JoHanatCent Posted September 21, 2010 Posted September 21, 2010 Hi Did you manage to create the "FlashCards.ini" file? Need to know the layout. Maybe a copy?
xPloit Posted September 21, 2010 Author Posted September 21, 2010 Hi Did you manage to create the "FlashCards.ini" file? I did manage the get the writting to a .ini working the way I wanted it to Need to know the layout. Maybe a copy? Here you go: expandcollapse popup[Intro_To_ATC_2] CLC=Course-Line Computer DH=Decision Height MTR=Multi Trade Receiver OBS=Omni Bearing Selector SSALS=Simplified Short Approach Lighting System RNP=Required Navigation Performance SDF=Simplified Directional Facility GRI=Group Repetition Interral MMR=Multi Mode Receiver DF=Direction Finder TVORs=Terminal VORs PCL=Pilot Controlled Lighting IM=Inner Marker MOCA=Minimum Obstruction Clearance Altitude LPV=Localizer Performance with Vertical Guidance INS=Inertial Navigation System IAFs=Initial Approach Fixes WACs=World Aeronautical Charts FAF=Final Approach Fix PBN=Performance Based Navigation LIRL=Low Intensity Runway Lighting LAES=Landing Aids Experiment Station DVOR=Doppler VOR WAAS=Wide Area Augmentation System RVR=Runway Visual Range MIRL=Medium Intensity Runway Lighting LNAV=Lateral Navigation TERPS=Terminal Instrument Approach Procedures RAIM=Receiver Autonomous Integrity Monitoring SAAAR=Special Aircraft and Aircrew Authorization Required MALSR=Medium Intensity Approach Lighting System with RAIL VAR=Visual Aural Range MM=Middle Marker LAAS=Local Area Augmentation System LNAV/VNAV=Lateral Navigation/Vertical Navigation SSALR=Simplified Short Approach Lighting System with RAIL RAILs=Runway Alignment Indicator Lights PAPI=Precision Approach Path Indicator RNAV=Area Navigation LOM=Locator Outer Marker IAP=Instrument Approach Procedure LORAN=Long Range Navigation SFL=Sequenced Flashing Lights MDA=Minimum Descent Altitude OM=Outer Marker LDA=Localizer Directional Aid GNSS=Global Navigation Satellite System ADF=Automatic Direction Finder REILs=Runway End Identifier Lights CDI=Course Deviant Indicator NDB=Nondirectional Radio Beacon MAP=Missed Approach Point LMM=Locator Middle Marker ODALS=Omnidirectional Approach Lighting System VASI=Visual Approach Slope Indicator HIRL=High Intensity Runway Lighting MEA=Minimum En Route Altitude 00101101011110000101000001101100011011110110100101110100
Bert Posted September 21, 2010 Posted September 21, 2010 You may want to use Trandumper. It is a app that runs in Internet Explorer and you can make your own test. You build your test in Notepad using a few simple rules when making questions. Very easy to use. I had a variant of the software a few years ago I made, but this site has a real slick version. I've worked with the developer on this one a small bit, and he is a great guy to know. If you have any trouble making a test, let me know and I'll help you out by PM. You will find you can make questions with pictures, video, embedded flash, multi choice, fill in the blank, drag and drop, and more. Yea, this sounds like a sales pitch, but the app is free and I know the code is clean for I have seen the source code. The best part of the app is the fact it can do random question and random answer. That prevents the problem of "The answer is 'B'" when you see a question instead of really learning the answer. I used this tool to help me gain many certifications and to just learn stuff quickly. http://www.gejos.com/ The Vollatran project  My blog: http://www.vollysinterestingshit.com/
xPloit Posted September 21, 2010 Author Posted September 21, 2010 thanks for the link. Like I said though, flash cards are working for me, I was just hoping to find a way to improve my AuI skills since I'm pretty new and need all the practice and exposure I can get right now haha 00101101011110000101000001101100011011110110100101110100
omikron48 Posted September 22, 2010 Posted September 22, 2010 (edited) You can read the whole .ini contents via IniReadSection so you end up with a 2D array with the acronym at [x][0] and the meaning at [x][1]. All you need after is to just generate a random number from 1 to the value in [0][0], then plug those values into your GUI. Since you're only dealing with small sample sizes, I'd suggest using an LCG for random number generation for a better spread. Here's some code: ;### CODE FOR LCG ;uses Apple CarbonLib parameters: http://en.wikipedia.org/wiki/Linear_congruential_generator Global Const $multiplier = 16807 Global Const $increment = 0 Global Const $modulus = _Pow(2, 31) - 1 Global $seed Func _SetSeed($value) $seed = $value EndFunc Func _NextSeed() $seed = Mod($multiplier * $seed + $increment, $modulus) Return $seed EndFunc Func _Pow($base, $exp) Local $result = 1 For $i = 1 To $exp $result *= $base Next Return $result EndFunc ;### END CODE FOR LCG ;Sample usage code Global $maxIndex = 50 ;the value in [0][0] of IniReadSection Global $index _SetSeed(TimerInit()) For $i = 1 To 20 $index = Mod(_NextSeed(), $maxindex) + 1 MsgBox(0x2000, "Test Output", $index) Next Keep in mind that you need to make adjustments if you're using Timer* functions in your script because I used a timer function to seed the random number generator. If you don't use Timer* functions, then it's fine. When you incorporate it into your code, you need to get the modulo of the result of _NextSeed by [0][0] then add 1 since modulo's lowest value is zero. If you don't want repeating appearances during a single session, you need to either make a list containing which items have already been used or use a different random number generation scheme. I remember reading from some game programming book about a method that generates random numbers without repetition for a predefined range. It involved a quadratic equation and prime numbers related to the size of the sample range. Unfortunately, I neither have the book nor remember the method. It was in a book I borrowed while I was still at uni. Edited September 22, 2010 by omikron48
JoHanatCent Posted September 22, 2010 Posted September 22, 2010 I added some lines marked with <<====== You have to split the result (maybe RegEx)to get what you want or redesign your INI layout to make things easier. expandcollapse popup#include <file.au3>; <<====== #Include <GUIConstants.au3> AutoItSetOption("MustDeclareVars",1) AutoItSetOption("GUIOnEventMode",1) Global $Correct = 0 Global $Wrong = 0 Global $CardsShown = 0 Global $aArray;<<======= Dim $key;<<====== #Include <Array.au3> ;<< ====== Only to display the $aArray Global $GUI = GUICreate("Flash Card Tester",280,50) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $StartQuiz = GUICtrlCreateButton("Start Quiz",10,10,70,30) GUICtrlSetOnEvent($StartQuiz,"_Quiz") Global $AddNew = GUICtrlCreateButton("Add New Cards",90,10,90,30) GUICtrlSetOnEvent($AddNew,"_AddNew") Global $Exit = GUICtrlCreateButton("Exit",210,10,50,30) GUICtrlSetOnEvent($Exit,"_Close") Global $AddGUI = GUICreate("Add New",200,100) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $NewWord = GUICtrlCreateInput("Word",10,10,180,20) Global $NewDef = GUICtrlCreateInput("Definition",10,40,180,20) Global $AddDone = GUICtrlCreateButton("Add",30,70,50,20) GUICtrlSetOnEvent($AddDone,"_AddDone") Global $Return0 = GUICtrlCreateButton("Return",90,70,50,20) GUICtrlSetOnEvent($Return0,"_Return") Global $TestGUI = GUICreate("Flash Card Tester",280,100) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") ;Global $Key = IniRead("FlashCards.ini","Intro_to_ATC_2",Random(),0) ;Random() doesn't get a random key... ;>>============= To Array and Randomize If Not _FileReadToArray("FlashCards.ini", $aArray) Then MsgBox(4096, "Error", "Error reading file to Array error:" & @error) Exit EndIf $key=Random(1,$aArray[0],1) ; 0 is how many records MsgBox(0,"Show:","Records in INI file >> " & $aArray[0] & @lf & "Current Rand number $key = "& $key & @LF & $aArray[$Key]) ;_ArrayDisplay($aArray) ;<<============ Global $Word = GUICtrlCreateLabel(IniRead("FlashCards.ini","Intro_to_ATC_2",$Key,0),10,10,120,50) Global $Def = GUICtrlCreateInput("",100,8,170,20) Global $NumCorrect = GUICtrlCreateLabel("Correct -- " & $Correct,10,40,70,30) Global $NumWrong = GUICtrlCreateLabel("Wrong -- " & $Wrong,10,55,70,30) Global $Percentage = GUICtrlCreateLabel("% Correct -- " & (100 * ($Correct / $CardsShown)),10,70,150,30) Global $Submit = GUICtrlCreateButton("Show Answer",100,35,170,20) GUICtrlSetOnEvent($Submit,"_ShowAnswer") Global $Return = GUICtrlCreateButton("Return",190,70,80,20) GUICtrlSetOnEvent($Return,"_Return") GUISetState(1,$GUI) While 1 Sleep(10) WEnd Func _Quiz() GUISetState(0,$GUI) GUISetState(1,$TestGUI) EndFunc Func _AddNew() GUISetState(0,$GUI) GUISetState(1,$AddGUI) EndFunc Func _AddDone() IniWrite("FlashCards.ini","Intro_To_ATC_2",GUICtrlRead($NewWord),GUICtrlRead($NewDef)) GUICtrlSetData($NewWord,"Word") GUICtrlSetData($NewDef,"Definition") TrayTip("Flash Card Tester","Flash card has been added",5) EndFunc Func _Return() GUISetState(0) GUISetState(1,$GUI) EndFunc Func _ShowAnswer() $CardsShown += 1 Global $Choice = MsgBox(4,"Answer","The answer is :" & IniRead("FlashCards.ini","Intro_to_ATC_2",$Key,0) & @CRLF & @CRLF & "Did you get it right?") ;The IniRead() has a problem because of $Key, so if it is fixed above, I can fix it here If $Choice = 6 Then ;$Correct += 1 ;Doesn't add 1 to the $Correct label... ElseIf $Choice = 7 Then ;$Wrong += 1 ;Doesn't add 1 to the $Wrong label... EndIf EndFunc Func _Close() Exit EndFunc
xPloit Posted September 22, 2010 Author Posted September 22, 2010 that's exactly what I was looking for. The only problem I have now is only showing the word...I would spend more time on it, but I have to leave for school haha. So unless I get some help on that by the time I get back, I guess I'll just keep messing around with it until I figure it out! 00101101011110000101000001101100011011110110100101110100
xPloit Posted September 23, 2010 Author Posted September 23, 2010 okay, I have all of the rest of my script working (with the exception of one other small (minor) part), except for only displaying the key and not the entire key=value string...I tried doing StringSplit to cut the string off at the = but I couldn't get that to work...is there anything else that I could do to make it only display the key part of the string? 00101101011110000101000001101100011011110110100101110100
omikron48 Posted September 23, 2010 Posted September 23, 2010 You're not using Ini* functions for handling your information file?
xPloit Posted September 23, 2010 Author Posted September 23, 2010 I tried to do IniRead() but I couldn't quite get that to work. Obviously what I'm doing now doesn't work either, but it's really close. I'm having much better luck with _ReadFileToArray so I have just stuck with that... 00101101011110000101000001101100011011110110100101110100
omikron48 Posted September 23, 2010 Posted September 23, 2010 (edited) Using your sample file format in post #8:Global $inifile ;contains the file path of your .ini file Global $section = "Intro_To_ATC_2" Global $key = "CLC" Global $value = IniRead($inifile, $section, $key, "ERROR") Msgbox(0x2000, $key, $value) Edited September 23, 2010 by omikron48
smashly Posted September 23, 2010 Posted September 23, 2010 (edited) Hi, Probably doesn't help you, but I had a go at writing your code. Load your Ini from the Gui or set a path to the ini in the script. Select the Classes you want then hit start quiz. (Class is Section name in your ini anything under that Section name is in that Class) Words from the classes selected will be jumbled and displayed 1 by 1 Word is displayed at the top of the Gui. Double Click the matching description in the listview below. I used your ini you posted in an earlier post to test it with. If your using that ini then you have one Class (Intro To ATC 2) Add more Sections to have more classes. Note: there's no error checking if a Section doesn't have keys and values in it..expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Global $Ini = @ScriptDir & "\FlashCards.ini" Global $iWait = 2000, $iShowWait = 2000 ;Sleep times Global $iWaitColor = 0x000000, $iCorrectColor = 0x00EE00, $iWrongColor = 0xFF0000, $iShowColor = 0x0000FF ;Text colors for Status msg Global $hGui, $iWord, $iStatus, $iDescrption, $iClass, $iStartQuiz, $iShowAnswer, $iEditIni, $iLoadIni, $iMsg Global $sWinTitle = "Flash Card Quiz" Global $sStart = "Start Quiz", $sStop = "Stop Quiz" Global $sCorrect = "Correct Answer", $sWrong = "Wrong Answer", $sShow = "Showing Correct Answer" Global $sWaitAnswer = "Waiting For Answer" Global $aFlash, $aQuiz, $iLastHit = -1, $iLastIndex = 1 Global $iCorrect = 0, $iWrong = 0 $hGui = GUICreate($sWinTitle, 575, 400, -1, -1) GUICtrlCreateGroup("Word", 5, 5, 390, 50) $iWord = GUICtrlCreateLabel("", 10, 20, 380, 30, $SS_CENTER) GUICtrlSetFont(-1, 20, 700, 0, "Arial", 5) GUICtrlCreateGroup("Status", 400, 5, 170, 50) $iStatus = GUICtrlCreateLabel("", 405, 25, 160, 20, $SS_CENTER) GUICtrlSetFont(-1, 11, 400, 0, "Arial", 5) $iDescrption = GUICtrlCreateListView("Descriptions", 5, 60, 390, 335) $iClass = GUICtrlCreateListView("Select Classes", 400, 60, 170, 215, -1, $LVS_EX_CHECKBOXES) $iStartQuiz = GUICtrlCreateButton($sStart, 400, 310, 170, 25); $iShowAnswer = GUICtrlCreateCheckbox("Show answer when wrong", 400, 280, 170, 25) GUICtrlSetState(-1, $GUI_CHECKED) $iEditIni = GUICtrlCreateButton("Edit INI", 400, 340, 170, 25) $iLoadIni = GUICtrlCreateButton("Load INI", 400, 370, 170, 25) GUISetState(@SW_SHOW, $hGui) _LoadIni() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE Exit Case $iStartQuiz _ToggleStartStop() Case $iEditIni ShellExecute("notepad.exe", $Ini) Case $iLoadIni _LoadIni(1) Case Else If $iLastHit <> -1 Then _CheckWord() EndSwitch WEnd Func _ToggleStartStop() If GUICtrlRead($iStartQuiz) = $sStart Then _CreateQuiz() Else _EndQuiz() EndIf EndFunc ;==>_ToggleStartStop Func _EndQuiz() MsgBox(64, "Results", "Words Displayed: " & $iLastIndex & @LF & _ "Correct Answers: " & @TAB & $iCorrect & " of " & $aQuiz[0][0] & @LF & _ "Wrong Answers: " & @TAB & $iWrong & " of " & $aQuiz[0][0]) _LoadIni() EndFunc ;==>_EndQuiz Func _CheckWord() Local $iLH = $iLastHit + 1 If $aQuiz[$iLH][0] = GUICtrlRead($iWord) Then GUICtrlSetColor($iStatus, $iCorrectColor) GUICtrlSetData($iStatus, $sCorrect) $iCorrect += 1 Else GUICtrlSetColor($iStatus, $iWrongColor) GUICtrlSetData($iStatus, $sWrong) $iWrong += 1 If GUICtrlRead($iShowAnswer) = 1 Then Sleep($iWait) GUICtrlSetColor($iStatus, $iShowColor) GUICtrlSetData($iStatus, $sShow) For $i = 1 To $aQuiz[0][0] If $aQuiz[$i][0] = GUICtrlRead($iWord) Then _GUICtrlListView_Scroll($iDescrption, 0, _GUICtrlListView_GetItemPositionY($iDescrption, $i - 1) - 16) _GUICtrlListView_SetItemSelected($iDescrption, $i - 1, True, True) $iLastHit = $i - 1 ExitLoop EndIf Next Sleep($iShowWait) EndIf EndIf Sleep($iWait) GUICtrlSetColor($iStatus, $iWaitColor) GUICtrlSetData($iStatus, $sWaitAnswer) _GUICtrlListView_SetItemSelected($iDescrption, $iLastHit, False) $iLastHit = -1 If $iLastIndex = $aQuiz[0][0] Then Return _EndQuiz() $iLastIndex += 1 GUICtrlSetData($iWord, $aQuiz[$iLastIndex][2]) WinSetTitle($hGui, "", $sWinTitle & " - Word " & $iLastIndex & " of " & $aQuiz[0][0]) EndFunc ;==>_CheckWord Func _CreateQuiz() Local $aTmp1, $iQuiz = 0, $sTmp1, $iRan If Not IsArray($aFlash) Or Not _CheckClassSelected() Then Return SetError(1, 0, 0) GUICtrlSetData($iStartQuiz, $sStop) Dim $aQuiz[1][3] For $i = 0 To _GUICtrlListView_GetItemCount($iClass) - 1 If _GUICtrlListView_GetItemChecked($iClass, $i) Then $aTmp1 = $aFlash[$i + 1][1] If IsArray($aTmp1) Then $iQuiz = $aQuiz[0][0] ReDim $aQuiz[$iQuiz + $aTmp1[0][0] + 1][3] $aQuiz[0][0] += $aTmp1[0][0] For $j = 1 To $aTmp1[0][0] $aQuiz[$iQuiz + $j][0] = $aTmp1[$j][0] $aQuiz[$iQuiz + $j][1] = $aTmp1[$j][1] Next EndIf EndIf Next For $i = 1 To $aQuiz[0][0] GUICtrlCreateListViewItem($aQuiz[$i][1], $iDescrption) Do $iRan = Random(1, $aQuiz[0][0], 1) Until (Not StringInStr($sTmp1, "," & $iRan & ",")) And $iRan <> $i $sTmp1 &= $iRan & "," $aQuiz[$i][2] = $aQuiz[$iRan][0] Next _GUICtrlListView_SetColumnWidth($iDescrption, 0, $LVSCW_AUTOSIZE) GUICtrlSetData($iStatus, $sWaitAnswer) GUICtrlSetData($iWord, $aQuiz[$iLastIndex][2]) WinSetTitle($hGui, "", $sWinTitle & " - Word " & $iLastIndex & " of " & $aQuiz[0][0]) EndFunc ;==>_CreateQuiz Func _CheckClassSelected() For $i = 0 To _GUICtrlListView_GetItemCount($iClass) - 1 If _GUICtrlListView_GetItemChecked($iClass, $i) Then Return 1 Next Return 0 EndFunc ;==>_CheckClassSelected Func _LoadIni($iFlag = 0) Local $sFOD, $aIRSN, $aIRS If $iFlag Then $sFOD = FileOpenDialog("Select an INI to open", "", "Flash Card (*.ini)", 3, "", $hGui) If @error Then Return SetError(2, 0, 0) $Ini = $sFOD EndIf $aIRSN = IniReadSectionNames($Ini) If @error Then Return SetError(1, 0, 0) Dim $aFlash[$aIRSN[0] + 1][2] $aFlash[0][0] = $aIRSN[0] _GUICtrlListView_DeleteAllItems($iClass) _GUICtrlListView_DeleteAllItems($iDescrption) $iCorrect = 0 $iWrong = 0 $iLastIndex = 1 GUICtrlSetColor($iStatus, $iWaitColor) GUICtrlSetData($iStatus, "") GUICtrlSetData($iWord, "") GUICtrlSetData($iStartQuiz, $sStart) For $i = 1 To $aIRSN[0] $aFlash[$i][0] = $aIRSN[$i] GUICtrlCreateListViewItem(StringReplace($aIRSN[$i], "_", " "), $iClass) $aFlash[$i][1] = IniReadSection($Ini, $aIRSN[$i]) Next _GUICtrlListView_SetColumnWidth($iClass, 0, $LVSCW_AUTOSIZE) WinSetTitle($hGui, "", $sWinTitle) EndFunc ;==>_LoadIni Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hLV, $aHit $hLV = GUICtrlGetHandle($iDescrption) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hLV Switch $iCode Case $NM_DBLCLK $aHit = _GUICtrlListView_HitTest($hLV) $iLastHit = $aHit[0] EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edit: Forgot to add an end check to the quiz. Cheers Edited September 23, 2010 by smashly
JoHanatCent Posted September 23, 2010 Posted September 23, 2010 expandcollapse popup#include <file.au3>; <<====== #Include <GUIConstants.au3> AutoItSetOption("MustDeclareVars",1) AutoItSetOption("GUIOnEventMode",1) Global $Correct = 0 Global $Wrong = 0 Global $CardsShown = 0 Global $aArray;<<======= Dim $key;<<====== Global $Split;<<======= #Include <Array.au3> ;<< ====== Only to display the $aArray Global $GUI = GUICreate("Flash Card Tester",280,50) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $StartQuiz = GUICtrlCreateButton("Start Quiz",10,10,70,30) GUICtrlSetOnEvent($StartQuiz,"_Quiz") Global $AddNew = GUICtrlCreateButton("Add New Cards",90,10,90,30) GUICtrlSetOnEvent($AddNew,"_AddNew") Global $Exit = GUICtrlCreateButton("Exit",210,10,50,30) GUICtrlSetOnEvent($Exit,"_Close") Global $AddGUI = GUICreate("Add New",200,100) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") Global $NewWord = GUICtrlCreateInput("Word",10,10,180,20) Global $NewDef = GUICtrlCreateInput("Definition",10,40,180,20) Global $AddDone = GUICtrlCreateButton("Add",30,70,50,20) GUICtrlSetOnEvent($AddDone,"_AddDone") Global $Return0 = GUICtrlCreateButton("Return",90,70,50,20) GUICtrlSetOnEvent($Return0,"_Return") Global $TestGUI = GUICreate("Flash Card Tester",280,100) GUISetOnEvent($GUI_EVENT_CLOSE,"_Close") ;Global $Key = IniRead("FlashCards.ini","Intro_to_ATC_2",Random(),0) ;Random() doesn't get a random key... ;>>============= To Array and Randomize Here If Not _FileReadToArray("FlashCards.ini", $aArray) Then MsgBox(4096, "Error", "Error reading file to Array error:" & @error) Exit EndIf $key=Random(1,$aArray[0],1) ; 0 is how many records MsgBox(0,"Show:","Records in INI file >> " & $aArray[0] & @lf & "Current Rand number $key = "& $key & @LF & $aArray[$Key]) $Split = StringSplit($aArray[$Key], "=") ;_ArrayDisplay($Split) msgbox(0, "A Split:", "First part: " & $Split[1] & @lf &@lf &@tab & "Second part: " & $Split[2]) ;<<============ End Here Global $Word = GUICtrlCreateLabel(IniRead("FlashCards.ini","Intro_to_ATC_2",$Key,0),10,10,120,50) Global $Def = GUICtrlCreateInput("",100,8,170,20) Global $NumCorrect = GUICtrlCreateLabel("Correct -- " & $Correct,10,40,70,30) Global $NumWrong = GUICtrlCreateLabel("Wrong -- " & $Wrong,10,55,70,30) Global $Percentage = GUICtrlCreateLabel("% Correct -- " & (100 * ($Correct / $CardsShown)),10,70,150,30) Global $Submit = GUICtrlCreateButton("Show Answer",100,35,170,20) GUICtrlSetOnEvent($Submit,"_ShowAnswer") Global $Return = GUICtrlCreateButton("Return",190,70,80,20) GUICtrlSetOnEvent($Return,"_Return") GUISetState(1,$GUI) While 1 Sleep(10) WEnd Func _Quiz() GUISetState(0,$GUI) GUISetState(1,$TestGUI) EndFunc Func _AddNew() GUISetState(0,$GUI) GUISetState(1,$AddGUI) EndFunc Func _AddDone() IniWrite("FlashCards.ini","Intro_To_ATC_2",GUICtrlRead($NewWord),GUICtrlRead($NewDef)) GUICtrlSetData($NewWord,"Word") GUICtrlSetData($NewDef,"Definition") TrayTip("Flash Card Tester","Flash card has been added",5) EndFunc Func _Return() GUISetState(0) GUISetState(1,$GUI) EndFunc Func _ShowAnswer() $CardsShown += 1 Global $Choice = MsgBox(4,"Answer","The answer is :" & IniRead("FlashCards.ini","Intro_to_ATC_2",$Key,0) & @CRLF & @CRLF & "Did you get it right?") ;The IniRead() has a problem because of $Key, so if it is fixed above, I can fix it here If $Choice = 6 Then ;$Correct += 1 ;Doesn't add 1 to the $Correct label... ElseIf $Choice = 7 Then ;$Wrong += 1 ;Doesn't add 1 to the $Wrong label... EndIf EndFunc Func _Close() Exit EndFuncAdded a few more lines in to split the text. Not saying this is ideal but working with your INI file layout. Obviousely you will have to put the code in its correct place.
xPloit Posted September 23, 2010 Author Posted September 23, 2010 smash, I didn't try your script, so I'm not sure if it works. Sorry for having you do all that and then I completely ignore it Johan's script works so I did edits on that to get everything working the way I wanted it to. Once I get everything (load/save and a few other quick fixes) I'll post the final script. I can't believe I had the right function before, but couldn't get it to work, lol >.< 00101101011110000101000001101100011011110110100101110100
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