Alpha DevCon 2018
Results 1 to 5 of 5

Thread: Programming Puzzle 7 - Yet another nested loop!

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

    Default Programming Puzzle 7 - Yet another nested loop!

    Beginning Xbasic Programming

    Puzzle 7 - Yet Another Nested loop

    You solved Puzzle_6, but your sales manager tells you that she forgot something
    that she needs. She doesn't really care how many separate invoices an item
    might have been on, she wants to know the amount of money each product generated.

    Just like a manager, right?

    Your job now is to write an xbasic script that will list each product
    and for each product show the total dollars generated by that item
    across all the invoices.

    Instructions:

    a) you may not use any of the built in summary functions, methods,
    or operations in Alpha Five. We're doing this one by hand.

    b) you may open the table only once

    c) your output should be directed to the trace window

    d) your list should be in ascending order based on the Product_id field

  2. #2
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,012

    Default Re: Programming Puzzle 7 - Yet another nested loop!

    As before.

    puzzle seven.txt

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

    Default Re: Programming Puzzle 7 - Yet another nested loop!

    At about this time, I would opt to train the manager in how to design reports.

    Code:
    'Date Created: 09-Jun-2011 11:29:00 AM
    'Last Updated: 09-Jun-2011 04:16:52 PM
    'Created By  : andy
    'Updated By  : andy
    OPTION STRICT
    OPTION ENCRYPTED_TOKENS
    ON ERROR GOTO ERR_HANDLER
    
    DIM vInvoice_ItemsP as P
    
    DIM vOrderC as C
    DIM vFilterC as C
    DIM vFormatC as C
    
    DIM vIndxN as N
    
    DIM arrInvoice[0] as P
    DIM arrInvoice[0].ProductC as C
    DIM arrInvoice[0].ExtensionN as N
    vInvoice_ItemsP = table.open("invoice_items",FILE_RW_SHARED)
    	vOrderC = "Product_id"
    	vInvoice_ItemsP.order(vOrderC)
    	vInvoice_ItemsP.fetch_first()
    	WHILE .not. vInvoice_ItemsP.fetch_eof()
    		vIndxN = arrInvoice.find(vInvoice_ItemsP.Product_Id, "ProductC")
    		IF vIndxN > 0 THEN
    			'Product found
    			arrInvoice[vIndxN].ExtensionN = arrInvoice[vIndxN].ExtensionN + vInvoice_ItemsP.extension
    		ELSE	
    			'Product not Found
    			arrInvoice[].ProductC = vInvoice_ItemsP.product_id
    			arrInvoice[..].ExtensionN = vInvoice_ItemsP.extension
    		END IF
    		vInvoice_ItemsP.fetch_next()
    	END WHILE
    vInvoice_ItemsP.close()
    
    vFormatC = "ProductC|ExtensionN"
    trace.WriteLn(arrInvoice.dump_properties(vFormatC))
    
    
    
    
    
    END
    '-----------------------------------
    'Error handler
    '-----------------------------------
    ERR_HANDLER:
    	Dim err as N= error_code_get()
    	Dim msg as C= "Error # "+ err + crlf() + error_text_get(err)
    	msg = msg + crlf() + "Script: " + error_script_get()
    	msg = msg + crlf() + "Line #: " + error_line_number_get()
    
    	trace.writeln(msg)
    
    	ui_msg_box("Error", msg, ui_attention_symbol)
    	msg = ""
    	
    	END

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

    Default Re: Programming Puzzle 7 - Yet another nested loop!

    Here's my solution.

    The attachment is the "exported" script. In this format the script can be easily "imported" into your copy of the puzzle database.

    -- tom

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

    Default Re: Programming Puzzle 7 - Yet another nested loop!

    puzzle attempt for puz 7!

    puz7.txt

Similar Threads

  1. Programming Puzzle 2 - Another Simple Loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 16
    Last Post: 12-20-2014, 10:38 AM
  2. Programming Puzzle 1 - Simple Loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 32
    Last Post: 12-26-2011, 01:38 PM
  3. Programming Puzzle 3 - Fractions, anyone?
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 7
    Last Post: 11-08-2011, 05:40 AM
  4. Programming Puzzle 6 - Another nested loop
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 6
    Last Post: 08-08-2011, 04:30 PM
  5. Programming Puzzle 5 - Nested loops
    By Tom Cone Jr in forum Xbasic Programming Puzzles
    Replies: 10
    Last Post: 08-08-2011, 02:06 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
  •