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

How do I handle so many calculations?

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

  • johnkoh
    replied
    Re: How do I handle so many calculations?

    Stan,

    Here, new zip files and I changed some of Field rules and added the tables as much I can.

    If you can open my Change_orders form, Please see following my issue
    (1) Move the record - it took about 10 second
    (2) Change field record - it took about 10 second for just ready to edit.
    (3) When I type - it took some time
    (4) After Changed the Rate fields - it took some time for calculation.

    I think, each of my current UDF where I used on the Calculation Value are running until the end itself.

    If each of my UDF does not contain any error, I think, It may be caused by execution structure(flow style), I mean on the Calculation value.

    If slow action was caused by flow style, Can I use some of UDF on the FieldRule or Do you have any better solution?

    Leave a comment:


  • Stan Mathews
    replied
    Re: How do I handle so many calculations?

    Originally posted by johnkoh View Post
    I checked with my zip file, I can see the Bestteam. ALB .ALM. ALX & .Muf. See a screen shot.

    Thank you
    Your zip does not include the tables in your c:\teamwork directory.

    I was able to create a dummy proposals table to eliminate the spec_section field rule error. I was able to create a dummy user_profile table to eliminate the autoexec error. Both these errors were due to the tables they use being in your c:\teamwork directory and not in the c:\changeorders directory. Any tables not in c:\changeorders are not in your zip.

    I do see why you are having sluggish reactiion on the form.


    You changed (for example).

    Code:
    'Customer_Name = lookup("customer","customer_id="+quote(vCustID),"Customer_name")
    to

    Code:
    FUNCTION Customer_Name AS C (vCustId AS C )
    	
        dim tCustom as p
        dim qCustom as p
        dim nCustom as n
        dim vCustName as c
        dim vCustAdd as c
        dim vCustCity as c
        dim vCustState as c
        dim vCustZip as c
        tCustom = table.open("customer",FILE_RO_SHARED)
        query.order ="customer_id"
        query.filter = "customer_id="+quote(vCustId)
        qCustom = tCustom.query_create()
        nCustom = qCustom.records_get()
        if nCustom>0 then
            qCustom.drop()
            vCustName = tCustom.Customer_name
         end if
    	Customer_Name = alltrim(vCustName)
    	tCustom.close()
    END FUNCTION
    Your function is slower than the original single line. You could use Ira's utility to find out how much slower but I would guess it is significantly slower.

    I'm not sure you even need either. A different set structure might allow you to link the customer table and no function/lookup would be needed.

    Leave a comment:


  • johnkoh
    replied
    Re: How do I handle so many calculations?

    Good Morning Stan,

    Before I will send the new zip files, I'd like to ask about

    Your zip does not include the tables/sets in the teamwork directly
    Sorry, I do not understand the " the teamwork directly ".

    I checked with my zip file, I can see the Bestteam. ALB .ALM. ALX & .Muf. See a screen shot.

    Thank you

    Leave a comment:


  • Stan Mathews
    replied
    Re: How do I handle so many calculations?

    I misspoke. It is the proposal table that is not included. You have your database spread across two directories. Teamwork and changeorders.

    Your zip does not include the tables/sets in the teamwork directly, only the changeorders directory. It works on your machine because the teamwork directory exists on your machine.

    The field rules for the spec_section field in the contacts table has a lookup to the proposal table which fails here (something like 150 times).

    Leave a comment:


  • johnkoh
    replied
    Re: How do I handle so many calculations?

    Stan,

    I opened the Zip file which are fine here.
    I attached the 2nd zip files.

    Leave a comment:


  • Stan Mathews
    replied
    Re: How do I handle so many calculations?

    Many of your calculated fields draw info from the contracts table which is not included in your attachment. Can't do much without it as the lack creates multiple errors.

    Leave a comment:


  • johnkoh
    replied
    Re: How do I handle so many calculations?

    Stan,

    We can't answer either question without looking at your application. Viewing the code of one udf doesn't help diagnose that.
    I attached the zip file and open the Change_Orders form.

    Thank you for help.

    Leave a comment:


  • johnkoh
    replied
    Re: How do I handle so many calculations?

    Mike,

    You are right. I changed it to "N" data type.
    Code:
    dim vConvRate as [COLOR="Red"]N[/COLOR]
      vConvRate = convert_type(vAdjRate,"n")  
    dim vItemRate as n
     vItemRate = if(isblank("var->vAdjRate"),vBdgtRate,vConvRate)
    Thank you.

    Leave a comment:


  • Mike Wilson
    replied
    Re: How do I handle so many calculations?

    Yes BUT:
    The variable (vAdjRate) you have collecting the Adjust_fica field value is dimmed Character. Is the Adjust_fica a character field? If so further in your code....
    Code:
    dim vConvRate as c
      vConvRate = convert_type(vAdjRate,"n")
    You are trying to convert the character value in the vAdjRate variable to numeric and have that numeric value in the variable vConvRate which you have dimmed character. Then further down...
    Code:
    vItemRate = if(isblank("var->vAdjRate"),vBdgtRate,vConvRate)
    your if statement is trying to say "have the numeric variable vItemRate be the numeric value vBdgtRate if this, but if not then be the character value of vConvRate". This can't and will not work.

    Leave a comment:


  • Stan Mathews
    replied
    Re: How do I handle so many calculations?

    Originally posted by johnkoh View Post
    My question is why my UDF scripts are running too slow and repeating.
    We can't answer either question without looking at your application. Viewing the code of one udf doesn't help diagnose that.

    Is the table change_hdr the parent table of the set upon which the form is built?

    Code:
    tChangeHd = table.open("change_hdr",FILE_RO_SHARED)
    If so you can probably save some time by getting a pointer to the current instance.

    Code:
    tChangeHd = table.current(1)
    If you don't change that line then you should at least close the table pointer instance somewhere in your function.

    Code:
    tChangeHd.close()

    Leave a comment:


  • johnkoh
    replied
    Re: How do I handle so many calculations?

    Mike,

    My question is why my UDF scripts are running too slow and repeating.

    I selected the Character data type for the "Adj_Rate" field(s) in the table because I want to calculate if the field value contain "0.00" which is not Null value, "Qty * 0.00 = 0.00" and If the field value is Null then use vBdgtRate, "Qty * vBdgtRate = Result".
    I noticed that the Number data type is not able to find the Null value.

    Leave a comment:


  • Mike Wilson
    replied
    Re: How do I handle so many calculations?

    Not quite certain what your question is. I do see significant errors in your code. You have variables dimmed as character mixed in with variables dimmed as numeric. Unless vMtrSum is global, it is not defined in this UDF. And you have numberic variables in you message string, that should return an error.

    Code:
    FUNCTION Calc_ChngOdr_Fica AS N (vChangeOdrId as c)
    	
    'Get field value from Current ChangeOrder form
    dim tChangeHd as p
    dim qChangeHd as p
    dim nChangeHd as n
    
    dim vProjectId as c
    [COLOR="red"]dim vAdjRate as c[/COLOR]
    tChangeHd = table.open("change_hdr",FILE_RO_SHARED)
    query.order="hdr_id"
    query.filter ="hdr_id="+quote(vChangeOdrId)
    qChangeHd = tChangeHd.query_create()
    nChangeHd = qChangeHd.records_get()
    if nChangeHd>0 then	
    	vProjectId = tChangeHd.project_id
    	[COLOR="red"]vAdjRate = tChangeHd.Adjust_fica[/COLOR]
    	
    tChangeHd.close()
    
    'Get the Default value from Contracts table within same project
    dim vBdgtRate as [COLOR="red"]n[/COLOR]  
    vBdgtRate = Bdgt_FicaRate(vProjectId) 
    
    dim vConvRate as [COLOR="red"]c[/COLOR]
      vConvRate = convert_type(vAdjRate,"[COLOR="red"]n[/COLOR]")  
    dim vItemRate as [COLOR="red"]n[/COLOR] [COLOR="red"]vItemRate [/COLOR]= if(isblank("var->vAdjRate"),[COLOR="red"]vBdgtRate[/COLOR],[COLOR="red"]vConvRate[/COLOR])
      
    
    'How to get the Current Items value?   
    dim vTempSum as n  'Toal value of the Labor
    vTempSum = Calc_ChngItm_SumLbr(vChangeOdrId) 'Get the Labor Value for current change order
      'ui_msg_box("Materials","Total material Amount is  "+vMtrSum)
      
    'Final Calulation  
    Calc_ChngOdr_Fica = Round(vTempSum*vItemRate/100,2)
      'ui_msg_box("Final SalexTax","Calculated Salex Tax is  "+"co"+vChangeOdrId +" rate  " +vItemRate+"  and Result Value is  "+Calc_ChngOdr_Fica)
    
    end if
    END FUNCTION
    Last edited by Mike Wilson; 12-21-2010, 10:57 AM.

    Leave a comment:


  • johnkoh
    replied
    Re: How do I handle so many calculations?

    Good Morning,

    I have about 20 calculation UDF and 3 of the tablesum() function on a form and used it on the calculation value expression.

    The form is running too slow so I added the Ui_msg_box() on one of the UDF. Whenever open or closed this form, the same message is shown several times until the end of related UDFs.

    Is the way faster and avoid the repeating the scripts?
    One Sample of my UDF.
    Code:
    FUNCTION Calc_ChngOdr_Fica AS N (vChangeOdrId as c)
    	
    'Get field value from Current ChangeOrder form
    dim tChangeHd as p
    dim qChangeHd as p
    dim nChangeHd as n
    
    dim vProjectId as c
    dim vAdjRate as c
    tChangeHd = table.open("change_hdr",FILE_RO_SHARED)
    query.order="hdr_id"
    query.filter ="hdr_id="+quote(vChangeOdrId)
    qChangeHd = tChangeHd.query_create()
    nChangeHd = qChangeHd.records_get()
    if nChangeHd>0 then	
    	vProjectId = tChangeHd.project_id
    	vAdjRate = tChangeHd.Adjust_fica
    	
    tChangeHd.close()
    
    'Get the Default value from Contracts table within same project
    dim vBdgtRate as n
      vBdgtRate = Bdgt_FicaRate(vProjectId) 
    
    dim vConvRate as c
      vConvRate = convert_type(vAdjRate,"n")  
    dim vItemRate as n
     vItemRate = if(isblank("var->vAdjRate"),vBdgtRate,vConvRate)
      
    
    'How to get the Current Items value?   
    dim vTempSum as n  'Toal value of the Labor
    vTempSum = Calc_ChngItm_SumLbr(vChangeOdrId) 'Get the Labor Value for current change order
      'ui_msg_box("Materials","Total material Amount is  "+vMtrSum)
      
    'Final Calulation  
    Calc_ChngOdr_Fica = Round(vTempSum*vItemRate/100,2)
      'ui_msg_box("Final SalexTax","Calculated Salex Tax is  "+"co"+vChangeOdrId +" rate  " +vItemRate+"  and Result Value is  "+Calc_ChngOdr_Fica)
    
    end if
    END FUNCTION

    Leave a comment:


  • Steve Andrews
    replied
    RE: How do I handle so many calculations?

    Howard,

    I agree with Ira that functions may be the way to go even though efficiency will still be questionable. While converting a system from V1 to V5, I encountered a dozen or so reports each of which contained the same set of calculated fields - about 25 of them nested and very complicated. I wrote one UDF which replaced all of these calculated fields.

    Aside from efficiency, there are two main advantages of using a UDF. First, debugging is much easier. When we had a question about some figures on the older reports, we had to go through by hand and reproduce every calculated field to analyze the problem. With the UDF, we can use debug() to see exactly what is going on with the calculations.

    Secondly, in cases like mine with duplicated calculations between layouts the UDF will assure consistency. In my transformation I discovered a few inconsistencies due to mistyping. Also, if there are any future changes in the criteria which governs the calculations, we now only make the change at one place (my UDF) rather than going to each report to make the same change.

    So in general when expressions get to lengthy or calculated fields of a layout get too complicated, I prefer using xbasic in a UDF. My 2 cents.

    Steve

    Leave a comment:


  • csda1
    replied
    RE: How do I handle so many calculations?

    Howard,

    Form calculations (at least in their current and past incarnations) are real inefficient. As the calculations can be based upon other calculations, they are actually executed many times as you fetch a record and move from field to field in a form. Most times this is not an issue, as the speed degradation is not noticable to the user. On the other hand, you can manually (well sort of - I really mean XBasic or Action script) have variables set to your calculation values as you fetch or enter a record, move in and out of paticular fields, or when you save the record. These have the advantage of only being recalculated when you decide a particular field that the calculation is based upon has changed.

    Not much fun manually coding, but it can enhance the snappiness of the display and values.

    On the other hand, if you can improve the efficiency of your form calculations, it might not be needed. The expressions you used can be often recoded with faster functions, and the nesting can be unrolled (basically using longer expressions to include the other calculation's expression). This unrolling can be, but may not always be, more efficient.

    Finally, sometimes calculation expressions can be done more efficiently using XBasic code in functions that perform part or all of the calculations in a more efficient way than a single expression line can do.

    Regards,

    Ira

    Leave a comment:

Working...
X