Alpha Video Training
Results 1 to 21 of 21

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

  1. #1
    Member
    Real Name
    Jim Snyder
    Join Date
    Jun 2009
    Location
    Nashville, TN and Medellin, Colombia
    Posts
    53

    Default <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. #2
    "Certified" Alphaholic MoGrace's Avatar
    Real Name
    Robin
    Join Date
    Mar 2006
    Location
    Los Angeles
    Posts
    3,685

    Default Re: <browse>.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

  3. #3
    Member
    Real Name
    Jim Snyder
    Join Date
    Jun 2009
    Location
    Nashville, TN and Medellin, Colombia
    Posts
    53

    Default Re: <browse>.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

  4. #4
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: <browse>.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

  5. #5
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: <browse>.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 at 03:00 PM.

  6. #6
    Member
    Real Name
    Jim Snyder
    Join Date
    Jun 2009
    Location
    Nashville, TN and Medellin, Colombia
    Posts
    53

    Default Re: <browse>.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

  7. #7
    Member
    Real Name
    Jim Snyder
    Join Date
    Jun 2009
    Location
    Nashville, TN and Medellin, Colombia
    Posts
    53

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

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

    Jim

  8. #8
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: <browse>.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))

  9. #9
    Member
    Real Name
    Jim Snyder
    Join Date
    Jun 2009
    Location
    Nashville, TN and Medellin, Colombia
    Posts
    53

    Default Re: <browse>.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

  10. #10
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: <browse>.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.

  11. #11
    Member
    Real Name
    Jim Snyder
    Join Date
    Jun 2009
    Location
    Nashville, TN and Medellin, Colombia
    Posts
    53

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

    Quote 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.

  12. #12
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default Re: <browse>.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.

  13. #13
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

    Default Re: <browse>.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)))

  14. #14
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: <browse>.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.

  15. #15
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

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

    Quote 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.

  16. #16
    "Certified" Alphaholic
    Real Name
    Mike Christensen
    Join Date
    Nov 2005
    Location
    Michigan U.P.
    Posts
    5,937

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

    shows up in v9 but not in v8...... :)
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________




  17. #17
    Member
    Real Name
    Jim Snyder
    Join Date
    Jun 2009
    Location
    Nashville, TN and Medellin, Colombia
    Posts
    53

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

    Cal, could you explain a bit more about the differences between tbl.get and tbl.open. I googled 'tbl.get' and could not find a useful explanation. Even a good reference link would be appreciated.

    And Tom, I read a little bit about tbl.get_cursor. It seems to be a method for getting the cursor position in an XDialog object:

    The OBJECT.GET_CURSOR() method is used with an Xdialog text control. It returns the position of the cursor in the VariableName text variable.
    On the other hand, your recent post suggests that this method can be used to fetch through a browse. Can you clarify for me. Thanks.

    Jim

  18. #18
    Volunteer Moderator
    Real Name
    Alan Buchholz
    Join Date
    Oct 2000
    Location
    Delavan, Wisconsin
    Posts
    9,620

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

    Quote Originally Posted by drjgs200 View Post
    Cal, could you explain a bit more about the differences between tbl.get and tbl.open. I googled 'tbl.get' and could not find a useful explanation. Even a good reference link would be appreciated.
    'table get' in the wiki google search found this...

    tbl is a pointer variable name - not part of the function name.


    http://wiki.alphasoftware.com/TABLE.GET+Method

    also - get_cursor found this.
    http://wiki.alphasoftware.com/TBL.Get_Cursor+Method
    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.

  19. #19
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,310

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

    Jim, I think you're mistaken. Here are two ideas for you:

    1) try the sample I furnished; and

    2) check the topic "Table Cursors" in the "What's new in version 9" document, per Mike C, post #16, And the second link Al posted in #18

    -- tom
    Last edited by Al Buchholz; 12-03-2011 at 07:15 PM.

  20. #20
    Member
    Real Name
    Jim Snyder
    Join Date
    Jun 2009
    Location
    Nashville, TN and Medellin, Colombia
    Posts
    53

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

    Thanks Tom and Al. I get it now (at least most of it). And thanks for your patience. I'm making progress one step at a time.

    Jim

  21. #21
    "Certified" Alphaholic Tim Kiebert's Avatar
    Real Name
    Tim Kiebert
    Join Date
    Jul 2004
    Location
    Geelong, Victoria, Australia
    Posts
    2,785

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

    I may get lambasted for suggesting this due to the blatantly obvious warning in the help that this and similar functions are only supported in the report writer,
    Limitations

    This function is a report writer function, not intended for table level field rules or other expressions. While the function may perform in some areas outside of the report writer, its use there is not supported.
    but.....
    For a simple task as getting a count of records in an embedded browse, ie a child table in the context of a form, I often just use the count() function.

    My rationale for this is that like a report a form has already created the groupings of the records needed for these functions. I have to date not had any issues where I have tried a 'report writer function' in a form context, it works in testing, and then at some later stage have it not work.

    I totally agree that these functions should not be used at the table level, such as field rules or in xbasic where there is no context of a layout.
    Tim Kiebert
    Eagle Creek Citrus
    A complex system that does not work is invariably found to have evolved from a simpler system that worked just fine.

Similar Threads

  1. Child Table Saved Browse
    By Tom Henkel in forum Alpha Five Version 10 - Desktop Applications
    Replies: 10
    Last Post: 09-22-2010, 04:49 PM
  2. Child Table Browse Filter
    By Mortie in forum Alpha Five Version 7
    Replies: 9
    Last Post: 12-23-2006, 08:09 PM
  3. Child Table Browse pointer table.current(2) lost
    By Mike Wilson in forum Alpha Five Version 7
    Replies: 7
    Last Post: 10-31-2006, 01:58 PM
  4. New records into Child table browse
    By Tom Henkel in forum Alpha Five Version 5
    Replies: 12
    Last Post: 05-16-2005, 06:10 AM
  5. Sorting in child table browse
    By Bob Wily in forum Alpha Five Version 5
    Replies: 5
    Last Post: 02-20-2004, 01:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •