Hot Topic (More than 10 Replies) Counting and Sorting lines (Read 1532 times)
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Counting and Sorting lines
Dec 18th, 2005 at 6:17am
Print Post Print Post  
Hi

I am hoping that somebody can tell me if Sesame can do this?

I want to make line numbers for each of the PO subform line like the ones that show on the subformscreen on left side.  But I need to keep them the same as the subform shows, the sequence order . And i need to have the PO top form to show the number of lines on the subform.  And if I remove a line from the subform then the remaining lines need to be reassigned to the new numbers and the total number pf lines on the PO has to go down by a count of 1.

Some times the lines need to be sorted by date, and sometimes by part number  When this new sort happens the line number has to change also so final line number is always the same as the number showing on the sub form.

Is there a way to set this up?  Thank you in advance.
« Last Edit: Dec 20th, 2005 at 6:17am by obfusc88 »  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Counting and Sorting lines
Reply #1 - Dec 19th, 2005 at 5:56am
Print Post Print Post  
SUBSEQUENT EDITED NOTE, 12/20/05: 
The following code does not work.  Needs corrections, but I may not be available for a few weeks.  Will leave it here as a beginning. 
==================================

Hello obfusc88.....

No time for much right now, but this may get you started.  This should get an element (Sequence) to match the line number shown on the subform to the left.

1.  On the "parent" form named PO, add a bound number LE, named LineCount

2. On the "subform" named Lines,  add a bound number LE, named Sequence

3. On the subform Lines,  put the following programming to execute On Form Entry:
Code
Select All
var vLineCount as Int
var vSequence as Int
var vLoop as Int

//Initialize counters
vLineCount = 0
vSequence = 0
vLoop = 1

//Get number of Lines in subform
vLineCount = @FormResultSetTotal("PO!Lines")

//Set the value of Sequence element
While vLoop <= vLineCount {

	 //Go to the next line of the Line Items.
	 FormResultSetCurrentPosition("PO!Lines",vLoop)

	  //Set the value for the LE Sequence
	  vSequence = vLoop
	  Sequence = vSequence

	  //Set to do the next line
	  vLoop += 1
	  }

//Set the LineCount on the parent form
If vLineCount > 0 Then {
	FormFieldValue("PO","LineCount",0,vLineCount)
	} 

=====================
Note, that this is untested off the top of my head. No access to Sesame at this time. You will need to modify to limit code firing when advancing parent records and other unwanted times.

I am sure that someone (Ray/Mark ?) can help provide you with the additional code for controlling the firing modes and the Deleting and the Sorting that you asked about.

Hope this was helpful

========================
12/20/05:
Addition to subsequent note above.  I told you it was untested.  When tested by me a few days later I found some error.  Feel free to ignore the programming above and start from scratch.
« Last Edit: Dec 20th, 2005 at 8:35am by Bob_Hansen »  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Counting and Sorting lines
Reply #2 - Dec 20th, 2005 at 6:18am
Print Post Print Post  
Thank you for the programming.

I will try this out and get back with results.
  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Counting and Sorting lines
Reply #3 - Dec 20th, 2005 at 6:43am
Print Post Print Post  
Good luck....I may not be available for a few weeks, but there are plenty of others here who will help you out.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Counting and Sorting lines
Reply #4 - Dec 20th, 2005 at 8:27am
Print Post Print Post  
Ignore the code I submitted above.  Just got a chance to test it out, but it has problems.  Cannot debug it now, but will edit the original to warn it does not work......Embarrassed

Sorry about that, I told you it was untested.  Cry

It might be less confusing if I delete it completely?
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Counting and Sorting lines
Reply #5 - Dec 20th, 2005 at 11:20pm
Print Post Print Post  
I guess that is good news and ba news.  Now I know why I was having problems and it seemed to get hung up.  I will try to work with what you gave me, but not really sure where to start.  Can anyone else help with this?

  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: Counting and Sorting lines
Reply #6 - Dec 21st, 2005 at 3:20am
Print Post Print Post  
Hello obfusc88

Sorry for any confusion.  I did not expect to be available as of today,  but here is some tested working code before I am off the air.  This is the best I can do right now.

1.  On the "parent" form named PO, add a bound number LE, ReadOnly, named LineCount

2. On the "subform" named Lines,  add a bound number LE, ReadOnly, named Sequence 

3. On the subform Lines,  put the following programming in the Sequence element, to execute On Form Exit:

Code
Select All
var vLineCount as Int

//Uses the current position of the record set
Sequence = @ResultSetCurrentPosition()

//Gets the total number of lines in the record set
vLineCount = @FormResultSetTotal("PO!Lines")

//Sets the Line Count on the parent form
FormFieldValue("PO","LineCount",0,vLineCount) 


===============================
In addition to working, it is much smaller and easier to follow. 

Note...this does not automatically update if a record is deleted.  Need to step through all records. 

I suspect that it mayl be necessary to make a macro that sorts and/or does a Mass Update to the records in the subform, and then runs this code in each record.  Once the macro is created, then you could call the  macro vs. calling this code.

If you cannot make the macro, check back here and someone will be glad to help.   (Mark can probably come up with an easier solution than a complex macro).
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Counting and Sorting lines
Reply #7 - Dec 22nd, 2005 at 4:28am
Print Post Print Post  
Your programming is working to count lines for me.  Thank you for helping me. 

Now I have the same line numbers.  Every time I add a new line item the field changes also.  but if i remove one of the lines then the total number of lines is not good. And if i sort the linenumbers might be wrong but the total count is still good.   But I found that if I step through all of the lines again, then it does get corrected.  Lucky for now not many records are deleted and I can do that.  How can I make this happen automatically so I do not have to step into each one?
  
Back to top
 
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Counting and Sorting lines
Reply #8 - Dec 24th, 2005 at 11:21pm
Print Post Print Post  
I am still needing to step through all lines to keep the numbers correct   Is there any way to make all the lines in the subform run when another one is changed?

And is ther a way to tell that a new subform record has been added to the parent? -new total lines will be more.

Is there a way to tell tha a subform record has been deleted from the parent?  new total lines is less.

Thank you and Happy Holidays.
  
Back to top
 
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Counting and Sorting lines
Reply #9 - Jan 5th, 2006 at 6:15am
Print Post Print Post  
I have been waiting for over a week and don't see any answer here.  I am still needing to go through every line to get the right sequence number when a line is deleted.

I used the lines that were suggested:
 
//Uses the current position of the record set
Sequence = @ResultSetCurrentPosition()

I have this in the On Form Exit section. and it works good when I add a new record, but if I delete a record then the numbers are wrong.  I have to step through every line to make them good again.  This works but I have to remember to do it.  Do I need to put this in another section?  I think that this needs some kind of a loop to run by itself?  Or maybe this is something that Sesame cannot do?


  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Counting and Sorting lines
Reply #10 - Jan 5th, 2006 at 1:58pm
Print Post Print Post  
Quote:
I am still needing to go through every line to get the right sequence number when a line is deleted.

Maybe you would need a command button on the parent that executes code that will loop through all of the subrecords and reassign them a new number.

At one time I also had some code in a subform to calculate the total of the subrecords, and place that value in the parent record. But, I found it was better to put the code in the parent form's Global Code event as a Subroutine, which is called in the parent's On Form Exit, On Form Change, and in a command button. The button is so I can force a recalculation if I am not making changes to the parent record, but have changed a subrecord.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Counting and Sorting lines
Reply #11 - Jan 6th, 2006 at 5:26am
Print Post Print Post  
Thank you for your help Carl.  Your idea to use a button sounds like it will work.  But can you tell me how to write the programming that would be done with the button?  Sometimes there are only one of two lines and sometimes  there might be 10 lines or more.

If I have a button on the main form I will have to remember to click on it.  Should I put the programming in the main form On Form Enter?  Won't that programming run as soon as I exit the subform lines so I don't need to remember?
  
Back to top
 
IP Logged
 
Carl Underwood
Senior Member
Members
*****
Offline



Posts: 1351
Location: New Hampshire
Joined: Mar 11th, 2003
Re: Counting and Sorting lines
Reply #12 - Jan 7th, 2006 at 1:34am
Print Post Print Post  
Quote:
Sometimes there are only one of two lines and sometimes there might be 10 lines or more.

That's okay, luckily, Sesame can tell us how many there are.

Quote:
...programming in the main form On Form Enter?  Won't that programming run as soon as I exit the subform lines...?

No, it won't. Sesame does not consider moving from a subform to the parent an On Form Entry event. You would need to advance to the next parent record and back again, for the On Form Entry event to execute.

Quote:
If I have a button on the main form I will have to remember to click on it.  Should I put the programming in the main form On Form Enter?

Well, you have a few choices here.

1) There's nothing to stop you from putting the code in the command button AND another event, like the the parent's On Form Exit. That way, if you want to see the line numbers right away, you can click on the button. If you don't care to see them right then (or if you forget to click the button), the parent's On Form Exit event will take care of it.
2) You could also place the same exact code in a subform event. If you put it in the subform's On Form Exit, it will re-number the lines every time you navigate up or down the subform lines. The only problem with this one, is that it can be a little distracting, because the gray highlight will scan from the top subform line to the bottom one every time you navigate up or down.
3) If you don't need to see the new numbering until the next time the parent form is viewed, you could simply place the code in just the parent On Form Entry event.

Just keep in mind that placing the code in an exit or entry event for the parent, may slow you down while navigating the parent records - especially if there are a lot of subform lines. In any case, you'll probably want to test it in a few different events to see what works best for you.

Code
Select All
var vCnt as int	//Subform count
var i as int	//Subform instance


//Tells us the number of subforms for this parent
vCnt = @FormResultSetTotal("MySubform")


//Loop through all of the subforms
//"MyLE" is the name of the subform LE that you want the line number in
For i = 1 to vCnt
	FormFieldValue("MySubform", "MyLE", i, i)
Next
 



Let me know how you make out.
  


Carl Underwood
CDU Computer Consulting LLC
Epsom, New Hampshire
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: Counting and Sorting lines
Reply #13 - Jan 7th, 2006 at 3:53am
Print Post Print Post  
Thank you Carl.  You have made a good explanation for me to follow.  I think I can do this now, you have given me the  program to do all of the lines, and some ideas about where to put it.  It might take me a few days to return with my results, but I will let you know what happens.
  
Back to top
 
IP Logged