WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: cssyphus on May 17, 2024, 08:45:30 AM

Title: What is correct method to determine if a map key exists?
Post by: cssyphus on May 17, 2024, 08:45:30 AM
What is the correct way to determine if a map element exists?

For example, the isDefined() test generates an "Array subscript out of bounds" error:

_Lst = `Ann,1` :@TAB: `Bob,2` :@TAB: `Carl,3`
_map = MapCreate(_Lst)
if isDefined(_map[`Bob`])
message(`Bob is in pos`, _map[`Bob`])
endif
if isDefined(_map[`Fred`])
message(`Fred is in pos`, _map[`Fred`])
endif

Title: Re: What is correct method to determine if a map key exists?
Post by: td on May 17, 2024, 09:43:20 AM

MapKeyExist (https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/MapKeyExist.htm)
Title: Re: What is correct method to determine if a map key exists?
Post by: cssyphus on May 18, 2024, 05:31:29 AM
I'm going with: "that wasn't in MY copy of the help file when I looked at it yesterday..." But it's there now. Spooky. Mandela effect?

Thanks Tony.

Man, if I had an extra minute of life for every hour I've spent searching for something that is right under my nose (and often not finding it)... I'd live forever.
Title: Re: What is correct method to determine if a map key exists?
Post by: td on May 18, 2024, 03:37:37 PM
My wife calls it refrigerator blindness...
Title: Re: What is correct method to determine if a map key exists?
Post by: kdmoyers on May 19, 2024, 08:01:59 AM
I appear to be nearly blind to my own typos.  It's a bummer.
Title: Re: What is correct method to determine if a map key exists?
Post by: snowsnowsnow on May 22, 2024, 05:10:08 AM
Quote from: td on May 18, 2024, 03:37:37 PMMy wife calls it refrigerator blindness...

I first heard that term in a comedy routine by Rita Rudner.

She's great.  I love her.