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

UDF with undetermined number of arguments

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

    UDF with undetermined number of arguments

    It appears that the only way to construct such function is to use optional parameters, which will make for a rather very lengthy syntax and, strictly speaking, with a limited number of arguments.
    Is there any other means to accomplish this?
    Thanks.

    #2
    Re: UDF with undetermined number of arguments

    G,

    I'm not sure that I understand your question fully nor what you intend to accomplish, but one approach which may work for you is to pass it one parameter - a pointer.

    There have been times when I have wanted to do some processing on a given record of a table without including all of the code at the place I am currently at (e.g. the expression of a calculated field). I would get a pointer to the current table and pass that pointer to a UDF. The UDF would then have all of the fields of that record handy.

    Likewise, you could construct a dot variable and pass the pointer. This allows you to easily pass many parameters without specifying each within the syntax of the UDF. However, why you would ever want an "undetermined" number of parameters is beyond me.

    My 2 Cents,
    Steve

    Comment


      #3
      Re: UDF with undetermined number of arguments

      Originally posted by G Gabriel View Post
      It appears that the only way to construct such function is to use optional parameters, which will make for a rather very lengthy syntax and, strictly speaking, with a limited number of arguments.
      Is there any other means to accomplish this?
      Thanks.
      Use a pointer/dot variable.

      Look at the example on this help page.

      Using Pointers and Dot Variables with Functions

      (Like Steve said...)
      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


        #4
        Re: UDF with undetermined number of arguments

        Alpha's UDF does not have the ability to get the function call line, or just the arguments as a string to process prior to it error'ing in the execution of the function if the # of arguments exceed that specified in the function definition. Many languages do, and you can process "Arg0" as it is typically called.

        If there is a maximum number of arguments, you can define the function to handle that maximum or smaller, but never bigger.

        It might be possible to build a function on the fly using a "F" function type pointer to meet the number of arguments, but you would need an error handler at that level of the original call. It would need to trap the error, get the line text of the error, and process the line again with a replacement function you built on the fly.

        I don't believe that will help you for normal coding, as it assumes you can trap the error from outside the function, not inside.

        The only really usable solution for Alpha 5 is to pass 1 argument as a string, pointer or similar that is then processed as multiple arguments after parsing it (which for a string containing al arguments, can be difficult if you have expressions as arguments)
        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


          #5
          Re: UDF with undetermined number of arguments

          A pointer will not work here. Or perhaps I should say, it would but will be very awkward.
          Let me illustrate:
          An example of a function that has an undetermined number of arguments is something like case().
          In case() you could enter 2 conditions or a hundred (though the help file says 16, actually it's a whole lot more than a hundred).

          If you create a UDF in alpha and specify your arguments, then if you add more arguments than the "hard-coded" allotted number of arguments at execution time, the function will fail and you will get an error message "too many parameters" or something along these lines.

          You can (less desirable work around) enclose all these arguments in one string or a pointer and let the function parse it. No problem here, but not the desired effect. The desired effect is to have something like case() and about the only way I could surmise alpha does it is by vertue of optional parameters.

          Which leads me to another thought from a different orbit:
          Did alpha impose the 16 conditions limit because they just implemented 16 optional parameters only? which leads to another thought from another stratosphere: if that's the case, then if you put a bunch of optional parameters of the same variable, would that lead to undetermined number of arguments? that might be the answer from Mars, but I haven't tested it yet.
          Last edited by G Gabriel; 12-30-2008, 05:03 PM.

          Comment


            #6
            Re: UDF with undetermined number of arguments

            G,

            One way to achieve what you are after is to use an array. The name of an array is a pointer in itself. As long as all of the parameters were of the same type, they could be stored into an array of that type. Take a look at the following code.
            Code:
            dim arr1[20] as C
            
            nSz = Some_Function(arr1)
            ui_msg_box("Arr1[]","Size = "+alltrim(str(nSz)))
            
            END
            
            FUNCTION Some_Function as N (pArray as P)
            	nSize = pArray.size()
            	
            	for j = 1 to nSize
            		cElement = pArray[j]
            		'Process array element.
            	next j	
            		
            	Some_Function = nSize
            END FUNCTION
            When you run this, you will see that the function itself knew that there were 20 elements in the array by use of the pArray.size() method. If you change the size of arr1[], you will notice that the function will adjust accordingly. Hence, in effect you are passing the function an undisclosed number of character-type parameters.

            Steve

            Comment


              #7
              Re: UDF with undetermined number of arguments

              Originally posted by Steve Andrews View Post
              When you run this, you will see that the function itself knew that there were 20 elements in the array by use of the pArray.size() method. If you change the size of arr1[], you will notice that the function will adjust accordingly.
              Steve:
              I am totally with you, but you went to step 2 before step 1.
              Somehow the user (or the function) has to populate the array before you could use that array.

              The question is (in the context of using an array):
              How do you take the arguments entered by the users (the argument will be an argument, a comma, another argument..could be couple of those or could be any number of arguments) and use that to populate the array?
              The problem you will run into is, once you enter one more argument than you specified in your UDF, alpha will throw a fit and tells you that you enterd too many parameters. Alpha counts the number of parameters by the number of commas. You have one comma means you have 2 parameters, 3 commas means 4 parameters ..etc.

              You could say, allright I will use a different separator instead of a comma: that does not cut it either, alpha will see the whole thing as a lousy variable. You could say, allright I will enclose all these arguments in quatations and you will be correct, but not the desired construct I am looking for. As I said, I am looking for something akin to case().

              Comment


                #8
                Re: UDF with undetermined number of arguments

                Gabe - why not just feed it a single variable, and parse the vaiable and based on the number of words, etc. process
                Cole Custom Programming - Terrell, Texas
                972 524 8714
                [email protected]

                ____________________
                "A young man who is not liberal has no heart, but an old man who is not conservative has no mind." GB Shaw

                Comment


                  #9
                  Re: UDF with undetermined number of arguments

                  Originally posted by G Gabriel View Post
                  Which leads me to another thought from a different orbit:
                  Did alpha impose the 16 conditions limit because they just implemented 16 optional parameters only?
                  Don't have any other ideas on your main question but...
                  The limit of 16 in the Case() command comes from an earlier version of A5 where there really was a limit. I know A5v1 had this limit but I'm not sure when it was removed. The info about the change is probably in the release notes somewhere but apparently they chose not to update the Help file. Beyond that I have no idea how/why it was done.

                  Comment


                    #10
                    Re: UDF with undetermined number of arguments

                    Here's a suggestion. Try passing a single parameter to the function as a separated crlf() list. Each optional parameter could be present in its own line of the list. You can identify each parameter by its position in the list or, alternatively if you need both the name of the parameter and its value, place the name in its line along with its value separated by a unique character, for example a vertical bar. In the function itself you can identify the total number of parameters in the single parameter passed to the function using the *count() function. You can also identify the name and value of each using the extract_string() function specifying the vertical bar as the delimiter. You can process each line of the list (the optional parameters) using the "for each ..." construct. QED. A piece of cake . 8-)

                    Comment


                      #11
                      Re: UDF with undetermined number of arguments

                      Hi Brett,

                      Originally posted by csda1 View Post
                      The only really usable solution for Alpha 5 is to pass 1 argument as a string, pointer or similar that is then processed as multiple arguments after parsing it (which for a string containing arguments, can be difficult if you have expressions as arguments)
                      Whether it's parsing through a string with an argument delimiter (CRLF() in how you described your version), a pointer to an array or collection of arguments, or a pointer to a property array containing multiple properties you can process, it's all amounts to the same of 1 argument masquerading as multiple arguments. The only problem is evaluating any expressions in the context of the calling thread, which requires getting the local variable space of the calling thread (a feature I requested several years ago). The only documented way is to pass the local variable space pointer as a 2nd argument. However, there are Alpha Five functions that do get this context, so it is obviously not impossible with Alpha to do it without passing the 2nd local variable space pointer.
                      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


                        #12
                        Re: UDF with undetermined number of arguments

                        Originally posted by martinwcole View Post
                        Gabe - why not just feed it a single variable, and parse the vaiable and based on the number of words, etc. process
                        Originally posted by brett s View Post
                        Try passing a single parameter to the function as a separated crlf() list.
                        Yes..yes.. but like I said earlier, not the desired outcome.

                        Couple days ago when I was writing a response to this, my computer start doing all sorts of weird things, so I stopped to figure out what is the problem. After a good long while, I figured the memory must be corrupt. Don't know if it's a new year's virus or Windows goofing off. Most likely the latter. Another explanation is that this thread is giving it a fit (and me too). This time I am going to write my response standing upside down on my head while going back and forth between 2 computers, maybe it will come out right this time around. I really thought this is not a complicated question, but evidently it is.

                        Here is an example that might illustrate the point:
                        Although this is not the function I have in mind, but this should serve as a good example and a potentially good function too:

                        Let's say you want to provide the user with a function that retrieves the max (or min or mean..etc) value of a set of values. Alpha does not have such function. So you will write a UDF that will look like this:
                        Max_Multi(.....here the user could enter 2 values separated by a comma, a dozen of values, a hundred.....all separated by commas) then the function will extract the max or min or mean.
                        When writing such function, you will specify parameter(s). If you put a specific number of parameters, then the user has to provide that exact number, or else. If you reference a list or an array.. etc., then somehow somewhere someone has to populate this list. How are you going to obtain the elements of the array or the list from the user and populate the array with them? How is the function going to do that? You are back to specifying parameters to be used to populate the array!

                        You most definitely can enclose those parameters in quotations, i.e. obtain a sting of variable length then parse it. BUT THAT IS NOT THE SAME AS ALLOWING THE USER TO ADD VALUES SEPARATED BY COMMAS UNTIL KINGDOM COME.

                        Time for me to get off my head! Hope this does it.
                        Last edited by G Gabriel; 01-04-2009, 01:54 PM.

                        Comment


                          #13
                          Re: UDF with undetermined number of arguments

                          And just in case the above is not clear enough, the function would look something like this:

                          ?max_multi(2,1)
                          =2
                          ?max_multi(2,1,19,5,8)
                          =19
                          max_multi(2,1,19,5,8,26,17,36,79,200,4,5)
                          =200
                          max_multi("c","x","m","d")
                          ="x"

                          Comment


                            #14
                            Re: UDF with undetermined number of arguments

                            Originally posted by G Gabriel View Post

                            The question is (in the context of using an array):
                            How do you take the arguments entered by the users (the argument will be an argument, a comma, another argument..could be couple of those or could be any number of arguments) and use that to populate the array?
                            The problem you will run into is, once you enter one more argument than you specified in your UDF, alpha will throw a fit and tells you.....
                            Check out <array>.initialize_properties()

                            Then just pass the array to your UDF

                            Good luck,
                            Jim

                            Comment


                              #15
                              Re: UDF with undetermined number of arguments

                              Originally posted by G Gabriel View Post
                              Let's say you want to provide the user with a function that retrieves the max (or min or mean..etc) value of a set of values. Alpha does not have such function.
                              Check out *min() and *max().

                              Originally posted by G Gabriel View Post
                              BUT THAT IS NOT THE SAME AS ALLOWING THE USER TO ADD VALUES SEPARATED BY COMMAS UNTIL KINGDOM COME.
                              Mere detail. It will achieve the same outcome. Why try and do something clever and difficult whewn there is an obvious and easier way to do it? (That's a rhetorical question). :)

                              Comment

                              Working...
                              X