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

Grouping by Lastname in a Table or Browse

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

    Grouping by Lastname in a Table or Browse

    I need to group a table by Lastname. While sorting it by Lastname+Firstname does that, I need to isolate the Lastnames into groups so that I can assign a Customerid value to each group so that all the records in each group have the same Customerid value. Example: the name Smith, Wilbur is one group and has three records all with the same Lastname/Firstname. When the Customerid value is assigned, all 3 records in the group will have the same Customerid value.

    Setting up a group in a report will group the Lastnames as I need but there is no way to turn the report into xBasic code and then alpply the code to a table/browse. At least I don't think there is.

    Any ideas on how I might create groups within a table so that when a Customerid value is assigned, it will assign the same value to each record in the group?

    Another way to accomplish this task is for a script to:

    1. Sort the table by Lastname+Firstname
    2. Identify the records with the same Lastname/Firstname as matching records
    3. Assign the same customerid value in the group of each matching record
    Last edited by forskare; 03-30-2015, 10:46 PM.
    TYVM :) kenn

    Knowing what you can achieve will not become reality until you imagine and explore.

    #2
    Re: Grouping by Lastname in a Table or Browse

    why not assign the customerid before running the report, then group by customerid ?
    Gregg
    https://paiza.io is a great site to test and share sql code

    Comment


      #3
      Re: Grouping by Lastname in a Table or Browse

      I would try copying to a temp table that only has the unique values you need. Then as Gregg suggested, add your customer id there with an update and post it back to the original table matched on the same name combo. Assuming of course you are assigning new values for the customer id...
      Robin

      Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

      Comment


        #4
        Re: Grouping by Lastname in a Table or Browse

        Code:
        cid = "000001"'starting value, change to suit
        tbl = table.open("customer")
        tbl.order("lastname+firstname")
        tbl.fetch_first()
        lname = tbl.lastname
        while .not. tbl.fetch_eof()
        	while tbl.lastname = var->lname .and. (.not. tbl.fetch_eof())
        		tbl.change_begin()
        		tbl.customerid = var->cid
        		tbl.change_end(.T.)
        		tbl.fetch_next()
        	end while
        	cid = increment_value(var->cid)
        	lname = tbl.lastname
        end while
        Note that one does not need to identify the records with the same last name. Simply get the current last name, process the customer id while the last name remains the same. When the last name changes, capture it, increment the customer id, rinse and repeat.
        Last edited by Stan Mathews; 03-31-2015, 09:48 AM. Reason: clarification
        There can be only one.

        Comment


          #5
          Re: Grouping by Lastname in a Table or Browse

          Hello Gregg, Robin and Stan,

          I tried Stan's code and, it works great!! There is one minor change to be made to separate the same last names with different first names. I added the Firstname field and what I figured to be needed code. (Red) I steps through the Debug OK and doesn't throw any errors but when running it on the form, it seems to do 'nothing'. I probably have the wrong code, put it in the wrong places or both. At any rate, the the Customerid as Anderson, Mary.


          cid = "000001"'starting value, change to suit
          tbl = table.open("accct2014")
          tbl.order("lastname+firstname")
          tbl.fetch_first()
          lname = tbl.lastname
          fname = tbl.firstname
          while .not. tbl.fetch_eof()
          while tbl.lastname = var->lname .and. tbl.firstname = var-> fname .and. (.not. tbl.fetch_eof())
          tbl.change_begin()
          tbl.customerid = var->cid
          tbl.change_end(.T.)
          tbl.fetch_next()
          end while
          cid = increment_value(var->cid)
          lname = tbl.lastname
          fname = tbl.firstname
          end while

          I have't tried Gregg's or Robin's suggestions yet. The code is 'oh so close'.
          TYVM :) kenn

          Knowing what you can achieve will not become reality until you imagine and explore.

          Comment


            #6
            Re: Grouping by Lastname in a Table or Browse

            Did you copy and paste from your code to the forum

            .and. tbl.firstname = var-> fname

            should be

            .and. tbl.firstname = var->fname

            You can easily find out what's happening by putting debug(1) as the first line, n the code, step through it (F12), put fname and lname in the expression boxes at the bottom and watch the values change.
            There can be only one.

            Comment


              #7
              Re: Grouping by Lastname in a Table or Browse

              "n the code" ? Lo siento mucho, No comprendo.
              TYVM :) kenn

              Knowing what you can achieve will not become reality until you imagine and explore.

              Comment


                #8
                Re: Grouping by Lastname in a Table or Browse

                Run. Push the button.
                There can be only one.

                Comment


                  #9
                  Re: Grouping by Lastname in a Table or Browse

                  Alpha has an upset stomach. I can step through the code and it advances from line to line. However, when I try to exit debug, Alpha crashes. I cannot use the f12 key because either win 8.1 or the Dell laptop hijacks it to run the screen brightness control.That leaves the 'Step' menu control. when I run the code, the first button push does nothing and a 2nd button push causes Alpha to crash. My builds are 2716/4452 which I believe is the last official update. Hmmmmm.
                  TYVM :) kenn

                  Knowing what you can achieve will not become reality until you imagine and explore.

                  Comment


                    #10
                    Re: Grouping by Lastname in a Table or Browse

                    What happens if you run the code from a button on a form not built on the same table or from the code tab. Your customerid field wouldn't happen to be an autoincrement field?
                    There can be only one.

                    Comment


                      #11
                      Re: Grouping by Lastname in a Table or Browse

                      Hi Stan,

                      No, it is not autoincrement. I placed the button on a dummy table and the same thing happens. Click the button once and after 30 seconds or so, the hour glass appears.I waited a full 2 minutes and then clicked on the screen, not the button. The screen blurred out as before and Alpha crashed. I created a browse just to view for changes and discovered that the script ran according to plan, creating the customerid values exactly as I need them. The script is working wonderfully awesome!!! Why Alpha crashes, I have no clue but the task is accomplished. Thank you for your help and follow-up. I greatly appreciate your talent and time.
                      TYVM :) kenn

                      Knowing what you can achieve will not become reality until you imagine and explore.

                      Comment


                        #12
                        Re: Grouping by Lastname in a Table or Browse

                        Kenn, are you using native Alpha tables, or SQL?

                        Comment


                          #13
                          Re: Grouping by Lastname in a Table or Browse

                          I should have included a tbl.close() at the end of the script but that wouldn't cause the crashing issue. Especially since the script ran before the firstname statements were added. I'm wondering if you have records without a firstname and whether that would make a difference.

                          Did some testing with V11 and the customer table in AlphaSports, added customerid field, added records with no first name but with last name, with last name but no first name. Can't make the script, as you posted except for the tablename, misbehave.
                          Last edited by Stan Mathews; 04-01-2015, 10:58 AM.
                          There can be only one.

                          Comment


                            #14
                            Re: Grouping by Lastname in a Table or Browse

                            Hi Tom,

                            Native dbf tables

                            Stan,

                            Yes, there are several records without a firstname and I added the tbl.Close() and a msgbox at the end. All ran well and it took about 6 seconds to assign the customerid value to 7,000+ records.

                            Who knows what the issue was but it did behave differently. Sometimes, how Alpha behaves causes one to question his sanity.
                            TYVM :) kenn

                            Knowing what you can achieve will not become reality until you imagine and explore.

                            Comment


                              #15
                              Re: Grouping by Lastname in a Table or Browse

                              If this is an ongoing process you can speed it up.

                              Code:
                              cid = "000001"'starting value, change to suit
                               tbl = table.open("accct2014")
                               tbl.order("lastname+firstname")
                               tbl.fetch_first()
                               lname = tbl.lastname
                              fname = tbl.firstname
                              tbl.batch_begin()
                               while .not. tbl.fetch_eof()
                               while tbl.lastname = var->lname .and. tbl.firstname = var-> fname .and. (.not. tbl.fetch_eof())
                               tbl.change_begin()
                               tbl.customerid = var->cid
                               tbl.change_end(.T.)
                               tbl.fetch_next()
                               end while
                               cid = increment_value(var->cid)
                               lname = tbl.lastname
                              fname = tbl.firstname
                               end while
                              tbl.batch_end()
                              tbl.close()
                              There can be only one.

                              Comment

                              Working...
                              X