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

<browse>.records_get() not working for child table

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

  • <browse>.records_get() not working for child table

    I have a set composed of 2 tables. The parent table has a one-to-many link to the single child table. I have a form layout called
    "RoundingFrm" based on this set. The child table is represented in the form layout by an embedded browse ("Browse1").

    In an attempt to count the records displayed in the embedded browse, I used the following script (attached to a button):
    ------
    dim varP_object as p
    dim rec_num as n
    varP_object = obj(":RoundingFrm:BROWSE1")
    rec_num = varP_object.records_get()
    msgbox("# records", str(rec_num))
    ------

    However, this script does not return the correct count of records in "Browse1" (again, based on the child table). Rather, it returns the number of records in the parent table. Does anyone know what I am doing wrong? Some prior posts suggest that the problem may lie with Version 10 of Alpha. If so, does anyone know of a work-around?

    thanks in advance,

    Jim

  • #2
    Re: &lt;browse&gt;.records_get() not working for child table

    I've been round and round with this one too - and finally went back to adding a calc field to the form.
    Robin

    Discernment is not needed in things that differ, but in those things that appear to be the same. - Miles Sanford

    Comment


    • #3
      Re: &lt;browse&gt;.records_get() not working for child table

      Thanks for your feedback, Robin. I tried your suggestion of putting a calculated field in my form. Specifically, I first added another field called 'rec_number' to my
      child table. I then defined this new field as a calculated field using the expression,

      Rec_Number = :RoundingFrm:browse1.records_get() .

      However, this technique still returned the number of records in the parent table. Interestingly, I get the same behavior in Version 11 (which I tried for the first time today). Am I doing anything obviously wrong?

      Thanks,

      Jim

      Comment


      • #4
        Re: &lt;browse&gt;.records_get() not working for child table

        Am I doing anything obviously wrong?
        Check the help documentation or wiki. I don't think the browse object has (or supports) a "records_get()" method.

        The calc display value should probably use an expression based on tablecount() or dbcount().

        -- tom

        Comment


        • #5
          Re: &lt;browse&gt;.records_get() not working for child table

          I think the reference is to using a tablecount() or dbcount() expression for the calculated field.

          You can also use (for a character linking field in both parent and child)

          a5_get_records_in_query("child_table_name","child_linking_field_name = "+quote(parent_linking_field_object_name_on_form.value))

          I do see <browse>.records_get() but it returns

          The number of records in the browse's current query list.
          This is not the same as the number of records linked to the currently visbile parent record in a form based on a set.
          Last edited by Stan Mathews; 11-30-2011, 03:00 PM.
          There can be only one.

          Comment


          • #6
            Re: &lt;browse&gt;.records_get() not working for child table

            Thanks, Tom and Stan. Let me chew on those ideas for a bit. Right now I need some exercise - I'm about to get a pressure ulcer on my butt.

            Jim

            Comment


            • #7
              Re: &lt;browse&gt;.records_get() not working for child table

              Thanks again, Stan. The approach you suggested will work.

              Jim

              Comment


              • #8
                Re: &lt;browse&gt;.records_get() not working for child table

                I've not tested whether tablecount() would be as fast or faster than the a5_get.....()
                I know the dbcount() could be faster than either of them. All depends on how many records you expect to have whether it is worth pursuing. In AlphaSports I can say the a5_get.....() is sufficient but we're talking a very limited dataset.

                The corresponding tablecount() expression would be

                tablecount("child_table_name","child_linking_field_name = "+quote(parent_linking_field_object_name_on_form.value))
                There can be only one.

                Comment


                • #9
                  Re: &lt;browse&gt;.records_get() not working for child table

                  I experiment with tablecount() and dbcount(). But on a related matter, can I DIRECTLY fetch through a browse like this:

                  n=0
                  While n<= rec_num
                  RoundingFrm:Browse1.fetch_next()
                  ' do something with the fetched values
                  End_While()

                  Or, do I need to fetch through a defined query of the child table? The query would mimic what would appear in the child embedded browse that I described above.


                  Thanks,

                  Jim

                  Comment


                  • #10
                    Re: &lt;browse&gt;.records_get() not working for child table

                    browse1.fetch_next() is legitimate and will only affect records related to the current parent. Not sure where rec_num comes into play.
                    There can be only one.

                    Comment


                    • #11
                      Re: &lt;browse&gt;.records_get() not working for child table

                      Originally posted by Stan Mathews View Post
                      browse1.fetch_next() is legitimate and will only affect records related to the current parent. Not sure where rec_num comes into play.
                      You're right, Stan. I was in a bit of a rush so my last post was not very clear. The 'rec_num' is a variable that I defined. As you might guess, it represents the number of records in the browse (as determined by the method you suggested in your previous post). I am thinking that I need to incrementally count through the fetching process because I suspect that the 'While .NOT. tbl.fetch_eof' procedure is not appropriate for browses. Anyway, I will try fetching through browse by pre-counting the records in the browse and using a incremented counter. Thanks again for your advice.

                      Comment


                      • #12
                        Re: &lt;browse&gt;.records_get() not working for child table

                        Come on guys, this is easy. But you have to learn when to use table.get() vs. table.open().

                        If you start fetching through the browse itself, you can mess up the user by leaving the focus on a different line in the browse.

                        Here's a generic function I threw together and tested on a simple 1:M set. The ui_msg_box() was added for testing purposes.

                        Code:
                        'Date Created: 01-Dec-2011 02:40:53 AM
                        'Last Updated: 01-Dec-2011 02:40:53 AM
                        'Created By  : Cal Locklin
                        'Updated By  : Cal Locklin
                        
                        FUNCTION count_child_recs as N ( child_table_name as C )
                        	tc = table.get( child_table_name )
                        	tc.fetch_first()
                        	cnt = 0
                        	WHILE .not. tc.fetch_eof()
                        		cnt = cnt + 1
                        		tc.fetch_next()
                        	END WHILE
                        	count_child_recs = cnt
                        	ui_msg_box( "", "Count = " + ltrim(str(cnt)) )
                        END FUNCTION
                        If you MUST refresh/resynch for some reason after doing this, get the initial record number (init_rec = tc.recno()) and then do a tc.fetch_goto(init_rec) at the end to return to that record. As a generic function, I should probably have done that but didn't think of it at the time.

                        Comment


                        • #13
                          Re: &lt;browse&gt;.records_get() not working for child table

                          Cal, I prefer to use the tbl.get_cursor() method instead of fetching with a pointer to the table itself. This method lets you establish an independent pointer to the same instance of the table that can be used to navigate through the records without affecting the base table.

                          Here's an example that works just fine from a button on the Invoice form in AlphaSports:


                          Code:
                          tbl = table.get("invoice_items")
                          tptr = tbl.get_cursor()
                          count = 0
                          tptr.fetch_first()
                          while .not. tptr.fetch_eof()
                          	count = count + 1
                          	tptr.fetch_next()
                          end while
                          msgbox("count",ltrim(str(count)))

                          Comment


                          • #14
                            Re: &lt;browse&gt;.records_get() not working for child table

                            Code:
                            n=0
                            While n<= rec_num
                            RoundingFrm:Browse1.fetch_next()
                            ' do something with the fetched values 
                            End_While()
                            Since you have predetermined the rec_num

                            Code:
                            For qx = 1 to rec_num
                            ' do something with the fetched values 
                            RoundingFrm:Browse1.fetch_next()
                            next qx
                            should work.
                            There can be only one.

                            Comment


                            • #15
                              Re: &lt;browse&gt;.records_get() not working for child table

                              Originally posted by Tom Cone Jr View Post
                              Cal, I prefer to use the tbl.get_cursor() method instead of fetching with a pointer to the table itself. ....
                              Thanks Tom. I'd forgotten all about the get_cursor() method.

                              And I'd love to know when that became available. It's not listed in the .chm help file and the "Supported by" info that was in the .chm files isn't shown in the WIKI page for <tbl>.get_cursor(). The <RTF>.get_cursor() method was available in v5 and the <TEXT>.get_cursor() method was available in v6 but I have no idea when the <tbl>.get_cursor() method became available.

                              Comment

                              Working...
                              X