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

Calculated field and or Variable

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

    Calculated field and or Variable

    On my invoice form I have a calculated field that adds up the total quantity of items ordered in a browse on the form. I do not have any trouble getting the correct value into the calculated field using
    Code:
    total(Invoice_Items->Quantity,GRP->INVOICE_HEADER)
    . It also works with this:
    Code:
    total(Invoice_Items->Quantity,GRP->INVOICE_HEADER,GRP->Invoice_items)
    The problem is I cannot find anyway to use the contents of a calculated field in another action or xbasic script to preform additional calculations.

    I have also tried specifying a variable with something like this.

    Code:
    DIM SHARED V-Items AS n
    V-Items = parentform:Items.value
    While I have had limited success trying to use a variable, when I do get it to work inside some script the value the variable pulls in is always from the first record in the table and not the current one.

    I will have a button on the form that when pushed it needs to get the total of the items and have that value available for use in the rest of the calculations that will be run when that button is pushed.

    inv1.png

    #2
    Re: Calculated field and or Variable

    I believe I was able to solve my problem by going at it differently.

    I was able to get the correct values written to a field using this code. Now hopefully I can use the value written to that table field in additional calculations.

    Code:
    'Set 'Value' property of 'Order_quantity' in Form 'invoice' .
    DIM form_name as c
    if is_object(topparent.this) then 
    	form_name = topparent.name()+".this"
    else
    	form_name = ""
    end if 
    
    DELETE expression_result
    expression_result =  eval("total(Invoice_Items->Quantity,GRP->INVOICE_HEADER)",form_name)
    parentform:Order_quantity.value = expression_result

    Comment


      #3
      Re: Calculated field and or Variable

      Calculated fields are designed to be used in browses, and also for totals. (total fields on forms/reports, and calculated fields when the database doesn't contain the value s you wish to display)

      For what you're trying to do, you may not want calculated fields, you probably want to use variables. And to get totals, I think you'll need to learn some X-basic functions. ~Or, you could place a hidden calculated field on the form, and grab the value from the field. (And possibly place the value into a variable.)


      example: vc_TextValue = Form:FieldName.value or optionally try this: vc_TextValue=Form:FieldName.text

      The first one example will work here, not the second one. The reason I added the second one is that sometimes, when you can't get what you want using the .value property, the .text property works. I've had to convert action scripts to X-basic just to change this to make them behave properly in some strange situations.....

      Note: The expression builder also can show you how to format the code that will work in X-basic. (as Keith indicates below)
      He is also much more seasoned than I presently am with a5. (Regardless, I always try to do things with X-basic without resorting to using the -> (pointer stuff) though. It works nicely in the a5 GUI, but IMHO, it seems weird to place that stuff in "real" code.)

      "The pointer stuff" used to really throw me off until I began thinking of it this way:

      this CALC field literally points (->) to a VALUE
      this FORM field literally points (->) to RECORDFIELD etc....
      Last edited by SNusa; 02-01-2012, 02:30 AM.
      Robert T. ~ "I enjoy manipulating data... just not my data."
      It's all about the "framework." (I suppose an "a5-induced" hard drive crash is now in order?)
      RELOADED: My current posting activity here merely represents a "Momentary Lapse Of Reason."

      Comment


        #4
        Re: Calculated field and or Variable

        Hi Preston,

        First thing, I notice on your screen shot that you have just the one field for the number of colours. To me that means all garments on this Order/Invoice will have 1 colour. Will you have to make out a new record if the customer wants a garment with extra colours?

        To use a calculated field within another calculated field, first create it in the Expression Builder, (click on icon shown in red box). Have a look at the attached screen shot and then open AlphaSports to see how it was done.

        PS. Hows your Matrix doing?
        Attached Files
        Last edited by Keith Hubert; 02-01-2012, 02:22 AM.
        Regards
        Keith Hubert
        Alpha Guild Member
        London.
        KHDB Management Systems
        Skype = keith.hubert


        For your day-to-day Needs, you Need an Alpha Database!

        Comment


          #5
          Re: Calculated field and or Variable

          Originally posted by SNusa View Post
          Calculated fields are designed to be used in browses, and also for totals. (total fields on forms/reports, and calculated fields when the database doesn't contain the value s you wish to display)

          For what you're trying to do, you don't want calculated fields, you want to use variables. And to get totals, I think you'll need to learn some X-basic functions.
          Or, you could place a hidden calculated field on the form, and grab the value from the field. (And possibly place the value into a variable.)

          example: vc_TextValue = Form:FieldName.value or optionally try this: vc_TextValue=Form:FieldName.text
          I tried using a variable and even placing the value of a calculated field into a variable but it does not work for me with my limited knowledge of X-Basic. I am still learning but I was able to get a suitable (for now) solution as stated above in message #2

          Comment


            #6
            Re: Calculated field and or Variable

            Originally posted by Keith Hubert View Post
            Hi Preston,

            First thing, I notice on your screen shot that you have just the one field for the number of colours. To me that means all garments on this Order/Invoice will have 1 colour. Will you have to make out a new record if the customer wants a garment with extra colours?

            To use a calculated field within another calculated field, first create it in the Expression Builder. Have a look at the attached screen shot and then open AlphaSports to see how it was done.
            Hi Keith,

            You are correct that the form in its current state only has one field for the number of colors in one location but that is because I am still testing. Once I get it to work for one print location I will then tackle adding the other 3 possible locations.

            Baby steps for me right now Keith.

            I have scaled the thing down to only cover up to 8 colors per location. That will satisfy a large majority of small shops. After that I will get with you or Tom about streamline up things for more color options like we discussed in the private messaging.

            Comment


              #7
              Re: Calculated field and or Variable

              Hi Preston,

              For the number of Locations, (the same for colours) all you need to do is have each field in the browse with a simple dropdown for choices.

              Do you understand now how the calculated fields work?
              Last edited by Keith Hubert; 02-01-2012, 02:39 AM.
              Regards
              Keith Hubert
              Alpha Guild Member
              London.
              KHDB Management Systems
              Skype = keith.hubert


              For your day-to-day Needs, you Need an Alpha Database!

              Comment


                #8
                Re: Calculated field and or Variable

                Originally posted by Keith Hubert View Post
                Hi Preston,

                For the number of colours all you need to do is have the field in the browse with a simple dropdown for choices.

                Do you understand now how the calculated fields work?
                I understand how to create calculated fields on a form but they seem to be of little use other than displaying the results on the form.

                For the color count I set up the drop down like this.
                color-count.png

                Comment


                  #9
                  Re: Calculated field and or Variable

                  Originally posted by preston View Post
                  I tried using a variable and even placing the value of a calculated field into a variable but it does not work for me with my limited knowledge of X-Basic. I am still learning but I was able to get a suitable (for now) solution as stated above in message #2
                  Here's the "magic (total function) that worked for you":
                  (Also, I believe the eval function "evaluates the funky calculated field pointer stuff" so that it works in X-basic. It also can convert character values to numbers) ie: x=eval("00010") returns the value of x=10

                  eval("total(Invoice_Items->Quantity,GRP->INVOICE_HEADER)",form_name)
                  parentform:Order_quantity.value = expression_result

                  or "simplified"
                  parentform:Order_quantity.value = eval("total(Invoice_Items->Quantity,GRP->INVOICE_HEADER)",form_name)

                  "Baby steps...." ~ I hear ya! Good luck!
                  Robert T. ~ "I enjoy manipulating data... just not my data."
                  It's all about the "framework." (I suppose an "a5-induced" hard drive crash is now in order?)
                  RELOADED: My current posting activity here merely represents a "Momentary Lapse Of Reason."

                  Comment


                    #10
                    Re: Calculated field and or Variable

                    Preston -
                    variable name V-Items will not work reliably
                    Start there.
                    If still no luck then post a sample otherwise we haveto guess if you are using correct object names.

                    Comment


                      #11
                      Re: Calculated field and or Variable

                      Originally posted by Ray in Capetown View Post
                      Preston -
                      variable name V-Items will not work reliably
                      Start there.
                      If still no luck then post a sample otherwise we haveto guess if you are using correct object names.
                      I tried it with different names like "Items2" and it still did not work.

                      Comment


                        #12
                        Re: Calculated field and or Variable

                        Originally posted by preston View Post
                        I tried it with different names like "Items2" and it still did not work.
                        He means use variables that make sense to others who are trying to figure out what you are trying to accomplish. Like vc_FName, vc_LName, vn_ItemAmt, vd_StartDate etc.... v for variable, c for type character, n for type number, d for type date etc.....

                        If you construct readable code, and follow some standards..... Others will be able to better understand what your intentions are.
                        Robert T. ~ "I enjoy manipulating data... just not my data."
                        It's all about the "framework." (I suppose an "a5-induced" hard drive crash is now in order?)
                        RELOADED: My current posting activity here merely represents a "Momentary Lapse Of Reason."

                        Comment


                          #13
                          Re: Calculated field and or Variable

                          Originally posted by SNusa View Post
                          He means use variables that make sense to others who are trying to figure out what you are trying to accomplish. Like vc_FName, vc_LName, vn_ItemAmt, vd_StartDate etc.... v for variable, c for type character, n for type number, d for type date etc.....

                          If you construct readable code, and follow some standards..... Others will be able to better understand what your intentions are.

                          Oh. Ok I will try to figure that out.

                          So for the variable thing I posted above in message #1 I posted it like this.

                          Code:
                          DIM SHARED V-Items AS n
                          V-Items = parentform:Items.value
                          So you are saying I should have stated it here as vn_V-Items ? I thought the "V-Items AS N" made it clear it was a number variable. Am I still missing something?

                          Comment


                            #14
                            Re: Calculated field and or Variable

                            Hi Preston,
                            I understand how to create calculated fields on a form but they seem to be of little use other than displaying the results on the form.
                            You are correct, that is where they are designed to be used and that is where they would stay. You did not state in your opening thread you wanted to use the values on other layouts.

                            Why cant you keep the value in a table (field)?
                            Regards
                            Keith Hubert
                            Alpha Guild Member
                            London.
                            KHDB Management Systems
                            Skype = keith.hubert


                            For your day-to-day Needs, you Need an Alpha Database!

                            Comment


                              #15
                              Re: Calculated field and or Variable

                              You should not be using a "-" in your variable name. Alpha will think that you wish to subtract a variable "Items" from a variable "V"

                              Allen

                              Declaring a Variable
                              Last edited by Allen Klimeck; 02-01-2012, 12:16 PM.

                              Comment

                              Working...
                              X