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

user defined functions

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

    user defined functions

    I'm probably gonna' get alot of flack for this, but....
    I must really be stupid..
    I cannot figure out the use of 'functions'. "Back in the Day", (in Cobol) I could put a section of code somewhere in the program and 'call' it from any place. Are functions like that???? What I mean is : if the function is in the code section; can I 'call' it or do I have to have the entire function inside the script?

    I'm working on Jim Chapmans progressive search function. In past db's I have had as many as 10-12 search routines just because they used a different table or a different form.

    Can I 'spoonfeed' a function with different variables and still use the same function. And back to my problem, where do I find the spoon and what do I put in it??

    In my mind (ha); I should be able to write a script, declare the 'internal' variables from the function and 'call' the function.

    Really confused, any help appreciated
    D

    #2
    Originally posted by dik_coleman
    I'm probably gonna' get alot of flack for this, but....
    I must really be stupid..
    I cannot figure out the use of 'functions'. "Back in the Day", (in Cobol) I could put a section of code somewhere in the program and 'call' it from any place. Are functions like that???? What I mean is : if the function is in the code section; can I 'call' it or do I have to have the entire function inside the script?

    I'm working on Jim Chapmans progressive search function. In past db's I have had as many as 10-12 search routines just because they used a different table or a different form.

    Can I 'spoonfeed' a function with different variables and still use the same function. And back to my problem, where do I find the spoon and what do I put in it??

    In my mind (ha); I should be able to write a script, declare the 'internal' variables from the function and 'call' the function.

    Really confused, any help appreciated
    D
    UDF's are not really different from built in functions.

    Just as you would use Upper("coleman") in and expression and get the result "COLEMAN", you might create a function (ulast()) that capitalized the last letter of a string. Using ulast("coleman") in an expression would yield the result "colemaN".

    UDF's are generally slower to execute but I believe the difference would only be seen in usage where the function was executed many hundreds of times as in an saved operation on table.
    There can be only one.

    Comment


      #3
      Big topic.

      Yes, you can do things the way you describe.

      A function can return a value

      A function need not return a value

      You can pass a value(s) to a function as long as the values to be passed in are defined within the function. The values being passed in are usually contained in variables.

      You don't have to pass values to a function

      You can refer to a script variable from a function as long as the variable is dimensioned as shared or global in the script.

      You can pass all the script variables to a function by using the
      lv = local_variables()
      and defining the variables pointer (lv) as an argument of the function.

      A function can be saved in the code editor (a global function). This function can be called from any script in the datbase

      A function can be embedded within a script and called only from within the script.

      You can use a function to "package" a piece(s) of code within a script. This can be a big help in making a long script more readable and understandable.

      My own biggest hurdle with functions (boy did I feel dumb) was coming to understand that, if you want a function to return a value then the function code needs to have an explicit statement
      FunctionName=Value
      within the function.


      Code:
      dim a as n;dim b as n;dim c as n, dim d as n
      
      a = 3
      b = 2
      c = 0
      d = 4
      
      tt = Additems(a,b,d)
      
      ui_msg_box("",ltrim(str(tt)))
      
      end
      
      Function AddItems as N(Expr1 as N,Expr1  as N, Expr3 = 0, Expr4 = 0)
      Additems = Expr1 + Expr2 +Expr3 + Expr4
      End Function
      In the above example, the third and fourth expression items are optional but the function will fail unless it is passed at least two numeric values.

      That's all I can think of right now (for a quickie!)
      Finian

      Comment


        #4
        Dick,

        Use the Code page of the Control panel. Define your Function there, just as you would any global script. Once the function is saved to the Code page you can call it from anywhere in your app.

        --tom

        Comment


          #5
          I'm sure I have more research to do but here's what I think I know.
          Function is written and stored under 'Code' tab on CP. In order to 'call' the function, all you need to do is execute a line using the name of the function and pass the 'proper' variables to the function.
          EG - In JC's lookup function:
          Function ProgressiveLkUp as N(vTableName as C, vIndexName as C, vNumberOfLines as N, vWidth as N)
          ----- all his code
          End function.

          To call this function for a table 'd_titles' with an index 'tbl-id' for 25 records in the list box with a width of 35; I would type the following command:

          ProgressiveLkUp (d_titles.dbf,tbl_id,25,35)

          in a script and voila -- it should work???
          It should return the record number to match the vTypeIn variable chosen.
          D
          Last edited by dik_coleman; 12-23-2005, 03:00 PM.

          Comment


            #6
            Well yes, but .....

            If you are entering the parameters for the function directly such as d_titles.dbf for the vTableName parameter, then it would need to be enclosed in quotes since the function is looking for a character value indicated by the "as C" in the function. So the calling the function using your example would actually be:

            ProgressiveLkUp ("d_titles.dbf","tbl_id",25,35)

            Now, if it were me I wouldn't even use the .dbf after the table name, so the line would be:

            ProgressiveLkUp ("d_titles","tbl_id",25,35)

            The reason that 25 and 35 are not in quotes is obvious, they are numeric parameters.

            OK, now at the risk of confusing you, there is another way this is done with the use of variables. Here is an example:

            mytable = "d_titles"
            myindex = "tbl_id"

            ProgressiveLkUp mytable,myindex,25,35)

            The reason that mytable and myindex are not in quotes above is because they are character variables already.

            I hope this helps you and doesn't confuse you more.

            Scott

            Comment


              #7
              thanx for quick reply. I figured out the "" around the table and index as I was typing the command..
              It works ....... BUT....
              I put a button on a form that is based on a set and d_titles is the base. Right now I only have 2 records in the table; and since the first record was being displayed, I chose the second... the record being viewed did not change; so I'm going back to 'try' to find out why.
              D

              Comment


                #8
                Originally posted by dik_coleman
                ................. I only have 2 records in the table; and since the first record was being displayed, I chose the second... the record being viewed did not change; so I'm going back to 'try' to find out why.
                D
                Hello Dick,

                The progressive lookup function just returns the record number if a selection is made. It returns a -1 if a selection was not made or the user cancels out. It is up to you to deal with things from this point on. If you want your current form to jump to the selected record, you'd do this:

                Code:
                vRecord = ProgressiveLkUp("YourTableName","YourIndexName",20,30)
                
                If vRecord > 0
                   parentform.recno_goto(vRecord)
                end if
                Good luck,
                Jim

                Comment


                  #9
                  I found out quickly that the function as written did not 'go to' the record as I thought it would...
                  I'll go back and try your way, but what I did follows:

                  I put the function on the button script, on a form based on a set (d_titles is the set base):

                  Code:
                  dim shared mydb as c
                  dim shared myindx as c
                  dim shared vRecNumber as N
                  mydb="d_titles"
                  myindx="title_name"
                  
                  'ProgressiveLkUp("d_titles","title_name",25,35)
                  
                  ProgressiveLkUp(mydb,myindx,25,35)
                  
                  'Go to a specified record number in Form 'd_titles_to_all_form' at parent level.
                  DIM var_recno_target as N
                  var_recno_target = vRecNumber
                  DIM object_name as C
                  object_name = ":"+"d_titles_to_all_form"
                  DIM varP_Object as p
                  'Get a pointer to the specified object
                  varP_Object = obj(object_name)
                  'Check if the specified object exists
                  if .not. is_object(varP_Object) then 
                  	ui_msg_box("Error","The object '"+object_name+"' does not exist.",ui_stop_symbol)
                  else
                  	varP_Object.recno_goto(var_recno_target) 
                  
                  end if
                  You probably recognize the Action Scripting for record navigation...

                  It works, but I'm sure your way is better

                  I know that I now have a much better understanding of how functions work and a little better understanding of how to use them
                  thanx for all your help.
                  D

                  Comment


                    #10
                    Hello Dick,

                    'ProgressiveLkUp("d_titles","title_name",25,35)

                    ProgressiveLkUp(mydb,myindx,25,35)
                    Either of the above should work fine.

                    Your syntax is just fine except for one little thing. If the user cancels out of the progressive lookup, it will return a -1. It doesn't appear that this situation is handled in your code and would produce an error when your form tried to fetch a record number value of -1.

                    I built this function with the hope that it could be used in a variety of situations so I left the developer/user with the record number so they could control what happens next. I imagine most of the time, it will be used to return a record field value. I have a new version that will allow the UI to be divorced from the lookup string, and it allows the UI to be displayed as columns rather than search string format.

                    Good luck,
                    Jim

                    Comment


                      #11
                      Yes, I know that I need more code to handle the user options. At this point, I am still building the data entry for the main table in the db.. There will be no duplicates in this table and any mods to the support or info tables will be made by searching for the name. If no name present, new record in main table....
                      thanx a whole bunch
                      D

                      Comment

                      Working...
                      X