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 Function Anybody?

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

    Global Function Anybody?

    I have a global function defined that can perform a query on a table and then open a form based on that table. This works fine such as it is. BUT if the user does not close the form, the next call will not refresh the query. Has anybody done this already? When I script this on a button it always refreshes the query even when the form is still open. It seems like a good use for a global function to me...;-) Robin

    #2
    RE: Global Function Anybody?

    "Has anybody done this already?" - Done what?

    "I have a global function defined that can perform a query on a table and then open a form based on that table. This works fine such as it is. BUT if the user does not close the form, the next call will not refresh the query." - Show us the function and maybe someone can comment
    There can be only one.

    Comment


      #3
      RE: Global Function Anybody?

      Here is what I have so far:
      function Q_Frm as L(frm_name as C,tbl_name as C,q_filt as C,q_ord as C)
      dim frm as p
      dim tbl as p
      tbl = obj(tbl_name)
      if .not. is_object(tbl) then
      on error goto INUSE
      tbl = table.open(tbl_name)
      on error goto 0
      end if
      trace.writeln("' Table: "+tbl_name)
      query.description = "Q_Form"
      query.filter = q_filt
      trace.writeln("' Q Filter: "+query.filter)
      query.order = q_ord
      query.options = "N" 'supposed to force to create a new query
      idx = tbl.query_create()
      recs = idx.records_get()
      trace.writeln("' Records found: "+ltrim(str(recs)))
      if recs "1 then
      cr = chr(13)+chr(10)
      msg = "No records were found that match your criteria"+cr
      msg1 = "Do you want to display all records?"
      msg_str = msg+msg1
      response = ui_msg_box("Query Result",msg_str,3+32)
      select
      case response = 2
      tbl.close()
      goto ENDIT
      case response = 6
      idx.drop()
      end select
      end if
      tbl.close()
      frm = obj(frm_name)
      if .not. is_object(frm) then
      frm = :form.load(frm_name)
      end if
      frm.resynch()
      frm.show()
      frm.activate()
      ENDIT:
      end
      INUSE:
      close_if_exists(tbl_name)
      cr = chr(13)+chr(10)
      msg = " Table: "+ut(tbl_name)+cr
      msg1= " Form: "+ut(frm_name)+cr
      msg2 = "Have Users close open forms and try again"
      msg_str = msg+msg1+msg2
      ui_msg_box("Table In Use",msg_str,0)
      end function

      Comment


        #4
        RE: Global Function Anybody?

        Check the help file. Don't you mean to use a query option of "M" instead of "N" ?

        -- tom

        Comment


          #5
          RE: Global Function Anybody?

          Hi Tom,
          Ok but my help file doesn't say anything about M only N,D, and U (v4.5 Bld 266). So what are the other query options and what do they do? Also when using the form method can a pointer or other variable be used to get the table for the query statement?

          example:
          frm:tables:GET_TABLE_NAME_HERE_WITH_VAR.query_create()

          also is it possible to write:
          idx = frm:tables:table_name.query_create()
          recs = idx.records_get()

          I've tried this and it doesn't work. How can I test the records found before opening the form?
          Thanks in advance - Robin

          Comment


            #6
            RE: Global Function Anybody?

            What's new in Alpha Five Vers 4.5 at pg 50 (PDF version) says:

            New Options for "tbl".Query_Create Method

            Alpha Five now has two new option flags for the "tbl".query_create() method. These options are set with
            the query.options variable. The options are:

            query.options = "M"

            If this option is specified, Alpha Five will build a new query list even though a) an existing query list exists,
            and b) an existing Index exists (both of which, Alpha Five could have used rather than running a new
            query).

            query.options = "X"

            If this option is specified, Alpha Five will use an index even if an existing query exists (which Alpha Five
            would otherwise have used in preference to the index)

            -- tom

            Comment


              #7
              RE: Global Function Anybody?

              I think the answer to all your other questions is no.

              The traditional approach to determining whether there are going to be any records in the query list is illustrated by example in the Xbasic Ref. Manual discussion of "index".records_get(). There they show how to check for an empty query list before running a report. You want to check for an empty query list before opening a form. The example should work fine if you're working with a single table, or with the primary table in a set.

              -- tom

              Comment


                #8
                RE: Global Function Anybody?

                Robin,

                I've never considered building a custom UDF to do what you describe. Basically, you're building a wrapper around the existing form.load()method. Have never felt the need to build the wrapper.

                Have you considered using form.load() to open forms, and then run your query against the underlying table to set the desired view? Check the examples in the Xbasic Ref Manual discussion of form.load(). The approach you're using now does things in reverse, it runs the query, then loads the form.

                -- tom

                Comment


                  #9
                  RE: Global Function Anybody?

                  Tom-
                  so the proper way to go about this would be to run a query on the table to get the record count and then open the form?
                  - I think I got it... Robin

                  Comment


                    #10
                    RE: Global Function Anybody?

                    wait - I AM confused - isn't that what you said to do?
                    please give me a script example to follow. Thanks

                    Comment


                      #11
                      RE: Global Function Anybody?

                      There are several different approaches. If you're going to use form.view() to display the form immediately, I'd recommend running the query first to get a records count.

                      If you're going to use form.load() you'd run the query after loading the form and check the record count before showing the form. The example in the Xbasic Ref. Manual is there for you to see.

                      -- tom

                      Comment


                        #12
                        RE: Global Function Anybody?

                        Without trying to sound argumentative - what is it about using an UDF that won't work? Except for preferring the line
                        frm:tables:tbl_name.query_create()
                        to which I cannot seem to pass a variable to for tbl_name;
                        it seems that a UDF ought to do what I want for the script the way it is. What is it about UDF's I do not understand?
                        ...you are so patient...

                        Comment


                          #13
                          RE: Global Function Anybody?

                          Tom -
                          I am so slow at this and preconceived ideas definitely make things worse. I think I get it - I have 2 choices:
                          1. I can run a query on the table and then view the records in a form based on that table or
                          2. I can set the form's base filter then run a query on the form itself while it is loading which cannot be done using a UDF.

                          What I cannot do is run a query, save it, and set that as the index for the form if it is already loaded because the saved query does not refresh the records displayed in the form. Even though the trace window reports the results of the new query correctly.

                          Therefore, I will use a revised version of my UDF to check records found by the query on the table only. When the form is deactivated it will close. Then the query will be refreshed when the form is called again.

                          Somehow it ain't right but I guess that is how I will do it!
                          Phooey. I hate being wrong... (thank YOU, however)

                          Comment


                            #14
                            RE: Global Function Anybody?

                            you clould also use tablecount() or dbcount() first - like:

                            if dbcount(fill in here) " 0 'or tablecount() " 0
                            form.view("xxx")
                            else
                            'message
                            end if
                            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


                              #15
                              RE: Global Function Anybody?

                              ""what is it about using an UDF that won't work? ""

                              Not to be argumentative, but I didn't say it won't work.

                              I just have never felt the need to re-invent the wheel such as you seem to be doing. I'm having trouble seeing what is gained by using your UDF.

                              A typical reason to develop a UDF is to permit code to be re-used over and over, so that it doesn't have to be retyped in lots of different places. This makes maintenance and bug fixes easier after deployment, too.

                              In my own work almost every form in an application requires special attention and setup before its opened. Sometimes they need to be modal, sometimes not. Sometimes with a query in place, often without. Always with an index sort order. Always with the record pointer positioned appropriately. Sometimes with special ordering arrangements for child tables, often without.

                              The form setup requirements have so little in common with each other that I've never felt the need to try to 'generalize' a UDF solution to open forms throughout the app. To handle all the permutations and combinations the UDF would become very unwieldy and overly complex. It would also slow performance.

                              Your situation is probably different from mine.

                              But here, if I need to open the same form time after time, with different queries in place each time, I simply use inline code and a variable to hold the current filter expression. I've discovered also that my users really like query by form, so I've taught them how to use the QBF operators. This of course makes it easy to use a single instance of the form to display a virtually infinite number of differently filtered views of the data.

                              -- tom

                              Comment

                              Working...
                              X