
Quote from Phil78 on September 21, 2021, 5:14 pmHi All
I would like to know if it is possible to use ArraySearch with an Object, unless my syntax is bad, because when I try there is a crash :
"Uncaught TypeError: str is undefined" or "Uncaught TypeError: a is undefined"
example mydata : id, name, surname, age
ArraySearch [mydata('name')] "Kate" [position] or ArraySearch [mydata.name] "Kate" [position]
Hi All
I would like to know if it is possible to use ArraySearch with an Object, unless my syntax is bad, because when I try there is a crash :
"Uncaught TypeError: str is undefined" or "Uncaught TypeError: a is undefined"
example mydata : id, name, surname, age
ArraySearch [mydata('name')] "Kate" [position] or ArraySearch [mydata.name] "Kate" [position]

Quote from luishp on September 21, 2021, 5:46 pm@phil78 you are using objects as if they were Arrays? Note that they are different things.
This will work:CreateEmptyObject [mydata] SetVar [mydata.name] "My name is Kate Holmes" SearchStr "Kate" "[mydata.name]" [position]Regards.
@phil78 you are using objects as if they were Arrays? Note that they are different things.
This will work:
CreateEmptyObject [mydata] SetVar [mydata.name] "My name is Kate Holmes" SearchStr "Kate" "[mydata.name]" [position]
Regards.

Quote from Phil78 on September 21, 2021, 7:48 pmI do not have any result with SearchStr. My object is mydata from example neoTableTutorialPart1.
As we use Arraylen to know the number of entries of the object, that's why I thought to use ArraySearch
I do not have any result with SearchStr. My object is mydata from example neoTableTutorialPart1.
As we use Arraylen to know the number of entries of the object, that's why I thought to use ArraySearch

Quote from luishp on September 22, 2021, 7:02 am@phil78 note that you are using an Array of Objects. Just use a loop to iterate all the Array items and use SearchStr to find those that match your string search. If I find time I would try to attach an example later.
Regards.
@phil78 note that you are using an Array of Objects. Just use a loop to iterate all the Array items and use SearchStr to find those that match your string search. If I find time I would try to attach an example later.
Regards.

Quote from luishp on September 22, 2021, 10:36 amHi again @phil78, please take a look at the attached sample.
What I have done:Create alll the data in Project > Events:
CreateEmptyArray [data] Loop 0 5 [n] CreateEmptyObject [data([n])] EndLoop SetVar [data(0).name] "Peter" SetVar [data(1).name] "Ursula" SetVar [data(2).name] "Sandra" SetVar [data(3).name] "John" SetVar [data(4).name] "Carmen" SetVar [data(5).name] "Lara" SetVar [data(0).surname] "Andrews" SetVar [data(1).surname] "Clark" SetVar [data(2).surname] "Strongarm" SetVar [data(3).surname] "Carpenter" SetVar [data(4).surname] "Miranda" SetVar [data(5).surname] "Conrado"Add a TextInput field whose Variable is [textToSearch]
Add a Container to show [name] and [surname]
Add a button to fire the search functionality:
SetVar [name] "" SetVar [surname] "" ArrayLen [data] [total] Loop 0 [total] [n] StrSearch "[textToSearch]" "[data([n]).name]" [position] If [position] > -1 SetVar [name] [data([n]).name] SetVar [surname] [data([n]).surname] ExitLoop EndIf EndLoopIt's important to understand that we are searching within a text string (name), that is field of an Object, that is an element in a Array. I hope it helps :)
Regards.
Hi again @phil78, please take a look at the attached sample.
What I have done:
Create alll the data in Project > Events:
CreateEmptyArray [data] Loop 0 5 [n] CreateEmptyObject [data([n])] EndLoop SetVar [data(0).name] "Peter" SetVar [data(1).name] "Ursula" SetVar [data(2).name] "Sandra" SetVar [data(3).name] "John" SetVar [data(4).name] "Carmen" SetVar [data(5).name] "Lara" SetVar [data(0).surname] "Andrews" SetVar [data(1).surname] "Clark" SetVar [data(2).surname] "Strongarm" SetVar [data(3).surname] "Carpenter" SetVar [data(4).surname] "Miranda" SetVar [data(5).surname] "Conrado"
Add a TextInput field whose Variable is [textToSearch]
Add a Container to show [name] and [surname]
Add a button to fire the search functionality:
SetVar [name] ""
SetVar [surname] ""
ArrayLen [data] [total]
Loop 0 [total] [n]
StrSearch "[textToSearch]" "[data([n]).name]" [position]
If [position] > -1
SetVar [name] [data([n]).name]
SetVar [surname] [data([n]).surname]
ExitLoop
EndIf
EndLoop
It's important to understand that we are searching within a text string (name), that is field of an Object, that is an element in a Array. I hope it helps :)
Regards.
Uploaded files:
Quote from Phil78 on September 22, 2021, 4:50 pm@luishp Thank you again Luis. I was thinking there was a predefined function. It is perfect for me.
with your example I have add this expression because array start with 0
Math "[total]-1" 0 [total]
Best regards
@luishp Thank you again Luis. I was thinking there was a predefined function. It is perfect for me.
with your example I have add this expression because array start with 0
Math "[total]-1" 0 [total]
Best regards

Quote from IoSoft on April 21, 2022, 12:32 pmHello everyone, I would like to know if, using this example that Luis presented, is there a code to continue with the search, that is, to place the "find next" function on the button (for the rest of the matches)?
THANK YOU
Hello everyone, I would like to know if, using this example that Luis presented, is there a code to continue with the search, that is, to place the "find next" function on the button (for the rest of the matches)?
THANK YOU

Quote from luishp on April 21, 2022, 2:15 pm@iosoft take a look at the main loop:
Loop 0 [total] [n]It searches from the first array element 0 to the last one [total] and stores the current position being searched on [n]
When you find an occurrence, just before the ExitLoop, store [n] plus 1 in a new variable (for instance [s])
SetVar [s] [n]+1So you can start next search in [n]+1 position, that's the next one to the last match occurrence:
Loop [s] [total] [n]Just remember to initialize [s] to 0 the first time you use this new loop.
Regards.
@iosoft take a look at the main loop:
Loop 0 [total] [n]
It searches from the first array element 0 to the last one [total] and stores the current position being searched on [n]
When you find an occurrence, just before the ExitLoop, store [n] plus 1 in a new variable (for instance [s])
SetVar [s] [n]+1
So you can start next search in [n]+1 position, that's the next one to the last match occurrence:
Loop [s] [total] [n]
Just remember to initialize [s] to 0 the first time you use this new loop.
Regards.

Quote from IoSoft on April 21, 2022, 2:34 pmSpectacular! Now I was able to specify what I was looking for.
Thank you so much
Cheers
Spectacular! Now I was able to specify what I was looking for.
Thank you so much
Cheers