Hot Topic (More than 10 Replies) programming question (Read 1898 times)
Mathew Verghese
Member
*
Offline


Always willing to learn

Posts: 15
Location: Kuwait
Joined: Jan 12th, 2004
programming question
Jan 23rd, 2004 at 10:16am
Print Post Print Post  
It is as follows:
We have a from with 4 fields(layout elements) eg., Item1, Item2, Item3 & Item 4, all numerical or money fileds.  The program in Item3 is: Item3 = Item1*Item2. Then we want a grand total of all the figures in the Item3 fields accross the forms added together and placed  in the Item4.  I think QA didnot have this facility.  Help is requested. 
This user form is doing a fantastic job in clearing all the doubts.  Thank you.
Mathew Verghese
  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: programming question
Reply #1 - Jan 23rd, 2004 at 2:27pm
Print Post Print Post  
Quote:
It is as follows:
We have a from with 4 fields(layout elements)


1 form 4 elements
**
Quote:
It is as follows:
we want a grand total of all the figures in the Item3 fields accross the forms added together and placed  in the Item4. 


when you say across all forms what do you mean?

can you please give more deatail of what you are trying to accomplish.

Thanks


  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Mathew Verghese
Member
*
Offline


Always willing to learn

Posts: 15
Location: Kuwait
Joined: Jan 12th, 2004
Re: programming question
Reply #2 - Jan 23rd, 2004 at 4:02pm
Print Post Print Post  
Let me see if I can make myself clear: (1 form and 4 layout elements)
first entry- 20.00x10.00 = 200.00(press F10)
second -    10.00x5.00   =  50.00 (press F10)
third entry-15.00 x 10.00=150.00(F10)
when the above is being done what we get in the Item4 field is 200.00 next 250.00, next 400.00 and so on. what I require is the programming for the Item4 field

Mathew Verghese
  
Back to top
 
IP Logged
 
BOBSCOTT
Senior Member
Members
*****
Offline


That Darn Computer #$X#
{curse words}

Posts: 1195
Joined: Nov 22nd, 2002
Re: programming question
Reply #3 - Jan 23rd, 2004 at 4:23pm
Print Post Print Post  
If I understand correctly you want to add the total across multiple records.

In my case I have a form that is used for invoices and I have a field on my main form that is the total of  all the customers invoices.  The command to take a look at is @FormResultSetTotal

This is the example and logic from what I use. It looks much more overwhelming then it really is. I hope this example and explanation points you in the correct direction.

I have a form called basic info it has a subform called Invoice data. On the Invoice data subform it has a table subform to a form called Line item master.

When a search is performed the client data is displayed on the main form, invoice data is displayed in the subform and invoice detail is displayed on the table subform.

The InvTotal field on the Invoice data form is using on form entry and on element entry programming of 
 
var vcnt as int 
var vloop as int 
var vmytotal as double 
   
vmytotal = 0 
vcnt = @FormResultSetTotal("Line item master") 
vloop = 1 
while vloop <= vcnt 

  vmytotal = vmytotal + @tomoney(@FormFieldValue("line item master", "ItemExtAmt", vloop)) 
  vloop = vloop + 1 

invtotal = vmytotal

To total all line items associated with that invoice and returning the total amount of that particular invoice.

The basic info form has a field called Invoicetotalall that uses on record entry logic of

var vAcnt as int 
var vAloop as int 
var vAmytotal as double 
   
vAmytotal = 0 
vAcnt = @FormResultSetTotal("inv data") 
vAloop = 1 
while vAloop <= vAcnt 

  vAmytotal = vAmytotal + @tomoney(@FormFieldValue("inv data", "INVTOTAL", valoop)) 
  valoop = valoop + 1 

InVoiceTotalAll = vAmytotal

this totals all invoices for this client and returns the total amount the client has outstanding to the field InVoiceTotal.
  

Team – Together Everyone Achieves More
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: programming question
Reply #4 - Jan 23rd, 2004 at 4:50pm
Print Post Print Post  
Quote:
Let me see if I can make myself clear: (1 form and 4 layout elements)
first entry- 20.00x10.00 = 200.00(press F10)
second -    10.00x5.00   =  50.00 (press F10)
third entry-15.00 x 10.00=150.00(F10)
when the above is being done what we get in the Item4 field is 200.00 next 250.00, next 400.00 and so on. what I require is the programming for the Item4 field

Mathew Verghese


Do you need the running total only for the records you are currently entering, or do you need a running total for all the records in the database?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Mathew Verghese
Member
*
Offline


Always willing to learn

Posts: 15
Location: Kuwait
Joined: Jan 12th, 2004
Re: programming question
Reply #5 - Jan 24th, 2004 at 9:14am
Print Post Print Post  
Yes a running total for all the records in the database? 


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


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: programming question
Reply #6 - Jan 24th, 2004 at 3:02pm
Print Post Print Post  
Just set up one more field as Counter, which is a number field.  Sesame gives you capability to setup multple counters which advance by one using Globalvalue () command that was thoroughly discussed earlier.  
[url]http://www.lantica.com/Forum2/cgi-bin/yabb/YaBB.pl?board=gen_disc;action=display;num=1073429412;start=6[/url]

Use the code like

If @IsNew and item4 = "" then
  {
           item4 = @xlookup (@filename, counter -   1, "counter", "item4") + item3
    }

You might have to use massupdate to get the initial value. If you want to have this periodic total set the value of item3 to 0 as certain time breaks like end of the year or end of the month.

You can also use @number to set up counter but you can have only one @number per ?application or may be database (not sure).

I used this technique with Q&A.

Thinking further, the above code will work fine with mass update (ofcouse you have to remove If @isnew conditon), however, the way @number counter and I believe also counter created by globalvalue ( ) command, you might have to modify it a little bit.

If you open up form to add record and decide to exit it, the @number code will have already advanced the counter and there is no mechanism in place to reset it if you decide all of sudden to escape  and not save the record.  When you back to add new record the previous value in the counter would not coincide with any value.

One can solve this problem in more than one ways, just modify the code that it will read the record previous record the highest counter value.

If @IsNew and item4 = "" then 
   {
           item4 = @xlookupr (@filename, 99999999999, "counter", "item4") + item3
     }

There is other way you can accomplish this by using loop in subtracting 1 each time until it does not result in error.  That is ..... if @error ... condition. 

I am not upto the speed with loops quite yet.
« Last Edit: Jan 24th, 2004 at 5:31pm by Bharat_Naik »  
Back to top
 
IP Logged
 
Alec
Lanticans
*****
Offline



Posts: 200
Location: Ascot, England, UK
Joined: Nov 22nd, 2002
Re: programming question
Reply #7 - Jan 24th, 2004 at 3:07pm
Print Post Print Post  
it might be better to edit your original posting and then delete your amendment. That way someone later can view all the good code in one posting.

Click on the "Modify" link above the post. Only the author can modify a posting.
  

Alec
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: programming question
Reply #8 - Jan 24th, 2004 at 3:28pm
Print Post Print Post  
Thank you Alec, I just did that.   Learning something new everyday!! Thanks.
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: programming question
Reply #9 - Jan 24th, 2004 at 5:30pm
Print Post Print Post  
Quote:
If @IsNew and item4 = "" then  
  {
           item4 = @xlookup (@filename, counter -   1, "counter", "item4") + item3
    }


I have ammended my previous note with this note in order to keep continuity. As a result of that, this note might appear as duplicate, please excuse me..

Thinking further, the above code will work fine with mass update (ofcouse you have to remove If @isnew conditon), however, the way @number counter and I believe also counter created by globalvalue ( ) command, you might have to modify it a little bit.

If you open up form to add record and decide to exit it, the @number code will have already advanced the counter and there is no mechanism in place to reset it if you decide all of sudden to escape  and not save the record.  When you back to add new record the previous value in the counter would not coincide with any value.

One can solve this problem in more than one ways, just modify the code that it will read the record previous record the highest counter value.

If @IsNew and item4 = "" then  
  {
           item4 = @xlookupr (@filename, 99999999999, "counter", "item4") + item3
    }

There is other way you can accomplish this by using loop in subtracting 1 each time until it does not result in error.  That is ..... if @error ... condition.  

I am not upto the speed with loops quite yet.
  
Back to top
 
IP Logged
 
Mathew Verghese
Member
*
Offline


Always willing to learn

Posts: 15
Location: Kuwait
Joined: Jan 12th, 2004
Re: programming question
Reply #10 - Jan 29th, 2004 at 7:25pm
Print Post Print Post  
My problem is as follows:For eg., the fields on my form are - item1, item2,total,grandtotal. item1*item2 the result goes to 'total' and to 'grandtotal' field and we are pressing F10 to get a blank page to enter the next, item1*item2 and the result(20x10=200)goes to the field 'total'. The figure we see then in the 'grandtotal' field should be this 200 plus the previous total.  Can we do this in Sesame? If we do what is the programming? Help is requested.
Mathew Verghese
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: programming question
Reply #11 - Jan 29th, 2004 at 7:48pm
Print Post Print Post  
Are you multiplying item1 and item2. Well, still it does not make a difference.  I replied to your earlier inquiry in the following link

http://www.lantica.com/Forum2/cgi-bin/yabb/YaBB.pl?board=gen_disc;action=display...

Sure it works.  If you need to have, I can send you files. Unfortunately it will be difficult to go over all the steps. I did it three different ways, using @number,  without using @number (created counter by using 999999), and third way by creating  counter using Globalvalue () command.

Let me know if you would like to have files Unfortunately, it involves little debugging. You never know ahead of time what problem you may encounter,  especially for neophyte like me.

« Last Edit: Jan 29th, 2004 at 9:49pm by Bharat_Naik »  
Back to top
 
IP Logged