Hot Topic (More than 10 Replies) @XResultSetSubSet question (Read 2059 times)
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
@XResultSetSubSet question
Oct 24th, 2009 at 10:10pm
Print Post Print Post  
The following code does a fine job of returning all of the Team Codes from the Activity subform from the first “Players” record.  I’m having a struggle finding a way of getting it to return all of the Team Codes from all of the Players?  And while we're at it, is it possible to get the Team Code from only the first or top subform record from each Player record?

Any help would be appreciated.

var vRS as Int
var vCRS as Int
var vCount as Int
var vLoop as Int
var vTCode1 as string



     vRS = @XResultSetSearch(@FN, "Players", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "")    
     If vRS > -1
     {

           vCRS = @XResultSetSubSet(vRS, "Activity")
           If vCRS > -1
           {

                 vCount = @XResultSetTotal(vCRS)

                 For vLoop = 1 To vCount
                       XResultSetCurrentPosition(vCRS, vLoop)
                       vTCode1 = @XResultSetValue(vcRS, "Team Code")
                   writeln(vTCode1)
                       

                 Next
                 XResultSetClose(vRS)
           }

     }
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @XResultSetSubSet question
Reply #1 - Oct 25th, 2009 at 1:50am
Print Post Print Post  
tcgeo wrote on Oct 24th, 2009 at 10:10pm:
I’m having a struggle finding a way of getting it to return all of the Team Codes from all of the Players?  And while we're at it, is it possible to get the Team Code from only the first or top subform record from each Player record?


To get the Team Code from each player you will need to loop through the Players in much the same way you are looping through the Team Codes for the first Player. I am assuming that each player has multiple Team Codes.

To get the first Team Code for a Player, do not loop through all of them, index the first one and use it.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: @XResultSetSubSet question
Reply #2 - Oct 25th, 2009 at 2:41am
Print Post Print Post  
Thanks for the response Mark.

I've tried to find a way to loop through the players without success.  I guess I just don't know how to go about it.  I've spent hours on this but just can't seem to find the right combination and placing of the loop code.

Thanks,

Brandon
  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @XResultSetSubSet question
Reply #3 - Oct 25th, 2009 at 3:32am
Print Post Print Post  
Something like this:

Code
Select All
var vRS as Int
var vCRS as Int
var vCount as Int
var inner as Int
var vTCode1 as string
var outer as int
var outer_count as int

     // Get the result set for the players
     vRS = @XResultSetSearch(@FN, "Players", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "")
     If vRS > -1
     {
	    // find out how many players we have
	    outer_count = @XResultSetTotal(vRS)
	    // loop through each of the players
	    for outer  = 1 to outer_count
		  // Set the current record to one of the players
		  XResultSetCurrentPosition(vRS, outer)
		  // Get the activities for this particular player
		  vCRS = @XResultSetSubSet(vRS, "Activity")
		  If vCRS > -1
		  {
			  // See how many activities this player has
			  vCount = @XResultSetTotal(vCRS)
			  // Loop through each of this player's activities
			  For inner = 1 To vCount
				  // Set the current record to an activity
				  XResultSetCurrentPosition(vCRS, inner)
				  // Get a value for the team code field for this activity for this player
				  vTCode1 = @XResultSetValue(vcRS, "Team Code")
				 // Write it out so we can all see it
				 writeln(vTCode1)
			  Next
	     }
	   next
	   // Close the players result set once we are done with all the players
	   XResultSetClose(vRS)
     }
 



Note, I haven't tested this code, but it should give you the general idea about nesting the loops.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: @XResultSetSubSet question
Reply #4 - Oct 25th, 2009 at 6:06pm
Print Post Print Post  
Hi Mark,

Thank you for your help and I really like the way you defined each line. I need to force myself to do that for clarity.  

You’re not gonna believe this but I actually had been trying to get the same code as yours to work.  Yours didn’t work either, or so I thought.  On a whim, and thinking that your code would most certainly work, I changed the @ResultSetValue to an LE on the subform that had many more entries, and low and behold, I get a result.  So, I changed the @ResultSetValue back to the original and scrolled up in the wrtieln() window and found the “Team Code” results. I hadn’t realized before that the results were there all along, along with all the “Team Code” results that did not contain data.  So, the question now is how do I get it to show only Team Code’s that aren’t blank?  I’ve played around with @Isblank = False without success.  Any ideas?

Also, when I direct the results to a @popupchoicelist, all of the results do not get displayed at one time, just one result is shown. In order to see the rest of the results, I have to click on the popup window over and over. I don’t have this issue if I use the same popup code with search results from the parent form, only when I get results from the subform.  Any Ideas?

Regarding;  “To get the first Team Code for a Player, do not loop through all of them, index the first one and use it.”   I’m not sure how to index the first one.  I have a default sort spec to put the last entry on the top. When I remove the subform looping from the code and I add an additional team code to the subform, I get the same result, it ignores the newly added team code.  

Thank you for all of your time,

Brandon

  
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @XResultSetSubSet question
Reply #5 - Oct 25th, 2009 at 9:21pm
Print Post Print Post  
Is blank only applies to elements, not string variables. Try using "if(xx <> "")" or using "if(@len(xx) > 0)".
« Last Edit: Oct 26th, 2009 at 1:57pm by The Cow »  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: @XResultSetSubSet question
Reply #6 - Oct 26th, 2009 at 8:58pm
Print Post Print Post  
tcgeo wrote on Oct 25th, 2009 at 6:06pm:
Hi Mark,
 “To get the first Team Code for a Player, do not loop through all of them, index the first one and use it.”   I’m not sure how to index the first one.  I have a default sort spec to put the last entry on the top. When I remove the subform looping from the code and I add an additional team code to the subform, I get the same result, it ignores the newly added team code.  

Thank you for all of your time,

Brandon


Hello Brandon,

You can use XResultSetSort to sort the child result set in the same order as it's displayed on form, so the #1 record will be the one that you want.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: @XResultSetSubSet question
Reply #7 - Oct 27th, 2009 at 1:34pm
Print Post Print Post  
Thanks Ray,

I'll give those a try.

Brandon

  
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: @XResultSetSubSet question
Reply #8 - Oct 27th, 2009 at 4:47pm
Print Post Print Post  
Do I understand correctly that vCRS (@XResultSetSubset) retrieves the child records for the @XResultSet vCR handle?
  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: @XResultSetSubSet question
Reply #9 - Oct 27th, 2009 at 5:22pm
Print Post Print Post  
lksseven wrote on Oct 27th, 2009 at 4:47pm:
Do I understand correctly that vCRS (@XResultSetSubset) retrieves the child records for the @XResultSet vCR handle?


Yes. That is to say that it retrieves the child records of the current record in the result set represented by vCR.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: @XResultSetSubSet question
Reply #10 - Oct 27th, 2009 at 5:23pm
Print Post Print Post  
lksseven wrote on Oct 27th, 2009 at 4:47pm:
Do I understand correctly that vCRS (@XResultSetSubset) retrieves the child records for the @XResultSet vCR handle?


@XResultSetSubSet() retrieves the child record(s) of the current record in the vCR XResultSet
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: @XResultSetSubSet question
Reply #11 - Oct 27th, 2009 at 5:31pm
Print Post Print Post  
I think you mean child records for the @XResultSet vRS handle, not vCR handle?  If so, yes.

If wanted you can use the Charity Donors Sample to test this.
I added a command button to the Main Menu and inserted Ray’s code with the following modifications to work with the CharityDonors sample:
vRS = @XResultSetSearch(@FN, "DONORS", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "")      
vCRS = @XResultSetSubSet(vRS, "Donations Subform")
vTCode1 = @XResultSetValue(vCRS, "amount")  //Or any of the other Donations subform names.
  
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: @XResultSetSubSet question
Reply #12 - Oct 27th, 2009 at 8:51pm
Print Post Print Post  
OK, cool.  Is that an undocumented command/feature?  I couldn't find hide nor hair of it in the manuals.  But I'm glad to know it.  That opens up some possibilities for me. 

Thank you!
  

Larry
Back to top
IP Logged
 
tcgeo
Full Member
***
Offline



Posts: 278
Location: Traverse City, Michigan
Joined: May 13th, 2008
Re: @XResultSetSubSet question
Reply #13 - Oct 27th, 2009 at 8:59pm
Print Post Print Post  
It's described in the List Browser from within the Program Editor.
  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: @XResultSetSubSet question
Reply #14 - Oct 27th, 2009 at 9:04pm
Print Post Print Post  
It is also on page 13 of the documentation Errata that can be found in the downloads area.
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged