InStr always returning TRUE!!!!!

Get help with using AutoHotkey and its commands and hotkeys
drizzt
Posts: 31
Joined: 20 Apr 2018, 20:44

InStr always returning TRUE!!!!!

26 Mar 2019, 14:01

hello,

I created a text database called Catalog_DB.txt that only has two fields per a line, then a carriage return for example

car 11223
bicycle 11239
stereo 32111

I am trying to search the file but no matter what I type it finds it even if its not there.

here is the code

Code: Select all

Loop, read, Catalog_DB.txt
{
	Loop, parse, A_LoopReadLine, `n
	{
		if	InStr (A_LoopField, "monkey")
			Msgbox, string found
		else 
			Msgbox, not found
	}
}

no matter what I enter, it always returns "string found"

Moderator Note: Indented code. ~ sinkfaze
CloakerSmoker
Posts: 29
Joined: 07 Sep 2018, 15:54

Re: InStr always returning TRUE!!!!!

26 Mar 2019, 14:12

You have a space between InStr and (A_LoopField, "monkey"), remove the space and it should work.
drizzt
Posts: 31
Joined: 20 Apr 2018, 20:44

Re: InStr always returning TRUE!!!!!

26 Mar 2019, 14:24

I removed the space. Problem still there.
CloakerSmoker
Posts: 29
Joined: 07 Sep 2018, 15:54

Re: InStr always returning TRUE!!!!!

26 Mar 2019, 14:34

Are you 100% sure about that? When I run that code with the space (On some random file which doesn't contain "monkey") I only get the "string found" message box, and when I run it without that space I never get the found message box.
Did you forget to save the file?
User avatar
sinkfaze
Posts: 614
Joined: 01 Oct 2013, 08:01

Re: InStr always returning TRUE!!!!!

26 Mar 2019, 14:37

I tested your original code and with CloakerSmoker's suggested fix, yours fails as expected and his works as expected. You need to look back over your code and make sure you've reloaded the script with the fix.
User avatar
JoeWinograd
Posts: 1537
Joined: 10 Feb 2014, 20:00

Re: InStr always returning TRUE!!!!!

26 Mar 2019, 14:54

Tested here, too...got same results as CloakerSmoker and sinkfaze. If it still fails for you after making the code change and re-running the script, it's possible that your text file is such that the script needs to look for carriage return, so try changing your Loop, parse, A_LoopReadLine, `n to Loop, parse, A_LoopReadLine, `n, `r. Regards, Joe

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], bjukrain, boiler, CarPiotr, coder_chick, DaveT1, hackkk745 and 47 guests