Page 1 of 1

If if two strings are equal (words/sentences not numbers) - Can't figure out how to trigger then

Posted: 12 Jul 2019, 12:27
by Dtiv19
Hi all,
I can't figure out why "if (userinput=word)" is not triggering It's corresponding "then".
Here is my code -



file := "M:My\txtfile\location.txt" ; location of word list
FileRead, LoadedText, %file% ; load list
Sort, LoadedText, random ; randomize words in list
Stringsplit, Array, LoadedText,`n ; Split into array
Loop, ; Get words one at a time
{
Word = % Array%A_Index%
Loop, ; Prompt the current word
{
InputBox, UserInput,%Word%,, , 300,100,0,880
if (Userinput = "End") ; Provide an exit
Exitapp
if (userinput=word) ;**Move on to the next word
Break
else ;Continue prompting same word
Continue
}
}
Exitapp




The goal is to make a flashcard script that takes words from a text file, prompts them in a random order, and moves onto the next word only after writing the prompted word into the userinput box (if it was real flashcards the front and the back would have the same words on them). I want to use the script to practice custom text expansions.

I've tried every combination of %'s and :='s and searched for the solution in as many ways as I can think to phrase it with no success if someone could point me in the right direction I'd greatly appreciate it!

Re: If if two strings are equal (words/sentences not numbers) - Can't figure out how to trigger then

Posted: 12 Jul 2019, 13:09
by MannyKSoSo

Code: Select all

file := "M:My\txtfile\location.txt" ; location of word list 
FileRead, LoadedText, %file%	; load list 
Sort, LoadedText, random	; randomize words in list
arrWords := StrSplit(LoadedText, "`r`n")
for i,v in arrWords {
	InputBox, UserInput,v,, , 300,100,0,880
	if (Userinput = "End")	; Provide an exit 
		Exitapp 
	if (Userinput = v) ;**Move on to the next word 
		Break 
	else	;Continue prompting same word 
		Continue 
}
Exitapp 
Untested, but since you used stringsplit the newer method is easier to use. Also you stuff may have had `r`n instead of `n (but change the split by what you need it). This could also be why it never matched.

Re: If if two strings are equal (words/sentences not numbers) - Can't figure out how to trigger then  Topic is solved

Posted: 12 Jul 2019, 13:30
by awel20

Code: Select all

file := "M:My\txtfile\location.txt" ; location of word list 
FileRead, LoadedText, %file% ; load list
Sort, LoadedText, random ; randomize words in list
Loop, Parse, LoadedText, `n, `r
{
    Loop
    {
        InputBox, UserInput, % A_LoopField,,, 300,100,0,880
        if (ErrorLevel = 1) ; user pressed cancel
            break 2
        else if (UserInput = A_LoopField) ; correct word. move to next word
            break
        else ; wrong word. repeat same word
            continue
    }
}
ExitApp

Re: If if two strings are equal (words/sentences not numbers) - Can't figure out how to trigger then

Posted: 12 Jul 2019, 14:29
by wolf_II
check with MsgBox what LoadedText contains.
then correct the path.

replace file := "M:My\txtfile\location.txt"
with file := "M:\My\txtfile\location.txt"

also untested.

Re: If if two strings are equal (words/sentences not numbers) - Can't figure out how to trigger then

Posted: 12 Jul 2019, 15:22
by Dtiv19
Thank you very much for your responses ! It works perfectly now