Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

dynamic for each statements

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    dynamic for each statements

    I am having a bit of trouble with an algorithm I am trying to create and my brain is starting to hurt! What I am trying to do is take items from multiple lists and output every possible combination.

    For example, I have three lists: Car, Color and Model Year. In the Car list I have: Honda Accord and Honda Civic. In the Color list I have: Blue and Black. In the Model Year list I have: 2006 and 2007. The resulting table of combinations would have 8 rows (2*2*2) and would look like:

    Honda Accord, Blue, 2006
    Honda Accord, Blue, 2007
    Honda Accord, Black, 2006
    Honda Accord, Black, 2007
    Honda Civic, Blue, 2006
    Honda Civic, Blue, 2007
    Honda Civic, Black, 2006
    Honda Civic, Black 2007

    The code I am using for a finite set (knowing there will only be 3 lists) is:

    Code:
    for each item in Coverages
    		for each item2 in Deductibles
    			for each item3 in State
    	
    			    tbl.enter_begin()
    			
    			    tbl.field1 = item.value
    			    tbl.field2 = item2.value
    			    tbl.field3 = item3.value
    			    num_cases = num_cases+1
    			
    			    tbl.enter_end(.T.)
    	
    			next
    		next
    	next
    The problem is - I will not know how many lists there will be at runtime. There may be 5 or 10 or 20. Instead of creating an if statement for every possible number of lists up to 20 and inserting the correct number of "for each" under each one, I'm positive there's a better way. I've been at this for three days now and am at my wits end. Any ideas on how I need to restructure this? Thanks!!

    #2
    Re: dynamic for each statements

    The problem is - I will not know how many lists there will be at runtime. There may be 5 or 10 or 20
    Not sure what do you mean?
    How could you go from 3 lists to 20?
    By a list, you infer a specification that comes from a field..at least, that's what it seems.
    Are you suggesting that there could be 20 more fields each contributing one more spec?
    Like:
    Body style: coupe, sedan
    Transmison: automatic, manual
    and so on?
    Or where and what are these additional lists?
    And why wouldn't you know? if they come from fields in a table, then at least you know the max possible number of lists.

    Comment


      #3
      Re: dynamic for each statements

      You're right on the money with your assumptions... I have a form where the user decides how many fields they want to use with this combination operation (could be 3, could be 20). When they choose the fields they want to vary from the drop-downs, a dialog appears with multi-select lists for them to choose which values they want to vary for each field.

      The tables that house these fields and values are also user-generated (in a one to many set). They define their autos, years, colors, body styles and whatever else they want to add. I know I can determine the number of fields but I'm not sure how to apply that to the algorithm.

      I've been studying up on recursive algorithms but am having trouble with them. Let me know if you need more info. I really appreciate your help!

      Comment


        #4
        Re: dynamic for each statements

        And to make it a little more complicated on top of this, there are multiple projects being handled, so if the user creates 3 projects, there will be 3 different groups of fields and values. So Project A may have 15, Project B may have 5 and Project C may have 30...

        Comment


          #5
          Re: dynamic for each statements

          Well, if the user chooses the specs, then it's a simple matter of knowing how many lists.

          But, let's forget about how many lists there are, it's irrelevant.. I am thinking of a simple scheme to do this thing. Let me put it to the test first. I will get back with you as soon as I get done with my insurance agent (policies expiring today).
          Later.

          P.S.
          If you don't want to wait for my reply, what I am thinking of is:
          Create an array of each field chosen
          Append the arrays to each other
          Save the final array as records.

          I am sure there are other ways, but for now, I gotta go.

          Comment


            #6
            Re: dynamic for each statements

            Got a little breezer here and was about to create a sample when I figured probably it's a set with several child tables or maybe a number of lookups.
            So, instead of creating something that does not quite match what you have, it would be best if you could attach your db.

            Comment


              #7
              Re: dynamic for each statements

              I'm going to pull the pieces from my database because there is sensitive data but the table layout is simply a field table that has a project_id, field_id and field_name and a value table that has a field_id and value_name. The form in question has 3 combo boxes listing all the fields for the project being used (global variable from another form) and a button that brings up a dialog that has the values for the fields chosen from the 3 combo boxes in multi-select list boxes. When the user selects the values they want from the list boxes, they click a button and it performs the code from my first posting. Give me a bit to pull the pieces from the full database (a guy's gotta eat!). Thanks!

              Comment


                #8
                Re: dynamic for each statements

                Jason:
                The easiest way to do this is just duplicate the table (or set) without the records, put few sample records and zip it. It will save a lot of time.

                Comment


                  #9
                  Re: dynamic for each statements

                  You'll see there are two forms in the database. One is to input the fields and values, the other does the selection and combinations (select fields form). The table that houses the output is "qtp data" and there's also an output to an excel spreadsheet happening on the generation event script (onpush event script in the select fields form).

                  If you need any clarification please let me know! Thank you so much again for your help!

                  Comment


                    #10
                    Re: dynamic for each statements

                    The way you have it now, you are allowing the user to choose only 3 items. Are you saying you want to be able to allow the user to choose as many as they want?
                    Also, I am not quite sure what is the objective in the end?
                    Are you trying to locate a car with certain features from a table?
                    And what is a "Project"?

                    Comment


                      #11
                      Re: dynamic for each statements

                      Right now I limited it to a finite set because I'm not sure how to handle an unknown.

                      The objective is to produce an excel spreadsheet that has every possible combination of the choices the user selects whether it be 3, 5 or 10. This spreadsheet then gets fed to another application for processing.

                      When you are generating these combinations you'll see the result in the "qtp data" table.

                      A project is essentially a work area where the user can divide their data whether it be by users (each user has their own project) or departments.

                      Comment


                        #12
                        Re: dynamic for each statements

                        The objective is to produce an excel spreadsheet that has every possible combination of the choices the user selects whether it be 3, 5 or 10. This spreadsheet then gets fed to another application for processing.
                        OK.. but is that essential? that you send it to Excel, then process it in another application? what is that other application?
                        I am trying to get the full picture because this is rather unusual.
                        Last edited by G Gabriel; 06-20-2008, 03:46 PM.

                        Comment


                          #13
                          Re: dynamic for each statements

                          It gets very confusing especially since I don't know what the external app does with the data. I just know I need to provide the data in an excel format.

                          So my requirements are to take the input, process the combinations and output them to the spreadsheet and save it to a file system for batch processing. I pretty much get to live with the peculiarity of the process and just make sure it works... :)

                          Comment


                            #14
                            Re: dynamic for each statements

                            <Double posted by accident - would an admin delete please?>
                            Last edited by jaylaforte; 06-20-2008, 03:57 PM. Reason: double post

                            Comment


                              #15
                              Re: dynamic for each statements

                              This is rather way out of the ordinary of my way of doing things and when you look at it, it seems very complex.. and it is. Complex in the sense of how to streamline it so it does not take forever for the script to run.

                              BUT..

                              There is always a simple solution that hovers right under your nose and you just don't see it simply because you are getting lost in the complexities.

                              That solution is:

                              A SET.

                              That's all.
                              When you create a set, alpha creates a composite table. The records in that composite table reflects all possible combination between the parent and the child(ren).

                              So, all you have to do, is dynamically create a set.
                              This means, for each one of these items to choose from, create a table for that item, that would be a max of 20 tables.
                              Each time a user add one item to the mix, you dynamically add that table to the set.
                              When the user is done, you have a table with composite records ready to be exported to Excel.

                              There is one caveat:
                              I've always advised against having too many tables in a set, but in this case since the chances of a user selecting all 20 tables is rather very slim and in addion since each table will hold a small number of records, it's worth a try.
                              Last edited by G Gabriel; 06-20-2008, 04:56 PM.

                              Comment

                              Working...
                              X