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

Simple table sum code is not working

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

    Simple table sum code is not working

    I am specifiying this code in the "calculated area'xy' of a form for a table vendor.dbf a variable call vtotComm.
    I need the sum of all the values in the 'comm.dbf' table field "amount".
    but the field in 'comm.dbf' table "amtbal" must be =zero
    and field salesper in comm.dbf = field "name" in vendor.dbf

    vtotComm = tablesum("comm.dbf", "amtbal=0" .AND. "salesper =' "+name+" ' ","amount")

    Why is not working?

    #2
    Re: Simple table sum code is not working

    "amtbal=0 .and. salesper =\"name\""

    or maybe not?
    Last edited by Mike Wilson; 06-11-2013, 09:13 AM.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

    Comment


      #3
      Re: Simple table sum code is not working

      "amtbal=0 .AND. salesper ='"+name+"'"

      Take your filter expression to the interactive window and establish sample values for any variables and experiment.

      Code:
      name = "sam"
      
      ?  "amtbal=0" .AND. "salesper =' "+name+" ' "
      ERROR: Argument is incorrect data type
      
      
      ?  "amtbal=0 .AND. salesper =' "+name+" ' "
      = "amtbal=0 .AND. salesper =' sam ' "
      
      
      ?  "amtbal=0 .AND. salesper ='"+name+"'"
      = "amtbal=0 .AND. salesper ='sam'"
      There can be only one.

      Comment


        #4
        Re: Simple table sum code is not working

        Originally posted by MikeData View Post
        I am specifiying this code in the "calculated area'xy' of a form for a table vendor.dbf a variable call vtotComm.
        I need the sum of all the values in the 'comm.dbf' table field "amount".
        but the field in 'comm.dbf' table "amtbal" must be =zero
        and field salesper in comm.dbf = field "name" in vendor.dbf

        vtotComm = tablesum("comm.dbf", "amtbal=0" .AND. "salesper =' "+name+" ' ","amount")

        Why is not working?
        HI Mike
        name should be a variable and may need to be SHARED or GLOBAL to work in the tablesum function.
        On Init of the form
        dim SHARED xname as C
        xname = ""
        On Fetch of the form
        name = formname:name.text ' (assumes name is a field on the form)
        vtotComm = tablesum("comm.dbf", "amtbal=0" .AND. "salesper =' "+var->xname+" ' ","amount")

        if it does not work as SHARED try GLOBAL
        Also, if vtotComm is a variable as well you can actually include this line in the On Fetch and not use the calculated field page at all.
        Nick Lawson
        cdc-TakeCharge
        Web Site:www.cdc-takecharge.com
        Video Blog: www.youtube.com/user/cdcTaleCharge
        How To Blog: cdctahecharge.wordpress.com

        Comment


          #5
          Re: Simple table sum code is not working

          Mike,

          Try using the "Quote() or S_Quote()"

          vtotComm = tablesum("comm.dbf", "amtbal=' 0" .AND. "salesper ="+name+" ' ","amount")

          Comment


            #6
            Re: Simple table sum code is not working

            Thanks for all the responses.
            "name" is a field in the table vendor.dbf
            The 2 dbf are not related.
            I believe that the relation is created by the code in the statement in order to get the total.
            This works:

            vtotComm = tablesum("comm.dbf", "salesper =' "+name+" ' ","amount")

            So if the name and salesper are equal, then I get the results for "amount".
            I just need to add the addition of the amtbal field in the comm.dbf be equal to zero as criteria to establish the relation.

            What is the syntax to include amtbal=0 to the expression?

            Comment


              #7
              Re: Simple table sum code is not working

              See post #3.
              There can be only one.

              Comment


                #8
                Re: Simple table sum code is not working

                Originally posted by johnkoh View Post
                Mike,

                Try using the "Quote() or S_Quote()"

                vtotComm = tablesum("comm.dbf", "amtbal=' 0" .AND. "salesper ="+name+" ' ","amount")
                John,

                A double quote mark begins and ends a character string, in this case a filter string so Alpha thinks

                "amtbal=' 0" .AND. "salesper ="+name+" ' "

                ends after the 0. ("amtbal=' 0")

                You can say

                "amtbal= 0"+" .AND. "+"salesper ='"+name+" ' "

                to string the parts together.

                Or one of these

                "amtbal= 0 .AND. salesper = '"+name+"'"
                "amtbal= 0 .AND. salesper ="+quote(name)
                "amtbal= 0 .AND. salesper ="+s_quote(name)
                There can be only one.

                Comment


                  #9
                  Re: Simple table sum code is not working

                  There are lots of examples available in the help file discussion of the tablecount() function. Directly relevant to tablesum() filter expressions.

                  Comment


                    #10
                    Re: Simple table sum code is not working

                    Originally posted by Stan Mathews View Post
                    1 "amtbal= 0"+" .AND. "+"salesper ='"+name+" ' "
                    2 "amtbal= 0 .AND. salesper = '"+name+"'"

                    3 "amtbal= 0 .AND. salesper ="+quote(name)
                    4 "amtbal= 0 .AND. salesper ="+s_quote(name)
                    Tom I have searched quite a few threads and I have copies of many of those codes.
                    Codes that look the same may not have same results. It seems that codes requires a bit different formating depending on the place of use.
                    I have found the same code could be slightly different if written in a field definition calculation or from a button or from the definition of calculated variables. Al least, it seems to me.

                    Stan gave me the above codes and I was working around the format of 1 and 2 in many variations as I have them working in other areas, but here, no success.
                    John had mentioned to use the S_quotes and quotes, but I did not followed them correctly.
                    I tried all 4 codes and 3 and 4 works perfect. 1 and 2 did not.
                    I have used Quotes and s_uotes in the past, but not with a clear understanding of their use. I have read the instruction for those 2 methods and I Think I follow them now. Not 100% sure yet.
                    I do appreciate the interest and attention you guys put into this. Thanks.

                    Comment


                      #11
                      Re: Simple table sum code is not working

                      They should all be equivalent given the same context (variable namespace).

                      Code:
                      name = "mike data"
                      salesper = "mike data"
                      
                      
                      ? "amtbal= 0"+" .AND. "+"salesper ='"+name+" ' "
                      = "amtbal= 0 .AND. salesper ='mike data ' "
                      
                      ? "amtbal= 0 .AND. salesper = '"+name+"'"
                      = "amtbal= 0 .AND. salesper = 'mike data'"
                      
                      ? "amtbal= 0 .AND. salesper ="+quote(name)
                      = amtbal= 0 .AND. salesper ="mike data"
                      
                      ? "amtbal= 0 .AND. salesper ="+s_quote(name)
                      = amtbal= 0 .AND. salesper ="mike data"
                      
                      
                      amtbal = 7.99
                      
                      ? eval("amtbal= 0"+" .AND. "+"salesper ='"+name+" ' ")
                      = .F.
                      
                      ? eval("amtbal= 0 .AND. salesper = '"+name+"'")
                      = .F.
                      
                      ? eval("amtbal= 0 .AND. salesper ="+quote(name))
                      = .F.
                      
                      
                      ? eval("amtbal= 0 .AND. salesper ="+s_quote(name))
                      = .F.
                      Sample table attached for use with

                      Code:
                      name = "mike data"
                      
                      
                      ? tablesum("comm2.dbf", "amtbal = 0 .and. salesper ='"+name+"' ","amount")
                      = 33.22
                      
                      ? tablesum("comm2.dbf", "amtbal = 0"+" .and. "+"salesper ='"+name+"' ","amount")
                      = 33.22
                      
                      ? tablesum("comm2.dbf", "amtbal = 0 .and. salesper ="+quote(name),"amount")
                      = 33.22
                      
                      ? tablesum("comm2.dbf", "amtbal = 0 .and. salesper ="+s_quote(name),"amount")
                      = 33.22
                      Attached Files
                      Last edited by Stan Mathews; 06-11-2013, 03:31 PM.
                      There can be only one.

                      Comment


                        #12
                        Re: Simple table sum code is not working

                        In the tablecount() examples an effort was made to explain the patterns within various filter expressions. Otherwise to many the rules seem almost random and therefore are difficult to apply to new situations. On the contrary, the patterns for correctly framed filter expressions rigorously follow the same rules in all contexts. If you work through each example in the tablecount() discussion, using the interactive editor, you'll be well on your way to never having to struggle with filter expressions again.

                        Comment


                          #13
                          Re: Simple table sum code is not working

                          Thanks Tom. I am in the process to find why code 1 and 2 did not work for me as Stan is showing that they should.

                          Comment


                            #14
                            Re: Simple table sum code is not working

                            tot1 = TABLESUM("comm.dbf","amtbal=0"+" .and. "+" salesper =' " +name+" ' ","amount")
                            tot2 = TABLESUM("comm.dbf","amtbal=0 .and. salesper =' " +name+" ' ","amount")

                            The ' and the " with spaces did matter!!!!!!
                            As I did take out the spaces and it works.

                            Am I correct?

                            Comment


                              #15
                              Re: Simple table sum code is not working

                              Yes.

                              salesper = " mike " is not the same as salesper = "mike".

                              As Tom said. You need to practice in the interactive.

                              Code:
                              name = "mike"
                              
                              ? "amtbal=0"+" .and. "+" salesper =' " +name+" ' "
                              = "amtbal=0 .and.  salesper =' mike ' "
                              
                              
                              ? "amtbal=0 .and. salesper =' " +name+" ' "
                              = "amtbal=0 .and. salesper =' mike ' "
                              
                              'not the same as
                              
                              ? "amtbal=0"+" .and. "+" salesper ='" +name+"' "
                              = "amtbal=0 .and.  salesper ='mike' "
                              
                              ? "amtbal=0 .and. salesper ='" +name+"' "
                              = "amtbal=0 .and. salesper ='mike' "
                              There can be only one.

                              Comment

                              Working...
                              X