1. Tracy Lamb
  2. PowerBuilder
  3. Sunday, 5 June 2022 12:20 PM UTC

Hi all,

I've got an array of numbers.  I'd like to find out if a particular number is in the array, and if it's there, remove that element from the array.

Right now I do it manually, by looping through the array.  It's not very big array, just thought there might be a more "elegant" way to accomplish the same thing.

// Remove this workorder from the global list of open WOs

ll_upper = Upperbound( gl_dde_datasheets )
if ll_upper > 0 then
   ll_CopyTo = 1
   for ll_ThisOne = 1 to ll_upper
      if gl_dde_datasheets[ ll_ThisOne ] <> al_FormID then
         ll_temp[ ll_CopyTo ] = gl_dde_datasheets[ ll_ThisOne ]
         ll_CopyTo++
      end if
   next

   gl_dde_datasheets = ll_Temp

end if

~~~Tracy

Accepted Answer
Roland Smith Accepted Answer Pending Moderation
  1. Monday, 6 June 2022 19:51 PM UTC
  2. PowerBuilder
  3. # Permalink

Standard arrays don't have the ability to remove entries. The only way to do that would be to loop through the array copying each entry to a new array and skipping over the one you want to remove.

 

Comment
  1. Tracy Lamb
  2. Friday, 10 June 2022 20:32 PM UTC
Thank you. That's what I'm doing and thought it might be the only way unless there were some array functions I might be missing. The array is usually only 1-5 entries.

~~~Tracy

  1. Helpful
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Monday, 6 June 2022 17:53 PM UTC
  2. PowerBuilder
  3. # 1

If >>> ALL <<< you want to do to the data is delete entries with specific values, the loop is the fastest method.

If you anything more than that, then going with the external datawindow as mentioned above is the way to go!

Comment
There are no comments made yet.
Tracy Lamb Accepted Answer Pending Moderation
  1. Sunday, 5 June 2022 14:40 PM UTC
  2. PowerBuilder
  3. # 2

Thanks Chris and Miguel,

your solutions sound good, but the array is usually only 1 or 2 values, sometimes maybe 4 or 5.  There's a lot of overhead in your solutions. Besides, the array is used by DDE Clients so a datastore or datawindow wouldn't work. 

~~~Tracy

Comment
  1. John Fauss
  2. Sunday, 5 June 2022 17:15 PM UTC
TCP/IP or Windows sockets. Roland's TopWizProgramming website has a free code example for using WinSockets.

Miguel's suggestion to consider use a string that contains the ID values is a good idea and I've used it before, but depending on the data values you may wish to include a prefix/suffix to each ID.

For example, if the ID string contains "123 12" and you issue a Pos function looking for "12", it would return the position of "123" instead of the position of "12". FWIW, I always delimit the ID values with "pipe" (|) characters or asterisks, as in "|123| |12|", then perform a search for the a value that includes the delimiters, for example "|12|". This prevents false positive results. Did you resolve your earlier question regarding using DDE events in a DWC or Tab control?
  1. Helpful
  1. Tracy Lamb
  2. Sunday, 5 June 2022 18:48 PM UTC
Thanks for your comment John,

I haven't tried your earlier suggestion for DDE events... I only use DDE in one window, so it was faster to just put the code in the window. I will look further into creating a window service in the future, when I have a little more time.

~~~Tracy
  1. Helpful
  1. Mark Goldsmith
  2. Sunday, 5 June 2022 19:03 PM UTC
Hi Tracy...in addition to John's suggestion re Windows Sockets, I believe that LabView is also COM enabled (ActiveX) both as a client and as a server (so you would use PB's ConnectToObject and/ or ConnectToNewObject) and so there's probably some options there for communicating back and forth... assuming you had access to the LabView code but if not, implementing something new on the LabView side.



Regards,



Mark
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Sunday, 5 June 2022 12:28 PM UTC
  2. PowerBuilder
  3. # 3

Hi Tracy;

  FWIW: I would use an external DataWindow to load the array data into instead. Then use the DW's Find() command (not to mention Sort as well) to locate the element your looking for.

    You could also load the array in Ascending or Descending sequence. Then use a Binary Search logic in your PowerScript.

HTH

Regards ... Chris 

Comment
  1. Miguel Leeuwe
  2. Sunday, 5 June 2022 14:02 PM UTC
Yes, that's the 100% best solution.

Having your data in a datastore / datawindow, gives you all the advantages of being able to filter(), sort(), etc. Maybe you could insert your data in the datastore to start with, omitting the initial use of an array altogether.

regards.
  1. Helpful
  1. Roland Smith
  2. Monday, 13 June 2022 13:42 PM UTC
I use a datastore with datawindow created 'on the fly' to sort the contents of string arrays.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.