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

calc field question

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

    calc field question

    Can the tablesum function be used in a calculated field.?
    I am trying to show a calculated summary field based on a filter for display at the bottom of a browse.
    The records in the browse are child records and I am trying to show the sum of just those child records.
    I tried tablesum("tablename","field="+variable,"fieldname") and it will not work in the calculated field expression buider. Works everywhere else. The expression builder says invalid expression. Tried what I could think of.
    Thanks in advance for help.

    #2
    Re: calc field question

    Hi James,

    Yes it does work. Your expression

    tablesum("tablename","field="+variable,"fieldname")

    looks wrong. The filter needs to be an expression. If variable ="a1234" the middle part evaluates to a filter expression

    "field=a1234"

    instead of

    "field= 'a1234' "

    So try an expression like

    tablesum("tablename","field=' "+variable+" ' ","fieldname")

    Note extra spaces are there for clarity.
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture


    Comment


      #3
      Re: calc field question

      Thanks. It made some progress. The code;

      1.) tablesum("tablename","field=' "+variable+" ' ", "fieldname") gave the message "field" variable not found. Meaning that it is taking variable to be a field.
      Variable is a N. If I change the code to;

      2.) tablesum("tablename","field=" "+variable+", "fieldname") the calc expression window show a numeric field designator with a numveric value.

      So instead of "field= ' "+variable+" ' " I used "field=" "+variable+", which works in the calc field definitions window, but when placed on a form by drop and drag and looking at properties the expression builder says -invalid exspression-. Neither work. The expression builder hates them both and the form told me to come back later if I wanted it to display anything.
      Thanks for the help.

      Comment


        #4
        Re: calc field question

        Originally posted by milesjg View Post
        Thanks. It made some progress. The code;

        1.) tablesum("tablename","field=' "+variable+" ' ", "fieldname") gave the message "field" variable not found. Meaning that it is taking variable to be a field.
        Variable is a N. If I change the code to;

        2.) tablesum("tablename","field=" "+variable+", "fieldname") the calc expression window show a numeric field designator with a numveric value.

        So instead of "field= ' "+variable+" ' " I used "field=" "+variable+", which works in the calc field definitions window, but when placed on a form by drop and drag and looking at properties the expression builder says -invalid exspression-. Neither work. The expression builder hates them both and the form told me to come back later if I wanted it to display anything.
        Thanks for the help.
        If variable is a numeric, then the expression should be more as you 1st had it. But you are referencing the field called field in tablename to be equal to the number. If the table does not have a field named field it will never work. Use the name of the field that you want to compare. And the expression should look like

        tablesum("tablename","fieldname_to_compare="+ltrim(str(variable)), "fieldname_to_sum")
        Regards,

        Ira J. Perlow
        Computer Systems Design


        CSDA A5 Products
        New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
        CSDA Barcode Functions

        CSDA Code Utility
        CSDA Screen Capture


        Comment


          #5
          Re: calc field question

          "Field" is a reserved word and should not be used as the name of a variable. Personally I think it's bad practice to use reserved words to name any object in your application, including fieldnames, formnames, etc.

          Comment


            #6
            Re: calc field question

            Chalk another one up for me. I forget how easy it is to explain something when it's in front of oneself, which seems obvious, and make it obscure to another.
            table is named "genaccts" I was calling tablename.
            field to sum on in "genaccts" is "aamount" I was calling field.
            variable it called autovar.
            The actual code is - tablesum("genaccts","auto=" + autovar,"aamount")
            When field "auto" is equal to the variable "autovar" the sum function produces the sum of the records that are linked to the master record with the key value of autovar.
            The master has a field called auto. The child has a field called auto. They are linked by the field "auto". "Auto" is a increment field in the master.
            There is a browse which when a record in the master table is displayed all the linked records in "genaccts" are displayed. I am tryin to display a sum of the linked records in "genaccts".
            "autovar" is a variable that is set to the value of the field "auto" in the master table. Thus when the record changes in the master the sum of all the links in "genaccts' for the master record are shown by the tablesum()
            I use this inmany palces elsewhere exactly as mentined but not in a calc field before.
            The code for table name produces "invalid expression" when trying to use it to define a calc field.
            Sorry about that.

            Comment


              #7
              Re: calc field question

              Is the field 'auto' character or numeric? And what is the type of autovar?

              Although it will be good to get the tablesum working properly for you there may be an easier way to get what you want. From the drag drop list drag the child field 'aamount' onto the form. This should bring up the field genie. Choose 'Total of the field'. You might want to edit the long default name for the calculation and then press OK. This will place the new calculated field on your form and create an entry in the calculated field list.
              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


                #8
                Re: calc field question

                The field "auto" is a numeric auto inrement field.
                Here is what I discovered. The code;
                1.) tablesum("genacts","auto=",+autovar,"aamount") will not work in the xy->calc field maker thingy. It cannot be defined in the expression builder. Gives error messages on both parts.
                You can define, in the calc field builder; (xy on the menu)
                2.) tablesum("genaccts","auto=" "+autovar+","aamount"). It will give you a
                N:0 at the bottom. You cannot define this in the expression builder. You get the message invalid expression.
                Number two displays the name of the field on the form. No number.
                If after you place the calc field (as defined in 2.)) on the form and select properties you can edit the expression so that it is 1.). You cannot edit it if you select the expression builder from the property window. Only if you edit it
                as it appears on the window. It then displays the sum of the filtered records.

                Comment


                  #9
                  Re: calc field question

                  Originally posted by milesjg View Post
                  The field "auto" is a numeric auto inrement field.
                  Here is what I discovered. The code;
                  1.) tablesum("genacts","auto=",+autovar,"aamount") will not work in the xy->calc field maker thingy.
                  Maybe the mistakes above are typos in this message but I see "genacts" where you have previously mentioned and use below "genaccts". Also you have an extra comma after "auto=" that should not be there.

                  It cannot be defined in the expression builder. Gives error messages on both parts.
                  You can define, in the calc field builder; (xy on the menu)
                  2.) tablesum("genaccts","auto=" "+autovar+","aamount"). It will give you a
                  N:0 at the bottom. You cannot define this in the expression builder. You get the message invalid expression.
                  Number two displays the name of the field on the form. No number.
                  If after you place the calc field (as defined in 2.)) on the form and select properties you can edit the expression so that it is 1.). You cannot edit it if you select the expression builder from the property window. Only if you edit it
                  as it appears on the window. It then displays the sum of the filtered records.
                  If both the auto field and the autovar variable are numeric then the following should work
                  Code:
                   [COLOR=Black]tablesum("genaccts","auto=" + var->autovar,"aamount")
                  [/COLOR]
                  Your autovar variable should be defined with a scope of at least session. If still no joy it may be time to upload enough of your app for someone to take a look.
                  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


                    #10
                    Re: calc field question

                    Hi James & Tim

                    Originally posted by Tim Kiebert View Post
                    If both the auto field and the autovar variable are numeric then the following should work
                    Code:
                     [COLOR=Black]tablesum("genaccts","auto=" + var->autovar,"aamount")[/COLOR]
                    You can't count on the expression builder being able to convert numerics to strings. The expression should be
                    Code:
                     [COLOR=Black]tablesum("genaccts","auto=" + ltrim(str(autovar)),"aamount")[/COLOR]
                    If you still have problems, try filling in absolutes and find out what part is not working. E.g.

                    tablesum("genaccts",".t.","aamount")
                    tablesum("genaccts","auto=" + ltrim(str(1234)),"aamount")
                    tablesum("genaccts","auto=1234","aamount")
                    tablesum("genaccts","1234=" + ltrim(str(autovar)),"aamount")
                    Regards,

                    Ira J. Perlow
                    Computer Systems Design


                    CSDA A5 Products
                    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                    CSDA Barcode Functions

                    CSDA Code Utility
                    CSDA Screen Capture


                    Comment


                      #11
                      Re: calc field question

                      Hello Ira,

                      Good point. The expression I suggested I tested in good ol' Alphasports but as you say probably best not to count on the auto conversion. I did find though that in the form calculated field dialog I had to prefix the variable with 'var->' otherwise the variable was not recognized. However, if from there I went into the expression builder then the unprefixed variable was recognized and a result returned.
                      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


                        #12
                        Re: calc field question

                        Tim;

                        Yep, those were typos. The formula you gave me does the same thing. It says in the calc field window "can't find field var->autovar". If however you place it in quotes - tablesum("genaccts","auto=" + "var->autovar","aamount")
                        it will accept it. Show n:0 at bottom. Placed on the form it show nothing though. (Name of field) Once again it can be edited (by method mentioned) to what you wrote - tablesum("genaccts","auto=" + var->autovar,"aamount") and it works.
                        But...you were cookin with natural gas when you suggested the drag and genie thing. Made all this moot. With "no work." Though I'd still like to know why the edit gyrations are necessary to git dis stuff to work. There has to be some deep, existential underlying purpose in a (grander sense) for all this time spent on this.this subject.
                        Really appreciate the help.

                        Comment


                          #13
                          Re: calc field question

                          James,
                          Though I'd still like to know why the edit gyrations are necessary to git dis stuff to work. There has to be some deep, existential underlying purpose in a (grander sense) for all this time spent on this.this subject.
                          Different scenarios require different scripting....context is everything and changing this will most times change the script that is written. So each problem solved will have different solutions in different contexts. By "context" I am referring to various things such as where the script is called from (form, browse, report, autoexec, etc.), what event it is called from (OnInit, OnFetch, OnPush,etc.), and where the script is to be used (calc field, variable, parent field, child field,etc.) and more.

                          So even though you might have basically the same script you most times have to modify it according to context...no generic solution IOW.
                          Mike
                          __________________________________________
                          It is only when we forget all our learning that we begin to know.
                          It's not what you look at that matters, it's what you see.
                          Henry David Thoreau
                          __________________________________________



                          Comment


                            #14
                            Re: calc field question

                            Originally posted by milesjg View Post
                            Tim;

                            Yep, those were typos. The formula you gave me does the same thing. It says in the calc field window "can't find field var->autovar". If however you place it in quotes - tablesum("genaccts","auto=" + "var->autovar","aamount")
                            it will accept it. Show n:0 at bottom. Placed on the form it show nothing though. (Name of field) Once again it can be edited (by method mentioned) to what you wrote - tablesum("genaccts","auto=" + var->autovar,"aamount") and it works.
                            But...you were cookin with natural gas when you suggested the drag and genie thing. Made all this moot. With "no work." Though I'd still like to know why the edit gyrations are necessary to git dis stuff to work. There has to be some deep, existential underlying purpose in a (grander sense) for all this time spent on this.this subject.
                            Really appreciate the help.
                            James,
                            I am glad that you were at least able to get the job done.
                            I would recommend trying some of Ira's alternatives substituting in some fixed data for the variable to narrow down the problem. You haven't mentioned how and where the variable is declared or how you are populating its value. I am suspecting it is a scope/context issue as Mike has mentioned.
                            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


                              #15
                              Re: calc field question

                              I have two tables in a set called locinventory, locations and inventory.
                              When I display the parent record, I would like to total the cases in inventory for that location shown in the browse. It would seem this is the way to do it, but no joy for me.

                              calc field on the parent record;
                              tablesum("inventory.dbf" , "Location_Code = Locinventory->Location_Code", "Locinventory->Cases_Date_1")

                              Even when I change my filter expression to ".T." it doesn't evaluate. Can I sum a field in a child table from the parent?

                              Thanks
                              Bill Belanger
                              (My 1st day back with Alpha and I'm stuck)

                              Comment

                              Working...
                              X