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 Value Wows..

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

    Calculated Value Wows..

    Ok, I have been working on a new little app and this time around I decided to do a lot of the math using calculated values on the form instead of using calculated fields in the table or intense scripts.

    On the surface it all works fine for the math on the form but I also need one Calculated Value that is a total of several other calculated values to be written to a field in a table so it can be used on other forms without having to recreate all the calculated values again and again on each form.

    There is no direct way to put a calculated value on a form into a field of a table so I tried the following.

    vn_subtot = CALC->Price_Subtot
    parentform:SUBTOT.value = vn_subtot

    And Also;

    parentform:SUBTOT.value = CALC->Price_Subtot


    Now here is the screwy part.

    For awhile it will work with the;
    vn_subtot = CALC->Price_Subtot
    parentform:SUBTOT.value = vn_subtot

    Then that will stop working and throw a script error so I switch to;
    parentform:SUBTOT.value = CALC->Price_Subtot

    And then that will work for a while and then start throwing a script error.

    Basically every time it throws a script error I just change the script method and it starts working again for a little while. Which make absolutely no sense. What is even weirder is when I use the variable vn_sutot to store the value and then write it to the SUBTOT.value, the variable vn_subtot remains zero even though it transfers the value of Calc->Price_Subtot to the SUBTO.value

    script-error.png

    Unless I can find a simple and reliable way to store the values in Calculated Values on a form into a table field, I think I will not try and use Calculate Values anymore.

    #2
    Re: Calculated Value Wows..

    Instead of:
    vn_subtot = CALC->Price_Subtot
    use the same expression you used to calculate CALC->Price_Subtot
    IOW:
    If you used Price_Subtot=ABC+XYZ
    Then do:
    parentform:SUBTOT.value =ABC+XYZ

    Comment


      #3
      Re: Calculated Value Wows..

      Originally posted by G Gabriel View Post
      Instead of:
      vn_subtot = CALC->Price_Subtot
      use the same expression you used to calculate CALC->Price_Subtot
      IOW:
      If you used Price_Subtot=ABC+XYZ
      Then do:
      parentform:SUBTOT.value =ABC+XYZ
      That would require writing about 100 lines of code to replicate all the Calculated Values on the form that affect the final value in Calc->subtot as Calc->subtot is a calculation of Calculated Values. If I was going to do that, what is the point of ever using Calculated Values in the first place?

      I am using this now and it is working but I will need to see if it remains stable.

      DIM window_name as C
      window_name = ":"+"Estimates"
      DIM varP_Object as p
      'Get a pointer to the specified window
      varP_Object = obj(window_name)
      'Check if the specified window exists
      if .not. is_object(varP_Object) then
      ui_msg_box("Error","The window '"+window_name+"' does not exist.",ui_stop_symbol)
      else
      DELETE expression_result 'Clear any possible previous expression result
      expression_result = eval("CALC->Price_Subtot",form_name)
      varP_Object:SUBTOT.value = expression_result
      end if

      Comment


        #4
        Re: Calculated Value Wows..

        Hi Preston,
        Have you tried creating some of the calcs at the table level when you structure it instead of the form level? Then they will be available to any form that uses the table. Just an idea...
        Robin

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

        Comment


          #5
          Re: Calculated Value Wows..

          Preston,

          To which event have you tied your script?

          -- tom

          Comment


            #6
            Re: Calculated Value Wows..

            Originally posted by Tom Cone Jr View Post
            Preston,

            To which event have you tied your script?

            -- tom
            A button push. I do not have it automatically fire from any other event happening on the form.

            Comment


              #7
              Re: Calculated Value Wows..

              Originally posted by MoGrace View Post
              Hi Preston,
              Have you tried creating some of the calcs at the table level when you structure it instead of the form level? Then they will be available to any form that uses the table. Just an idea...
              That is the way I have done it in the past. I was just hoping this would work as it would keep me from having to search through a tables calculated fields to find the right one to make adjustments if needed.

              Also the math I use is very complex so it would require a lot of extra fields to break the math up due to expression length limitations in calculated fields.

              Comment


                #8
                Re: Calculated Value Wows..

                Preston,

                I honestly preferred using script/udf's(mostly) for this. I tried field rules, calc fields and some other in the forms. It became clear that using scripts and udf's worked much better and much faster over all.

                My calculations for car dealers have to compute payments for sales and leasing, including monthly/weekly/quarterly/semi-annual/2 weeks/2 times a month payments as well as all other computations. I even had to write my own payment functions because alpha's were too far off to comply with the Federal regulation-Z. I also have to contend with printing payment coupons, and contracts. Doing sales tax forms and computations for end of month.

                Generally, a sale/lease will go through 5 scripts and 2 udf's before a payment is generated to the penny. The scripts and udf's vary with the choices, of course.
                Dave Mason
                [email protected]
                Skype is dave.mason46

                Comment


                  #9
                  Re: Calculated Value Wows..

                  Looking at Gabe's example - if the calcs were defined for the table, then that calc could be set as the default value for the field in the field rules. That would allow the amount to be overwritten in the form using a 'recalc' button...

                  Also, I remember early on reading that calcs needed to be written in a logical order and how they are placed in the tab order of the form can make a difference also.

                  Edit: The logical sequence would probably apply to calcs that use other calcs. But if your fields are populated with default values, at least you wouldn't have to deal with blank values when entering a new record. Or you could set your numeric defaults to 1 instead of 0 ... hard to guess without seeing the form.

                  In my payroll app I have lots of calculations and the only way to get some of the calcs to update when the data is changed is to change a value in a non essential field, save the record, then edit it back. Hence the recalc button.
                  Last edited by MoGrace; 01-24-2015, 06:01 PM.
                  Robin

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

                  Comment


                    #10
                    Re: Calculated Value Wows..

                    Most of my scripts/functions are triggered with an onfielddepart event. The fields on the form get populated and a refresh is done to make them visible.
                    Some/many of the fields on the form are variables and get written to the table(s) on saving. Much faster that way too.
                    Dave Mason
                    [email protected]
                    Skype is dave.mason46

                    Comment


                      #11
                      Re: Calculated Value Wows..

                      There is no direct way to put a calculated value on a form into a field of a table

                      Onfetch code for form

                      parentform.commit()
                      Tbl = table.current()
                      tbl.change_begin()
                      tbl.whateverfieldname = calc->calcfieldname
                      tbl.change_end()
                      There can be only one.

                      Comment


                        #12
                        Re: Calculated Value Wows..

                        The numbers of calc fields I had to do slowed the loading of the form. I suspect it still does that in v11 and v12??
                        Dave Mason
                        [email protected]
                        Skype is dave.mason46

                        Comment


                          #13
                          Re: Calculated Value Wows..

                          Getting back to this thread..
                          Why would you have to re-write "100's" of lines of code?
                          How many times do you assign this calc value to that field?
                          I would think only once, unless there is more to your script that doesn't meet the eye.
                          Also, in a situation like this, you do not have to re-write anything. Just simply copy/paste the expression and use the editor to find/replace..
                          But assuming all of this does not apply to your situation.. the bad news is you are trying to swim against the tide and thus you are meeting this resistance.
                          Alpha, once you initialize a form, the first thing it will do (and I showed that in a previous thread many years ago) is to run the calc fields on the form, first and foremost.
                          Unfortunately, alpha does not recalc these values each time you push a button.
                          What does that tell in terms of possible solutions?
                          You will have, somehow, to force alpha to recalc these values.
                          How?
                          There is a method to recalc all calc fields that apply to the table, but to my knowledge none for a form.
                          So, now what?
                          You could either:
                          1-Change the value (and change it back) of one of the calculations dependencies to force alpha to recalc, or
                          2-Load a second instance of the form right before assigning the calc value to the field, or
                          3-Add the value to the field at the table level and re-synch the form
                          All of the above is a long winded round about ways to do something that you shouldn't have had to deal with in the first place. And I say that, because this issue and related ones came up way too many times in the past where peope want to take the value of a calc field and do something with it, either assign it to a field, update a table, a report or something similar loosing sight of where this value came from in the firat palce.

                          Comment


                            #14
                            Re: Calculated Value Wows..

                            Gabe makes sense. If the field needs to be a calculated value, then the calc goes there. Otherwise if the calcs are for the purpose of a report, let it do the calcs with the table values. You can also embed a report preview into a form and provide links back to the record. Unless the calcs are fairly simple, i would expect the overhead on the form would be very slow - especially during data entry, which ought to be fast.

                            Most of my forms use vars to hold the totals I want to see, and those can be posted to the table if necessary.

                            So many ways to skin a cat!
                            Robin

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

                            Comment


                              #15
                              Re: Calculated Value Wows..

                              Don't use the forms to do the calcs. That is what scripts and functions are for. Robin, Wise to use the vars to hold the totals. They can be assigned by the scripts as they run.

                              My rule on functions: If you have to write the code more than 2 times, make it a function.
                              Dave Mason
                              [email protected]
                              Skype is dave.mason46

                              Comment

                              Working...
                              X