Alpha Video Training
Results 1 to 7 of 7

Thread: Invert Date List

  1. #1
    Member
    Real Name
    Don Gunther
    Join Date
    Feb 2002
    Posts
    36

    Default Invert Date List

    I have this code that will display dates with the oldest first.Ex. 1/1/2002
    2/5/2002
    4/5/2002

    I would like to invert the listing.
    4/5/2002
    2/5/2002
    1/1/2002

    Thanks for your help...

    dim global vdate as c
    dim namearray(52) as C
    dim i as n

    i=1
    tbl=table.open("time_hx",file_ro_shared) 'open the payroll file
    tbl.index_primary_put("trandate") 'look at this index, its unique
    tbl.fetch_first()
    while .not.tbl.fetch_EOF()
    namearray(i)=dtoc(tbl.trandate) 'change the date to character
    i=i+1
    tbl.fetch_next()
    end while
    tbl.close()
    vdate=ui_get_list_array("Which Pay Date?",1,"namearray")
    vdate=alltrim(vdate)
    if vdate=""
    end
    end if

  2. #2
    Member
    Real Name
    Craig Schumacker
    Join Date
    May 2000
    Posts
    687

    Default RE: Invert Date List

    Don:

    Add the line

    sort_array("namearray", 1)

    after the array is loaded and before you prompt for vdate.

    Craig

  3. #3
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,300

    Default RE: Invert Date List

    Craig,

    His array is of type C, and DTOC() formats the string equivalents for each date as "MM/DD/YYYY".

    So, you get this kind of sort:

    Code:
    dim myArray[5] as C
    myArray(1) = "01/01/2002"
    myArray(2) = "11/01/2001"
    myArray(3) = "01/01/2003"
    myArray(4) = "10/01/2000"
    myArray(5) = "01/01/2004"
    
    sort_array("myArray",1)
    for i = 1 to 5; ?myArray(i); next i
    
    11/01/2001
    10/01/2000
    01/01/2004
    01/01/2002
    01/01/2000
    The descending sort sorts each value from left
    to right, but this probably isn't what he wants.

    I think he'll need to change the array
    declaration so that it's of type D,
    or he'll need to convert the dates using
    DTOS(), which will create string equivalents
    formatted as "YYYYMMDD". If he uses
    DTOS() then a simple array sort descending
    will work fine.

    -- tom

  4. #4
    Member
    Real Name
    Craig Schumacker
    Join Date
    May 2000
    Posts
    687

    Default RE: Invert Date List

    Tom:

    Yes, you are correct. Sort_array() will not work in this case.

    I think I would consider resetting the index "trandate" to "descending" order before I went through the transitional changes you suggest... If the index "trandate" is sorted on date only, it will load the array properly to begin with.

    I'm also a big one on accurately dimensioning arrays by basing them on a record count, rather than a static dimension, and using for...next to load the array. This prevents the dreaded "array out of range" message from ever appearing. Of course, it's possible '52' is enough, but...

    Craig

  5. #5
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,300

    Default RE: Invert Date List

    Craig, I agree. In fact, that's my approach as well. Good ideas.

    -- tom

  6. #6
    Member
    Real Name
    Don Gunther
    Join Date
    Feb 2002
    Posts
    36

    Default RE: Invert Date List

    Thank you both for your speedy reply, but I need a little more help. I’m new to this so I have no clue how to make these corrections. Would appreciate how to modify me script.
    Thanks
    Don

  7. #7
    Member
    Real Name
    Don Gunther
    Join Date
    Feb 2002
    Posts
    36

    Default RE: Invert Date List

    It seemed more involved, but following your directions all I did was to change the index "trandate" to "descending" and it looks fine… Thanks Don

Similar Threads

  1. How to invert date field
    By George Corder in forum Alpha Five Version 5
    Replies: 3
    Last Post: 09-01-2004, 05:22 PM
  2. Invert order in record list object
    By Howard G. Cornett in forum Alpha Five Version 5
    Replies: 2
    Last Post: 06-09-2003, 07:07 AM
  3. Report, using Drop Down List for Date Selection.
    By NBGH in forum Alpha Five Version 4
    Replies: 4
    Last Post: 02-13-2002, 04:26 AM
  4. invert(str(xx)) vs str(invert(xx))
    By russ Boehle in forum Alpha Five Version 4
    Replies: 10
    Last Post: 05-03-2001, 08:46 PM
  5. invert date help
    By Tom Patten in forum Alpha Five Version 4
    Replies: 5
    Last Post: 02-03-2001, 06:36 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •