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

Get help with using AutoHotkey and its commands and hotkeys
Dtiv19
Posts: 2
Joined: 12 Jul 2019, 11:36

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

12 Jul 2019, 12:27

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!
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

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

12 Jul 2019, 13:09

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.
awel20
Posts: 211
Joined: 19 Mar 2018, 14:09

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

12 Jul 2019, 13:30

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
wolf_II
Posts: 2688
Joined: 08 Feb 2015, 20:55

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

12 Jul 2019, 14:29

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.
Dtiv19
Posts: 2
Joined: 12 Jul 2019, 11:36

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

12 Jul 2019, 15:22

Thank you very much for your responses ! It works perfectly now

Return to “Ask For Help”

Who is online

Users browsing this forum: cheatH12, Google [Bot], mikeyww, Pavel, renega and 56 guests