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 you open Sub- UDF from parent UDF

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

    How do you open Sub- UDF from parent UDF

    Hi All,

    I have the parent(Main) UDF which
    Code:
     
    Function Get_Quantity as n (prdctId as c, vQty as n)
           'Some of action for open tables and get the information.
           '
           ' I have the conditions to calculate here
           If vTypeofMaterial ="abc" then
                   variable_A = Calculate as 123.....
                   
           else  
                 variable_A = Open_sessame    'Call the 2nd UDF which get the Calculated Value
                [COLOR="#B22222"] 'I have the trouble here. it opens the 2nd UDF but does not stop.
      
                 'I inserted the Ui_msg_box() here for test, This Msg_box opens all the time. It did not stop until terminating A5.[/COLOR]
                  
           end If
           'Write the Result
                  Get_Quantity =  variable_a+(variable_A * vWaste/100)
    End Function
    Why did the 2nd condition not work?

    #2
    Re: How do you open Sub- UDF from parent UDF

    Code not shown.

    Comment


      #3
      Re: How do you open Sub- UDF from parent UDF

      Open_sessame() is the name of a udf as well?

      variable_A = Open_sessame()
      There can be only one.

      Comment


        #4
        Re: How do you open Sub- UDF from parent UDF

        Tom and Stan

        When you read more than one tables in the scripts, do you recommend to close the table right after procedure which case A or Case B, closing the end of scripts.

        Case A
        Code:
         
                tPrd = table.open("prdcts",FILE_RO_SHARED)
        	query.order=""
        	query.filter="alltrim(prod_id) ="+quote(vPrdId)
        	qPrd = tPrd.query_create()
        	rPrd = qPrd.records_get()
        	if rPrd>0 then
        		vGrpId = alltrim(tPrd.Group_id)
                        vSeriesId = alltrim(tPrd.Series_id)
        	end if	
        	[COLOR="#FF0000"]qPrd.drop()
        	tPrd.close()[/COLOR]
        
                tSer = table.open("series",FILE_RO_SHARED)
        	query.order=""
        	query.filter="series_id="+quote(vSeriesId)
        	qSer = tSer.query_create()
        		vMtrType = alltrim(tSer.Mtr_type)
        	[COLOR="#FF0000"]qSer.drop()
        	tSer.close()[/COLOR]
        Case B
        Code:
         
                tPrd = table.open("prdcts",FILE_RO_SHARED)
        	query.order=""
        	query.filter="alltrim(prod_id) ="+quote(vPrdId)
        	qPrd = tPrd.query_create()
        	rPrd = qPrd.records_get()
        	if rPrd>0 then
        		vGrpId = alltrim(tPrd.Group_id)
                        vSeriesId = alltrim(tPrd.Series_id)
                           
                            'Read 2nd table
                           tSer = table.open("series",FILE_RO_SHARED)
        	           query.order=""
        	           query.filter="series_id="+quote(vSeriesId)
        	           qSer = tSer.query_create()
                           rSer = tSer.Records_get()
                           if rSer > 0 then
        		         vMtrType = alltrim(tSer.Mtr_type)
        	           else
                                 'Shown the message by  UI_msg_box()
                           end if
          [COLOR="#FF0000"]                 qSer.drop()
        	           tSer.close()
        	end if	
        	qPrd.drop()
        	tPrd.close()[/COLOR]

        My UDF Scripts and not shown the 2nd UDF.
        I used this UDF at Calculation Value, " xPoqty = Est_PoQty_calc (prdId, qty, uom) "

        Code:
         
        'void all of the DIMs and variable name
         
        FUNCTION Est_Poqty_calc AS N (vPrdId AS C,vEstQty as n,vEstUom as c)
                tPrd = table.open("prdcts",FILE_RO_SHARED)
        	query.order=""
        	query.filter="alltrim(prod_id) ="+quote(vPrdId)
        	qPrd = tPrd.query_create()
        	rPrd = qPrd.records_get()
        	if rPrd>0 then
        		vGrpId = alltrim(tPrd.Group_id)
                        vSeriesId = alltrim(tPrd.Series_id)
        	end if	
        	qPrd.drop()
        	tPrd.close()
        
                tSer = table.open("series",FILE_RO_SHARED)
        	query.order=""
        	query.filter="series_id="+quote(vSeriesId)
        	qSer = tSer.query_create()
        		vMtrType = alltrim(tSer.Mtr_type)
        	qSer.drop()
        	tSer.close()
           
                [COLOR="#B22222"]'Condition 
                       If vMtrType ="Dir" then
                            vConvQty = vEstQty
                            'Some other calcuation here
                       else
                            vConvQty = Est_Indirect_poqty (** Tried put the variable too here) 
                       end if[/COLOR]
                
         'Result and want to shown of the Form
                     Est_Poqty_calc = vConvQty + (vConvQty * vWaste/100)
        
        End Function
        It runs fine without the " Else " case but I have the trouble whenever / whatever on " else " case.

        Comment


          #5
          Re: How do you open Sub- UDF from parent UDF

          John,
          Your Case A and B both would work. Typically, if you are finished with a table after opening, close it.. ie - Case A. But since you are using values from the Prdcts table to access a record in the Series table, you could use the existing table pointer to get those values instead of writing the Products field values to variables and using the variables to access the Series table. To accomplish the latter, you would need the products table to remain open and point to it to get the field values to address the Series table, and close it at the end, as you have in Case B. I have begun using <prt2>=<ptr1>.order() to query tables. It is less coding, seems to be faster, and you don't have to drop() it at the end. To do what I am describing, the code, derived from your Case B would be this:
          Code:
             tPrd = table.open("prdcts",FILE_RO_SHARED)
              qPrd=tPrd.order("","prod_id ="+quote(vPrdId))          'another method to filter table
              rPrd = qPrd.records_get()
                   if rPrd>0 then
                      vGrpId = alltrim(tPrd.Group_id)
                     [COLOR="#0000FF"] 'vSeriesId = alltrim(tPrd.Series_id)[/COLOR]    ' not needed anymore here
                   'Read 2nd table
                         tSer = table.open("series",FILE_RO_SHARE)
                         qSer=tSer.order("","series_id="+quote([COLOR="#FF0000"]tPrd.Series_id[/COLOR]) 'pointer gets value
                         rSer = tSer.Records_get()
                             if rSer > 0 then
          		         	vMtrType = alltrim(tSer.Mtr_type)
          	           else
                                   'Shown the message by  UI_msg_box()
                             end if
                             tSer.close()
          	end if	
          	tPrd.close()
          Mike W
          __________________________
          "I rebel in at least small things to express to the world that I have not completely surrendered"

          Comment


            #6
            Re: How do you open Sub- UDF from parent UDF

            John
            Can you clarify your question.
            Are you asking about when to close files, or an else condition or what the post says?
            I cant see where there is a second UDF call, maybe I am stupido but I have read thru all the codes a few times.

            Comment


              #7
              Re: How do you open Sub- UDF from parent UDF

              Hi

              Sorry, I was out of office all day.

              Thank you Mike, for "<tbl>.order()" info.

              Ray,
              Sorry for confusing. My question is still remain as why did the 2nd(on else) condition hold or ran forever?

              On the "else" condition, I deleted and inserted the Ui_msg_box(), the Message shows all the time.


              'Condition
              If vMtrType ="Dir" then
              vConvQty = vEstQty
              'Some other calcuation here
              else
              vConvQty = Est_Indirect_poqty (** Tried put the variable too here)
              end if

              Comment


                #8
                Re: How do you open Sub- UDF from parent UDF

                John,

                In your function you run a query and then retrieve a field value from the "found" record. That "found" field value is then used in your IF.. ELSE..END IF code block.

                This will not work because the script in your function DOES NOT WAIT for the query to be completed before executing (or attempting to execute) the statements which follow. Instead, the query is run in a separate thread, and the script continues to run without stopping until the query has finished. In your script that means the variable vMbrType has no value... indeed it doesn't even exist... when the IF..ELSE..END IF code block begins.

                -- tom

                Comment


                  #9
                  Re: How do you open Sub- UDF from parent UDF

                  John,

                  FWIW, I think you've chose a slow way to "find" a record. If you are looking for a single record resist the temptation to run a query against the whole table. Instead, set an index and do a find by key. No query is necessary if the desired record can be found using an indexed search.

                  Comment


                    #10
                    Re: How do you open Sub- UDF from parent UDF

                    Tom,

                    Thank you. I think this a solution
                    run a query and then retrieve a field value from the "found" record
                    I will try now and let you.

                    Comment


                      #11
                      Re: How do you open Sub- UDF from parent UDF

                      Tom,

                      I gave up to use the Index because my Index is not stabilize, some reason, after packing or update index, the index name was changed by A5.

                      Comment


                        #12
                        Re: How do you open Sub- UDF from parent UDF

                        Originally posted by johnkoh View Post
                        Tom,

                        I gave up to use the Index because my Index is not stabilize, some reason, after packing or update index, the index name was changed by A5.
                        Make the index name 10 characters or less...
                        Start with a letter and only use letters, numbers, or underscore _
                        Al Buchholz
                        Bookwood Systems, LTD
                        Weekly QReportBuilder Webinars Thursday 1 pm CST

                        Occam's Razor - KISS
                        Normalize till it hurts - De-normalize till it works.
                        Advice offered and questions asked in the spirit of learning how to fish is better than someone giving you a fish.
                        When we triage a problem it is much easier to read sample systems than to read a mind.
                        "Make it as simple as possible, but not simpler."
                        Albert Einstein

                        http://www.iadn.com/images/media/iadn_member.png

                        Comment


                          #13
                          Re: How do you open Sub- UDF from parent UDF

                          John, it's possible that using a "faster" technique to find the desired record will solve your problem. However, the most reliable way to overcome a "timing" issue like this is to use separate user defined functions. Your script will halt until a user defined function has completed its work. Then it will resume. So, if it were me I'd put the code that's retrieving the desired field value into its own function,

                          Comment


                            #14
                            Re: How do you open Sub- UDF from parent UDF

                            Tom,

                            I think it caused more than "Find" problem Because
                            I tested this UDF and applied on Calculate Value as (Case 1) xPoQty = Est_poqty_calc2(EstQty) or (Case 2) xPoQty = if(EstQty> 0.01, Est_poqty_calc2(EstQty), 0).

                            After added the xPoQty field into a browse
                            a) the design mode is shown the Ui_get_text() box until end of record and stop
                            b) If I change the mode, Ui_get_text() box is displayed and does not stop nor does not close
                            c) If I click on a field, Ui_get_text() box is displayed and does not stop nor does not close


                            Code:
                             FUNCTION Est_poqty_calc2 AS N ( vEstQty as n )
                            
                            'Test Shown the Ui_get_text
                            vMtrType = ui_get_text("Test","enter dir or Ind")
                            	
                            	if vMtrtype="dir" then
                            		Est_poqty_calc2 = vEstQty
                            	
                            	elseif vMtrtype="Ind"
                            		Est_poqty_calc2 = vEstQty * 2
                            	else
                            		ui_msg_box("Error","No records  "+crlf()+vMtrtype)
                            		cancel() 'end 
                            	end if
                            END FUNCTION
                            I am not sure that why this UDF works well and the other does not.

                            On Calculated value, xDeduct = if(Estitem->out_Yn=.t.,Est_Deduct_qty(Estitem->Prod_Id,Estitem->Estqty,Estitem->Estuom),0)

                            Code:
                            FUNCTION Est_Deduct_qty AS N (vPrdctId AS C, vEstQty as n, vEstUom as c )
                            'get the ShapeId from prdct table
                            	dim tPrd as p
                            	dim qPrd as p
                            	dim vShapeId as c
                            	tPrd = table.open("prdcts",FILE_RO_SHARED)
                            	query.order=""
                            	query.filter="prod_id ="+quote(vPrdctId)
                            	qPrd = tPrd.query_create()
                            		vShapeId = alltrim(tPrd.Shape_id)
                            	qPrd.drop()
                            	tPrd.close()	
                            		'get the waste rate, size from Shape table
                            		dim tShape as p
                            		dim qShape as p
                            		dim vShapeId as c
                            		dim Shared vLength as n
                            		dim shared vAreaUnit as n
                            			Shape_info(vShapeId)
                            		
                            	'Calculate the est Qty, Convert to each pc Condition
                            	dim vPieces as n
                            	if vEstUom = "sqft" then
                            		Est_Deduct_qty = vEstQty
                            	elseif vEstUom ="lnft" 
                            		Est_Deduct_qty = round(vEstQty*12/vLength*vAreaUnit,2)	
                            	else if vEstUom = "each" 
                            		Est_Deduct_qty = round(vEstQty*vAreaUnit,2)	    
                            	end if
                            END FUNCTION

                            Comment


                              #15
                              Re: How do you open Sub- UDF from parent UDF

                              John,

                              Me understand you not.

                              Comment

                              Working...
                              X