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

Default Table Sort

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

    Default Table Sort

    I want to have a default sort for a table based on a date field. I have tried everything in indexes but nothing works.
    -----------------------------------------------
    Regards
    Mark Pearson
    [email protected]
    Youtube channel
    Website

    #2
    Re: Default Table Sort

    At which point do you want this default sort to take affect? In forms or browses you can set that in the properties. I don't think it can be set in the default browse. In xbasic, say using table.open(), you would need to apply the index.
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

    Comment


      #3
      Re: Default Table Sort

      Hi Tim - my problem has turned out bigger than that. What I am trying to do is create crosstab that sorts the columns based on a date field. I want to produce a monthly stat by user. See attached picture of the current result. No matter what I do with teh date field it does not prduce a logical sort result. It keeps sorting as a character. Appreciate any hep.

      demo.jpg
      -----------------------------------------------
      Regards
      Mark Pearson
      [email protected]
      Youtube channel
      Website

      Comment


        #4
        Re: Default Table Sort

        Have you tried the little button with 3 dots on it Mark?
        groupby.JPG
        See our Hybrid Option here;
        https://hybridapps.example-software.com/


        Apologies to anyone I haven't managed to upset yet.
        You are held in a queue and I will get to you soon.

        Comment


          #5
          Re: Default Table Sort

          Yep - sure have. It does not seem work for dates. As I want it to sort by month, all it does is encase the date in month(), which then gives a number which is sorted, but if the year for months 10 11 and 12 is 2011, and the months 1for 1 2 and 3 is 2012, it still sorts as 1 2 3 10 11 12. This problem is componded by the fact it does it only shows a number for the sort
          -----------------------------------------------
          Regards
          Mark Pearson
          [email protected]
          Youtube channel
          Website

          Comment


            #6
            Re: Default Table Sort

            Got a bit further like this Mark;
            groupby01.JPG
            See our Hybrid Option here;
            https://hybridapps.example-software.com/


            Apologies to anyone I haven't managed to upset yet.
            You are held in a queue and I will get to you soon.

            Comment


              #7
              Re: Default Table Sort

              Mark,

              I'm not understanding you. 1,2,3,10,11,12 IS sorted by month.

              If you want 10, 11, 12, 1, 2, 3 then you have to sort by year and by month.

              Perhaps DTOS(your_date_field) will help. If you group by the left 6 characters wouldn't that gete you there?

              Comment


                #8
                Re: Default Table Sort

                Thanks All- the penny drops. I was so used to another programs crosstab system (lotus approach) that I simply thought that it would still base the sort on the date. Guess I will get used to it. Thanks. I might add that Alpha should take alook at the Lotus approach one. Well over 13 years old in tech terms, but still much better than Alpha's. I guess I can't have everything
                -----------------------------------------------
                Regards
                Mark Pearson
                [email protected]
                Youtube channel
                Website

                Comment


                  #9
                  Re: Default Table Sort

                  OK - FYI - I got the sort correct based on your help. In order to achieve my final goal of puting the result table in an excel spreadsheed, I had to manipualte the field names to be more in line with something presenatable. The scrip below does:

                  1. Creates a silent crostab
                  2. Uses the result table
                  3. Opens excel and puts in the data

                  The great thing about this whole project was that I had to actually write very little of the code. The cross tab was initialy created with the wizard and converted to xbasic. The code for excel was recorded as a macro in excel and then copied/paste and modified into the code.

                  --------------------
                  'Creating the crosstab

                  xtab_db_name = filename_decode("IBYBM.DBF")
                  tbl = table.open("e15a")
                  ON ERROR GOTO ERROR09062012221756893
                  crosstab.db = xtab_db_name
                  crosstab.db_dd_delete = .F.
                  crosstab.filter = ""
                  crosstab.row = "FIELD35"
                  crosstab.column = "STR(YEAR(SMD))+STR(MONTH(SMD))"
                  crosstab.options = "I"
                  crosstab.tabulate = "ISSTOTAL"
                  crosstab.code = 1
                  tbl.crosstab()
                  GOTO CONTINUE09062012221756893
                  ERROR09062012221756893:
                  ON ERROR GOTO 0
                  ui_msg_box("Error","Error running Crosstab Operation"+crlf()+error_text_get())
                  END
                  CONTINUE09062012221756893:
                  tbl.close()
                  'Add the table just created by the Crosstab operation to the Database..
                  file_add_to_db(xtab_db_name)

                  'Extracting the crosstab data and putting it in excel

                  Dim excel as p
                  dim t1 as p
                  dim q1 as p
                  dim pth1 as c
                  dim filepointer as p
                  dim mylist as c
                  dim nrecs as n
                  dim i as n
                  dim i1 as n
                  dim lcount as n
                  dim pname as c
                  dim getarow as c
                  dim myfd as p
                  dim myfd1[20] as c
                  dim mytotal as c
                  dim myform1 as c
                  query.filter = ""
                  query.sort = ""

                  mylist = A5_GET_FIELDNAMES("ibybm","n") 'Extract result table field names

                  lcount = *count(mylist)
                  dim mylist2 as c
                  mylist = STRITRAN(mylist,"_"," ",1)
                  dim mylist2 as c
                  i = 0
                  mylist = *line_replace(mylist,"Users", 1)

                  for each x in mylist 'Changing field names to be more readable

                  x.value = "01 " + right(x.value,len(x.value) - at2(" ", x.value,1)) + " " + left(x.value,4)

                  if isdate(x.value) = .t. then
                  if mylist2 = "" then
                  mylist2 = date_format(ctod(x.value),"Mon yyyy")
                  else
                  mylist2 = mylist2 + crlf() + date_format(ctod(x.value),"Mon yyyy")
                  end if

                  end if
                  i = i + 1

                  next
                  mylist = "User" + Crlf() + mylist2

                  mylist = STRITRAN(mylist,crlf(),",",1) 'Convert list to comma sepearted to become first row in spreadsheet

                  pth1 = a5.Get_Path()
                  pth1 = pth1 + chr(92) + "work files"
                  if A5_IS_PATH_VALID(pth1) = .f. then
                  DIR_CREATE(pth1)
                  end if

                  pth1 = pth1 + chr(92) + "LB_issues_by_user_by_month.csv" 'Default spreadsheet name

                  if file.exists(pth1) = .t. then
                  file.remove(pth1)
                  end if

                  filepointer = file.create(pth1,FILE_RW_Shared)
                  mylist = mylist + crlf()
                  filepointer.write(mylist)

                  t1 = table.open("ibybm",FILE_RO_SHARED)

                  nrecs = t1.records_get()

                  mylist = ""
                  t1.fetch_first()

                  for i = 1 to nrecs
                  getarow = ""
                  for i1 = 1 to lcount
                  myfd = t1.field_get(i1)
                  if getarow = "" then

                  getarow = myfd.value_get()
                  getarow = alltrim(getarow)
                  else

                  getarow = getarow + "," + myfd.value_get()
                  end if


                  next

                  t1.fetch_next()
                  File.Append_Line(pth1,getarow)

                  next

                  filepointer.flush()

                  filepointer.close()
                  t1.close()
                  dim sv as c
                  dim ev as c

                  sv = "A"

                  for i = 1 to lcount-1
                  sv = increment_value(sv)

                  next


                  ev = alltrim(sv + alltrim(str(1)))
                  ev = "B1:" + ev

                  excel = ole.create("excel.Application")

                  excel.Workbooks.Open(pth1)
                  excel.visible = .t.


                  excel.Range(ev).select()

                  excel.selection.HorizontalAlignment = 3
                  excel.selection.VerticalAlignment = 3
                  excel.selection.Orientation = 90
                  excel.selection.font.bold = .t.
                  excel.Range("A1").select()

                  sv = "A" + alltrim(str(nrecs+2))
                  excel.Range(SV).select()
                  excel.selection.formula = "Totals"
                  excel.selection.font.bold = .t.

                  sv = "A"
                  dim mrow as n
                  dim mrow1 as n
                  dim myform as c
                  dim sr as c
                  dim er as c
                  dim sr1 as c
                  mrow = nrecs+2
                  sr = "-1"
                  sr1 = "-2"
                  mrow1 = (nrecs+1)*-1
                  er = alltrim(str(mrow1+1))

                  for i = 2 to lcount
                  sv = increment_value(sv)
                  ev = alltrim(sv)
                  ev = ev + alltrim(str(mrow))

                  excel.Range(EV).select()
                  myform = "=Sum(R["+er+"]C:R["+sr+"]C)"
                  excel.ActiveCell.FormulaR1C1 = myform
                  excel.selection.font.bold = .t.
                  next
                  sv = "A"
                  for i = 1 to lcount
                  sv = increment_value(sv)

                  next
                  dim sv1 as c

                  sv1 = increment_value(sv)
                  excel.Range(SV + alltrim(str(1))).select()
                  excel.selection.formula = "Totals"
                  excel.selection.font.bold = .t.

                  excel.Range(SV1 + alltrim(str(1))).select()
                  excel.selection.formula = "Average"
                  excel.selection.font.bold = .t.

                  for i = 2 to nrecs + 2

                  excel.Range(sv + alltrim(str(i))).select()
                  mrow = lcount * -1
                  er = alltrim(str(mrow))
                  myform = "=Sum(RC["+er+"]:RC["+sr+"])"
                  excel.ActiveCell.FormulaR1C1 = myform
                  excel.selection.font.bold = .t.
                  excel.Range(sv1 + alltrim(str(i))).select()

                  myform1 = "=average(RC["+er+"]:RC["+sr1+"])"
                  excel.ActiveCell.FormulaR1C1 = myform1
                  excel.Selection.NumberFormat = "0"
                  excel.selection.font.bold = .t.

                  next

                  excel.activesheet.Cells.Select()

                  excel.Cells.EntireColumn.AutoFit()
                  excel.Range("A1").select()
                  'excel.activesheet.Cells.Select
                  'excel.Cells.EntireColumn.AutoFit
                  -----------------------------------------------
                  Regards
                  Mark Pearson
                  [email protected]
                  Youtube channel
                  Website

                  Comment


                    #10
                    Re: Default Table Sort

                    Well the code certainly looks impressive Mark!
                    Just for info, why did you choose to manipulate the data in Excel and not in Alpha and then just do a simple export to Excel?
                    See our Hybrid Option here;
                    https://hybridapps.example-software.com/


                    Apologies to anyone I haven't managed to upset yet.
                    You are held in a queue and I will get to you soon.

                    Comment


                      #11
                      Re: Default Table Sort

                      The key reason I use excel is that I cannot build a report to manage variable number columns which a cross tab builds. Excel allows me to do this and Excel puts the report on more common ground for others to review. I could view a browse result and export to execl, but I would still have to manipulate the coulumn names to make sense.

                      If you want to test the above, copy and paste into a new code, build a crosstab (or use one you have built), view te crosstab code in xbasic, copy and paste over the crosstab script. Then change the results table name in the A5_getfieldnames() line. Run and it should work to some degree. The only issue you will need to change in greate detail is the part of the script that changes the column names. Initially it will not effect the execution, just the look of the columns.
                      -----------------------------------------------
                      Regards
                      Mark Pearson
                      [email protected]
                      Youtube channel
                      Website

                      Comment


                        #12
                        Re: Default Table Sort

                        Always more than one way to skin a cat Mark and if the solution works for you that's all that matters.
                        However,
                        In the Crosstab Genie, the facility to select which records are actually evaluated is available, so in date terms that would limit the range of columns.
                        If I had to do this on a regular basis, I'd create a Query to identify the records I was interested in, say Year = 2012. This could be a user controlled date range
                        Create a Table with the Field Names the way people expect - As in Person, Sales, Date etc.
                        Run the Crosstab and use Replace Existing Add Unique Append function mapping the raw cross tab names to the report table names, and then squirt it into Excel.
                        The users could view in Excel and I'd still have the data files to use for other purposes.
                        See our Hybrid Option here;
                        https://hybridapps.example-software.com/


                        Apologies to anyone I haven't managed to upset yet.
                        You are held in a queue and I will get to you soon.

                        Comment


                          #13
                          Re: Default Table Sort

                          Yep Ted, more than one way for everything - if there wasn't sex would be boring (did I just say that?). In relation to your approach, how do you get the column names in the crosstab to be the way you want, particularly based on a date and based on a variable numebtr of columns
                          -----------------------------------------------
                          Regards
                          Mark Pearson
                          [email protected]
                          Youtube channel
                          Website

                          Comment


                            #14
                            Re: Default Table Sort

                            I'm obviously missing something here. I had assumed that you were looking at a fixed period to report upon. Say a 12 month window.
                            The query would give you the period, say 01/01/2012 to 31/12/2012.
                            If the sort order is correct then the first col will be Jan, 2nd Feb etc.
                            The append would insert data into the column with a text descriptor - Jan/Feb/Mar etc

                            So Xtab 2012_2_8 would map to Feb

                            On the other hand, if you are looking at unbounded periods like for all time, then the approach I suggested would be more cumbersome.

                            I'll try and put a sample of what I mean together (and I may fall flat on my face) but I'm sure that I have done this previously.
                            See our Hybrid Option here;
                            https://hybridapps.example-software.com/


                            Apologies to anyone I haven't managed to upset yet.
                            You are held in a queue and I will get to you soon.

                            Comment

                            Working...
                            X