Alpha Video Training
Results 1 to 3 of 3

Thread: Shortening a script

  1. #1
    nick marodis
    Guest

    Default Shortening a script

    I may have created a monster here but it's needed to get the job done. I have a form with 8 shared variable and 8 variable check box thats valure are .t. or .f..
    I use the variables to query a table.
    I'm useing the case statement to decide with values to use. If I'm not mistake it will take 512 case statments 8x8x8 for all possible combinations.
    Example
    ''XBasic
    dim shared area as c
    dim shared ar as l
    dim shared da as l
    dim shared dr as l
    dim shared tr as l
    dim shared wn as l
    dim shared fe as l
    dim shared ro as l
    dim shared ty as l
    dim shared day1 as c
    dim shared driver1 as c
    dim shared wnweek as c
    dim shared feq1 as c
    dim shared route1 as c
    dim shared truck1 as c
    dim shared type1 as c
    dim query.description as c
    dim query.order as c
    dim query.filter as c
    dim query.options as c
    dim child as n

    debug(1)
    dim tnt as p

    tnt=table.current(2)
    query.description="lroute"
    query.order=""
    select
    case var->ar=.t..and.da=.f..and.tr=.f..and.ro=.f..and.ty=.f..and.fe=.f..and.wn=.f..and.dr=.f.
    use=var->area
    query.filter="Area ='"+use+"'"

    case var->da=.t..and.ar=.f..and.tr=.f..and.ro=.f..and.ty=.f..and.fe=.f..and.dr=.f..and.wn=.f.
    use=var->day1
    query.filter="Nrday ='"+use+"'"

    case var->tr=.t..and.ar=.f..and.da=.f..and.ro=.f..and.ty=.f..and.fe=.f..and.wn=.f..and.dr=.f.
    use=var->truck1
    query.filter="Truck ='"+use+"'"

    case var->ro=.t..and.da=.f..and.tr=.f..and.ar=.f..and.ty=.f..and.fe=.f..and.wn=.f..and.dr=.f.
    use=var->route1
    query.filter="Route ='"+use+"'"

    case var->ty=.t..and.da=.f..and.tr=.f..and.ro=.f..and.ar=.f..and.fe=.f..and.wn=.f..and.dr=.f.
    use=var->type1
    query.filter="type ='"+use+"'"

    case var->fe=.t..and.da=.f..and.tr=.f..and.ro=.f..and.ty=.f..and.ar=.f..and.wn=.f..and.dr=.f.
    use=var->feq1
    query.filter="freq ='"+use+"'"

    case var->dr=.t..and.da=.f..and.tr=.f..and.ro=.f..and.ty=.f..and.fe=.f..and.wn=.f..and.ar=.f.
    use=var->driver1
    query.filter="driver ='"+use+"'"

    case var->wn=.t..and.da=.f..and.tr=.f..and.ro=.f..and.ty=.f..and.fe=.f..and.ar=.f..and.dr=.f.
    use=var->wnweek
    query.filter="wweek ='"+use+"'"

    case var->wn=.t..and.da=.f..and.tr=.f..and.ro=.t..and.ty=.f..and.fe=.f..and.ar=.f..and.dr=.f.
    use=var->wnweek
    use1=var->route1
    query.filter="wweek ='"+use+"'.and.route='"+use1+"'"


    case else
    end select


    tnt.query_create()

    Any Suggestion would be greatly appreciated.
    nick


  2. #2
    "Certified" Alphaholic
    Real Name
    William Hanigsberg
    Join Date
    Apr 2000
    Location
    Toronto, ON
    Posts
    4,018

    Default RE: Shortening a script

    Hey Nick,

    Somebody will probably come up with something better but before I wrote so long and complicated a script I would consider a lookup table.

    Create the table with 512 records and then you can write a one or two line function which will take the combination of variables as an arguement and return the filter expression (which can be a field in the table).

    It would probably run faster than a script with so many conditions.

    Bill

  3. #3
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default RE: Shortening a script

    Nick,

    Build your query, don't create 256 versions of it. I don't know if this is exactly correct, but something like;


    query.filter=".t."
    IF ar->ar=.t.
    query.filter=query.filter+".and.Area ='"+var->area+"'"
    END IF
    IF ar->da=.t.
    query.filter=query.filter+".and.Nrday ='"+var->day1+"'"
    END IF
    IF ar->tr=.t.
    query.filter=query.filter+".and.Truck ='"+var->truck1+"'"
    END IF
    IF ar->ro=.t.
    query.filter=query.filter+".and.Route ='"+var->route1+"'"
    END IF
    IF ar->ty=.t.
    query.filter=query.filter+".and.type ='"+var->type1+"'"
    END IF
    IF var->fe=.t.
    query.filter=query.filter+".and.freq ='"+var->feq1+"'"
    END IF
    IF var->dr=.t.
    query.filter=query.filter+".and.driver ='"+var->driver1+"'"
    END IF
    IF var->wn=.t.
    query.filter=query.filter+".and.wweek ='"+var->wnweek+"'"
    END IF


    Regards,

    Ira J. Perlow
    Computer Systems Design & Associates
    csda@mediaone.net

Similar Threads

  1. Alpha Five Action Script: Script Create
    By debwelch in forum Alpha Five Version 5
    Replies: 1
    Last Post: 04-30-2004, 11:35 AM
  2. Date dialog script & report script won't combi
    By rbierman@iowbar.org in forum Alpha Five Version 5
    Replies: 6
    Last Post: 12-07-2003, 08:40 AM
  3. script
    By alev in forum Alpha Five Version 5
    Replies: 6
    Last Post: 05-17-2003, 06:01 PM
  4. Script recorder to script- Help!
    By Scott Naples in forum Alpha Five Version 4
    Replies: 3
    Last Post: 11-28-2002, 12:55 PM
  5. Is it psoosible to write a script 2 print a script
    By Graham Wickens in forum Alpha Five Version 4
    Replies: 2
    Last Post: 11-03-2002, 01:27 PM

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
  •