Sign up on the Revelation Software website to have access to the most current content, and to be able to ask questions and get answers from the Revelation community

At 27 AUG 1998 11:28:44AM Bruce Lee wrote:

Hello,

Will the insert command sort values as they are inserted? Basically, I am building a list of @vm delimitted items; however, I need the list to be built in sorted order. If the insert command will do this, what is the syntax.

Thank You,

Bruce Lee


At 27 AUG 1998 11:47AM Matt Sorrell wrote:

Bruce,

What you need to use first is the LOCATE … BY statment. What this does is determines where in the array the value would be, and returns the POS for that location. You can then insert at that POS. Here is a snippet of code that I use for that:

LOCATE FN IN FNOS BY "AL" USING @VM SETTING POS ELSE

  FNOS=INSERT(FNOS,1,POS,0,FN)

END

The AL mnemonic indicates an ascending, left-justified search. Other possible values are:

AR - ascending, right-justified (usually used for numerics)

DL - descending, left-justified (text strings)

DR - descending, right-justified (numerics)

Obviously, ascending sorts from A - Z, and descending sorts from Z - A. I use the ELSE clause because I don't want to insert into the array if it already exists. If you do want to insert regardless, then the command would be as follows:

LOCATE FN IN FNOS BY "AL" USING @VM SETTING POS THEN

  FNOS=INSERT(FNOS,1,POS,0,FN)

END ELSE

  FNOS=INSERT(FNOS,1,POS,0,FN)

END

This will insert into the array at the correct position regardless.

Hope this helps.

Matt


At 27 AUG 1998 11:48AM Matt Sorrell wrote:

Bruce,

What you need to use first is the LOCATE … BY statment. What this does is determines where in the array the value would be, and returns the POS for that location. You can then insert at that POS. Here is a snippet of code that I use for that:

LOCATE FN IN FNOS BY "AL" USING @VM SETTING POS ELSE

  FNOS=INSERT(FNOS,1,POS,0,FN)

END

The AL mnemonic indicates an ascending, left-justified search. Other possible values are:

AR - ascending, right-justified (usually used for numerics)

DL - descending, left-justified (text strings)

DR - descending, right-justified (numerics)

Obviously, ascending sorts from A - Z, and descending sorts from Z - A. I use the ELSE clause because I don't want to insert into the array if it already exists. If you do want to insert regardless, then the command would be as follows:

LOCATE FN IN FNOS BY "AL" USING @VM SETTING POS THEN

  FNOS=INSERT(FNOS,1,POS,0,FN)

END ELSE

  FNOS=INSERT(FNOS,1,POS,0,FN)

END

This will insert into the array at the correct position regardless.

Hope this helps.

Matt

View this thread on the forum...

  • third_party_content/community/commentary/forums_nonworks/3f71b9fd69f831b88525666d0055075e.txt
  • Last modified: 2023/12/28 07:40
  • by 127.0.0.1