Alpha DevCon 2018
Results 1 to 9 of 9

Thread: Programming Puzzle 9 - Dump ta dump

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

    Default Programming Puzzle 9 - Dump ta dump

    Beginning Xbasic Programming

    Puzzle 9 - Dump ta dump

    You solved Puzzle 6, 7, & 8 but NOW your sales manager tells you
    that the list of product sales doesn't do anyone any good displayed on
    screen. She needs the list of sales in a text file she can print or
    send to others. After noting that it took you longer to do the
    descending sort that she had expected, she says dumping the
    list to a disk file should be trivial. After all, you're dumping it
    to the trace window already, right?

    After contemplating what you might want to "dump" on your manager,
    you realize that your job now is to write an xbasic script that will list
    each product in the Inivoice_items table and for each product show the
    total dollars generated by that item across all the invoices. Your list
    should be sorted in descending order based on total dollars generated
    by each item. And, finally, the list must be written to disk in a simple
    text file.

    Instructions:

    a) you may not use any of the built in summary functions, methods,
    or operations in Alpha Five. We're totaling sales without using
    any of the built-in summarization tools Alpha provides.

    b) you may open the table only once

    c) your output should be written to a disk file named "Puzzle_9_Sorted_List.txt"
    in a folder called "Temp" on your "C" drive.

    d) export your solution script and attach it to your reply, here

    e) attach a copy of the text file your script creates when you submit your
    solution here

  2. #2
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,044

    Default Re: Programming Puzzle 9 - Dump ta dump

    Comments simply regurgitate what the code already tells you. Hence why I hate comments. For Mr. PickyPicky's sake I have added some comments.
    Attached Files Attached Files

  3. #3
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    24,945

    Default Re: Programming Puzzle 9 - Dump ta dump

    All I needed to do was use

    file.from_string() with the appropriate parameters instead of the loop I had writing to the trace window.

    Puzzle_9 - 06-12-2011 -1.txt
    Puzzle_9_Sorted_List.txt

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

    Default Re: Programming Puzzle 9 - Dump ta dump

    Very nice work, guys. You both built a long string containing the complete output text. Then you used a higher level function to write the string to your disk file.

    Here's my more primitive approach. Key differences are few: (a) script verifies target directory exists or creates it; (b) script gives user the optioin to end early without overwriting an exisitng file; and (c) the file is created one line at a time.

    -- tom

  5. #5
    Member
    Real Name
    Jeb Richardson
    Join Date
    Aug 2011
    Location
    Bowling Green, KY
    Posts
    26

    Default Re: Programming Puzzle 9 - Dump ta dump

    To Mr. Prof. PickyPicky, towards the end of my script there are comment out lines. These lines are alternative ways I discovered to write my array into a txt format document. If the time is available check out the alternatives and see what you think. (The alternatives were introduced to me by Stan.)

    Puzzle_9.txt
    Puzzle_9_Sorted_List.txt



    -Jeb

  6. #6
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,044

    Default Re: Programming Puzzle 9 - Dump ta dump

    Jeb -

    Code looks and even better it works.

    I didn't validate that your results where correct so cannot attest to the calculations.

    I would suggest that you always dimension your variables prior to using them. Alpha 5 does allow you use a non dimensioned variable, but I find this to be bad habit forming. When you are editing your code you can click the "Code" menu option then choose "Find Un-DIMed Variables" This genie will even help you create the code needed to dimension the variables. I prefer to start all my code with the "OPTION EXPLICIT" command, this will cause alpha5 to stop execution if it finds an un-dimmed variable.

    On line 27 you create the output file and open it using the file.create() function. However you still have a bit of processing to do before you utilize the opened file. I personally prefer to open files right before i need to read or write data and then close them immediately.

    In this case I would move line 27 down to where you are gonna start writing to the file.
    Code:
    creation = file.create(path,FILE_RW_SHARED)
    creation.write_line("Product ID"+space(20)+"Totals")
    Same with line 62
    Code:
    item.close()
    . Since you were done using the table at line 49, I would place my <tbl>.close() call there. No sense leaving a table pointer open if you are not using it.

    None of this is ground breaking or show stopping. In the end sometimes if the code works just go with :)

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

    Default Re: Programming Puzzle 9 - Dump ta dump

    Jeb, I think Andy means

    OPTION STRICT

    not OPTION EXPLICIT

  8. #8
    "Certified" Alphaholic
    Real Name
    Andrew Schone
    Join Date
    Dec 2005
    Location
    Kansas
    Posts
    1,044

    Default Re: Programming Puzzle 9 - Dump ta dump

    You are correct.

  9. #9
    Member
    Real Name
    Jeb Richardson
    Join Date
    Aug 2011
    Location
    Bowling Green, KY
    Posts
    26

    Default Re: Programming Puzzle 9 - Dump ta dump

    Awesome. Thanks guys!

    -Jeb

Similar Threads

  1. Data dump
    By wood1e in forum Alpha Five Version 7
    Replies: 9
    Last Post: 03-29-2006, 08:16 PM
  2. Dump of all A5 functions
    By Melvin Davidson in forum Code Archive
    Replies: 17
    Last Post: 08-29-2005, 12:58 PM
  3. alpha : cheap stack dump linked in -> no dump
    By Collinet Philippe in forum Alpha Four Version 6 and Prior
    Replies: 0
    Last Post: 06-23-2004, 02:21 PM
  4. Autoexec! Want to dump it!
    By Bob Elliott in forum Alpha Five Version 4
    Replies: 2
    Last Post: 02-19-2002, 12:01 PM
  5. data dump
    By Kim Sargent in forum Alpha Five Version 4
    Replies: 4
    Last Post: 10-09-2001, 05:49 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
  •