News:

  • June 27, 2026, 09:42:27 PM

Login with username, password and session length

Author Topic: Implement a table search in Do-More  (Read 8223 times)

rockhead

  • Newbie
  • *
  • Posts: 5
Implement a table search in Do-More
« on: November 09, 2016, 10:53:02 AM »
I'm working on my 1st project with Do-More. I have a memory address setup to hold a number entered from a touchscreen (Part Number). I have a table of 40 values (Part Number List) that will be searched for a match to the entered value. I need to know the index position of the match (Position 10 in the table). I was able to accomplish this easily using the FIND instruction in DS5. I see there is no equivalent to this instruction in Do-More right now. I was thinking I might be able to accomplish this using a FOR-NEXT loop but was wondering if there might be other alternatives.

BobO

  • Host Moderator
  • Hero Member
  • *****
  • Posts: 6164
  • Yes Pinky, Do-more will control the world!
Re: Implement a table search in Do-More
« Reply #1 on: November 09, 2016, 11:26:02 AM »
We are definitely adding table functions in the future, but for now the best bet is some form of loop iterator.

One big benefit of looping in Do-more is the yielding mechanism: all looping instructions test the execution time at the bottom of the loop, and if it exceeds the specified time slice for that task or program block, it suspends the operation and picks up next scan. If the time slice value for a task or program block is 65535 (the max), it does not do the yield test. By default, only $Main's slice is 65535 (it can be changed) and all others will yield. So with that in mind, the preferred way to do a search is to put the search code into a dedicated task, and one-shot enable the task any time you need to do the search.

If your table is always small, it's no big deal to put it inline and not do the task thing...however...loops can hit scan time pretty hard, and do so much quicker than you expect.

Sorry for the inconvenience. We understand the importance of table functions and had hoped to get them into our next release, but the new hardware under development has been a monumental effort for us and forced certain features further into the future.
"It has recently come to our attention that users spend 95% of their time using 5% of the available features. That might be relevant." -BobO

plcnut

  • Hero Member
  • *****
  • Posts: 814
    • premiersi.com
Re: Implement a table search in Do-More
« Reply #2 on: November 09, 2016, 11:49:20 AM »
Here is how I do it.
Circumstances don't determine who we are, they only reveal it.

~Jason Wolthuis
Premier Systems Integration, LLC
http://premiersi.com

rockhead

  • Newbie
  • *
  • Posts: 5
Re: Implement a table search in Do-More
« Reply #3 on: November 09, 2016, 01:34:31 PM »
Thanks for the replies guys.

BobO: I was planning on putting this in a task since it will only need to run occasionally. I will keep the time slice feature in mind as I work things out. And this is really not an inconvenience. A little challenge for the brain is never bad. As you know, in programming there is always more than one way to skin a cat. I understand everything can't get done at once and that some things must take precedence over others.

plcnut: Your code looks even simpler than what I was thinking of doing. (Even simpler than using FIND in DS5) Thanks for the example.

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3612
  • Darth Ladder
Re: Implement a table search in Do-More
« Reply #4 on: November 14, 2016, 01:07:17 PM »
Or you can either sort the table and use COUNTIFxx, or create a one-column index table.   This doesn't save you anything if you have to continuously reindex, but someone suggested doing a CHECKSUM on the table data to tell when it had changed (in another application).  If you do that, then you only reindex or resort when needed.
I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.