News:

  • June 25, 2026, 11:58:07 AM

Login with username, password and session length

Author Topic: Copying values across a range of structures  (Read 10936 times)

ElroyJetson

  • Full Member
  • ***
  • Posts: 36
Copying values across a range of structures
« on: March 23, 2017, 09:00:18 AM »
Is there a way to copy a value of one structure elements to a range of values in other structure elements?
What I am doing is creating multiple UDT's, and I need to do compares and differences of those UDTs to SDT0.
I am only comparing times for this, but I need to copy the SDT0.Date and .Dayofweek to ALL of my UDT's .Date and .Dayofweek. at powerup.
I can do it with multiple single MOVE instructions, but I was hoping there was a way to do this with only 1 or 2 rungs...

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Copying values across a range of structures
« Reply #1 on: March 23, 2017, 10:46:17 AM »
Not like you think in a simple MOVER or MEMCOPY, but this is VERY easy to do using FOR/NEXT

FOR V100 0 9 (or whatever range)
MOVE $Now.Date UDT[V100].Date
MOVE $Now.DayOfWeek UDT[V100].DayOfWeek
NEXT

You could even use the DATAINFO instruction before your FOR loop to query how large your UDT block is if you think your UDT block will ever need to grow (vs. hard coding the "9" as the "end" FOR value).

ElroyJetson

  • Full Member
  • ***
  • Posts: 36
Re: Copying values across a range of structures
« Reply #2 on: March 23, 2017, 11:05:12 AM »
Ah ha!!! Thanks for that franji1!!! Thats beautiful.

Another question if you will...
I want to count down the duration of the time difference between SDT0(Now) and my UDTs.
I've used the DTDIFF command, and the result I get is in seconds. I can calculate the minutes remaining by /60 and moving to a D location, but calculating the seconds down is not working to my satisfaction. I want the seconds remaining to go from 59 to 0. How do I convert the seconds of DTDIFF in seconds remaining?

Thanks again...
« Last Edit: March 23, 2017, 11:07:28 AM by ElroyJetson »

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Copying values across a range of structures
« Reply #3 on: March 23, 2017, 11:12:51 AM »
In MATH, use the Modulo (remainder) operator %, and do % 60

(D100 % 60)

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Copying values across a range of structures
« Reply #4 on: March 23, 2017, 11:14:22 AM »
FYI, if you use the DATAINFO instruction, make sure you SUBTRACT 1 from the block size to get the LAST INDEX of your FOR loop.
So 10 UDTs needs to go from 0..9, not 0..10.

ElroyJetson

  • Full Member
  • ***
  • Posts: 36
Re: Copying values across a range of structures
« Reply #5 on: March 23, 2017, 11:17:05 AM »
Thanks again. I actually tried that (or so I thought), but it didnt work at the time.  ???
Works great NOW......... ::)

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3827
    • Host Engineering
Re: Copying values across a range of structures
« Reply #6 on: March 23, 2017, 11:21:13 AM »
Is your DTDIFF result negative?  Modulo does not work as expected on negative values.  Just swap your DTDIFF order to make it a "positive" difference.  Or programmatically see if you need to negate the negative result before doing any divides or modulo?!?

ElroyJetson

  • Full Member
  • ***
  • Posts: 36
Re: Copying values across a range of structures
« Reply #7 on: March 23, 2017, 11:34:05 AM »
Is your DTDIFF result negative?  Modulo does not work as expected on negative values.  Just swap your DTDIFF order to make it a "positive" difference.  Or programmatically see if you need to negate the negative result before doing any divides or modulo?!?

Yes it was, but I had done exactly as you said and reversed the DTDIFF....

Muchos Gracias!!!!