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

Global User Functions, question...

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

    Global User Functions, question...

    Greetings,

    When you create functions, do they each individually have to be in a separate script/function file in the Code tab or can you create a script/file that has several associated functions in it?

    Regards,
    Keith
    Keith Weatherhead
    Discus Data, Ltd
    [email protected]

    #2
    Originally posted by KeithW
    .... can you create a script/file that has several associated functions in it?
    The short answer to the above is yes. I do not have time right now to give you examples. If you need one, ask and I am sure someone will oblige (me, I'm leaving on a vacation!).

    Ray

    Comment


      #3
      Keith,

      You can have more than 1 function inside a UDF entry, but only the 1 with the same name as the entry is accessible from everywhere.

      All the rest of the functions that are inside a UDF entry are accessible only to any other function within that UDF.
      Regards,

      Ira J. Perlow
      Computer Systems Design


      CSDA A5 Products
      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
      CSDA Barcode Functions

      CSDA Code Utility
      CSDA Screen Capture


      Comment


        #4
        Here's a little example that may be illuminating. Put it in it's own script and run it. You'll want to make sure you don't have other global functions named Set_name() and Show_name() to keep the confusion down.

        Code:
        dim global vname as C
        Set_name()
        Show_name()
        end 
        
        Function Set_name as C()
        	vName = "Keith"
        end function
        
        Function Show_name as A()
        	ui_msg_box("Hello", vName)
        end function
        -Steve
        sigpic

        Comment


          #5
          Here's an example of Ira's comment:
          Code:
          FUNCTION Full_name as C ( fname as C, lname as C )
             full_name = f_upper( alltrim( fname )) + " " + f_upper( alltrim( lname ))
             IF at( " ", full_name, 2 ) > 0
                show_warning( full_name )
             END IF
          END FUNCTION
           
          FUNCTION show_warning as C ( name_in as C )
             msg = "This name is a 'complex' name consisting of more than a simple first and last name:" +crlf(2)
             msg = msg + name_in
             ui_msg_box( "WARNING", msg, 48 ) 
          END FUNCTION
          If this is saved as a UDF named "Full_name", only the Full_name function will be accessible as a Global UDF. However, the "show_warning" function can be accessed by the main function or, if there were others, by any other function within the main function.

          Of course, something this simple wouldn't really need a second function. It's only an example.

          FYI: The placement of the main function isn't important. The Show_warning function could have been placed ahead of the Full_name function. As long as the saved name matches one of the functions within the script, that function will be considered the 'main' function.

          Comment


            #6
            Thank you Cal for illustrating what I said.

            I'll also add one other point, just to be complete.

            If there is an external function name and an internal function with the same name, the internal one will be the one that is executed if called from within that code entry. It also has the slight advantage of being marginally faster than an external one.
            Regards,

            Ira J. Perlow
            Computer Systems Design


            CSDA A5 Products
            New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
            CSDA Barcode Functions

            CSDA Code Utility
            CSDA Screen Capture


            Comment


              #7
              Use a local udf in a scripted operation?

              Originally posted by csda1
              Thank you Cal for illustrating what I said.

              I'll also add one other point, just to be complete.

              If there is an external function name and an internal function with the same name, the internal one will be the one that is executed if called from within that code entry. It also has the slight advantage of being marginally faster than an external one.
              Any one have experience with something like

              update.expr1 = "st_decy(Prdamt)"

              where update.expr1 is part of an update operation converted to xbasic and st_decy() is a udf?

              If the udf is visible on the code tab, thus globally defined, the script runs to completion. If I move the function into the script it seems to work but if I rename the global function the script fails with the error

              Variable update.expr1 expression - Function is not recognized.
              If I add a line to the script earlier than the update, ui_msg_box("","Converted is "+st_decy("0000a")), the result of the local function is displayed.
              There can be only one.

              Comment


                #8
                Originally posted by Steve Workings
                Here's a little example that may be illuminating. Put it in it's own script and run it. You'll want to make sure you don't have other global functions named Set_name() and Show_name() to keep the confusion down.

                Code:
                dim global vname as C
                Set_name()
                Show_name()
                end 
                
                Function Set_name as C()
                	vName = "Keith"
                end function
                
                Function Show_name as A()
                	ui_msg_box("Hello", vName)
                end function

                Thanx to all for the illustrations, as they say, "a picture is worth a 1,000 words" ... now I'm sure I can dig a deeper hole than I have done so far !!

                Thanx All !
                Keith
                Keith Weatherhead
                Discus Data, Ltd
                [email protected]

                Comment


                  #9
                  Stan,

                  Basically, only internal functions can only be used by internal code. You are setting a global variable, update.expr1, with a string, that contains a reference to a UDF. At some point, you are running the update function (which is external), which then does an eval() of the string. It does not have any context to the internal function and thus fails.

                  Thus when you move the code internally, any calls to it internally would work, but the update function is external, and use the external one. If you change the name of the external one, the update can't find it.

                  Is that clear?
                  Regards,

                  Ira J. Perlow
                  Computer Systems Design


                  CSDA A5 Products
                  New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                  CSDA Barcode Functions

                  CSDA Code Utility
                  CSDA Screen Capture


                  Comment


                    #10
                    As always, to the point.

                    Originally posted by csda1
                    Stan,

                    Basically, only internal functions can only be used by internal code. You are setting a global variable, update.expr1, with a string, that contains a reference to a UDF. At some point, you are running the update function (which is external), which then does an eval() of the string. It does not have any context to the internal function and thus fails.

                    Thus when you move the code internally, any calls to it internally would work, but the update function is external, and use the external one. If you change the name of the external one, the update can't find it.

                    Is that clear?
                    Makes sense now. I was seeing the coded operation as purely scripted but it really just establishes the variables for the tbl.update().

                    Thanks for the clarification.
                    There can be only one.

                    Comment


                      #11
                      Re: Ira's comment on speed.

                      Functions are always (as far as I can determine anyway) slower than in-line code. Even functions internal to a script are slower. There seems to be an "overhead" in starting the function; the internal code runs just as fast once the function is running.

                      So, my policy is to use functions when:
                      - Speed is not an issue. (Remember, we are usually talking milliseconds here so speed is usually only an issue in loops.)
                      - The same routine will be used in many locations and/or apps and: (a) I don't want to retype or cut-and-paste and (b) far more important, if it ever has to be changed, I only want to change it in one place.

                      I know Ira uses functions much more than I do. In his case, the philosophy may be more like, "If speed becomes an issue, consider eliminating some function calls."

                      Comment


                        #12
                        Cal,

                        Well of course (may be obvious to some) that inline code would always be faster. But if you (not you, people in general) are creating a function that the overhead of the function call is critical to the speed, then you probably haven't partitioned the problem into a large enough chunk to be efficient.

                        But functions have other advantages which is why I always use them (even as a wrapper for just a regular script of code).

                        1. They can be invoked from expressions within Alpha 5, e.g. a calculated field expression

                        2. They can have a variety of arguments, allowing the same code to be used in many cases

                        3. Function calls by their very nature must complete before continuing in the active thread. That's not always true of in-line code. Thus they perform effectively a more reliable wait (which is probably why I never seem to have sync issues)

                        As for speed of in-line code, the code runs identical whether within a function or just in a script, so why not put a function wrapper around it? It is also easier to write

                        function_name()

                        versus

                        Script_play("function_name")

                        I haven't investigated the overhead of a function call versus the Script_play(), but I suspect they are closer in overhead than not.
                        Regards,

                        Ira J. Perlow
                        Computer Systems Design


                        CSDA A5 Products
                        New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                        CSDA Barcode Functions

                        CSDA Code Utility
                        CSDA Screen Capture


                        Comment


                          #13
                          Speed of UDF vs Script_Play()

                          Cal et al,

                          Originally posted by csda1
                          I haven't investigated the overhead of a function call versus the Script_play(), but I suspect they are closer in overhead than not.
                          I actually was surprised, but the overhead of calling a global script versus a UDF function call with identical code was not what I expected. I further ran tests with inline code, UDF code, evaluate_template() and script play(). All the code executed a simple assignment of a constant z=1. The speeds from best to worst (normalized times in seconds for the code to execute is next to them);

                          z=1 ' .000019124 sec
                          z=x() ' .00018280 sec
                          evaluate_template("z=1") ' .00021158 sec
                          script_play("y") ' .00265600 sec


                          Without a doubt, there is no advantage to using script_play() ever (unless required to)! It is 15 times slower than a UDF call.

                          evaluate template() needs to compile the code, and is much better than the script_play() but not as good as the UDF call. And of course, inline code is by far the fastest. Thus, if you have a trivial amount of code, better to include it than to call a UDF if speed is a requirement.
                          Regards,

                          Ira J. Perlow
                          Computer Systems Design


                          CSDA A5 Products
                          New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
                          CSDA Barcode Functions

                          CSDA Code Utility
                          CSDA Screen Capture


                          Comment

                          Working...
                          X