Quick Question on Array - Cannot find the string issue

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
hellotherenjny
Posts: 8
Joined: 17 Oct 2021, 10:49

Quick Question on Array - Cannot find the string issue

26 Oct 2021, 08:47

Hello,

Thanks always for the help!

I have a quick question. Somehow, this keeps on returning "Not in the list" while, Value (00004) and Zero(0) should return (000040) and find it in the array. Can you help how I can solve this?

Thanks a lot!

Code: Select all

^3::
	Array := ["000020","000040"]
	
	Value := 00004
	Zero := 0
	
	msgbox, %Value%
	msgbox, %Value%%Zero%
	
	Loop, % Array.Length()	{
		if( Array[ A_index ] = %Value%%Zero% ) 
			msgbox, "In the list"
		}
		msgbox, "Not in the list"
	return
User avatar
mikeyww
Posts: 26888
Joined: 09 Sep 2014, 18:38

Re: Quick Question on Array - Cannot find the string issue

26 Oct 2021, 09:25

Code: Select all

Value := 00004
Zero  := 0
found := "False"
For each, item in ["000020", "000040"]
 If (item = Value Zero)
  found := "True"
MsgBox, 64, Result, %found%
Explained: IfExpressions
User avatar
Chunjee
Posts: 1420
Joined: 18 Apr 2014, 19:05
Contact:

Re: Quick Question on Array - Cannot find the string issue

26 Oct 2021, 12:45

Perplexing I know but ahk does not come with an .includes or .indexOf method.

You may add them with array.ahk
https://chunjee.github.io/array.ahk/#/docs?id=includes
https://chunjee.github.io/array.ahk/#/docs?id=indexof

Code: Select all

; requires https://www.npmjs.com/package/array.ahk
Array := ["000020","000040"]

if (Array.includes("000020")) {
	msgbox, % "has!"
}

Array.includes("z")
; => false

Array.indexOf("000040")
; => 2

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, Frogrammer, Google [Bot] and 275 guests