Re: pass by reference
- Posted by Tyrone Faulkner <tyrone at idx.com.au> Mar 11, 2003
- 593 views
Hi Derek, I declared all the common variables at the top of the file and it works like a dream. Actually this was the best solution as it would have been too much fiddling around to send them as parameters because of the quantity. Also each procedure uses most of the variables anyway. It is very quick. The program reads a 7mb comma delimited ascii file, summarizes and writes out to another file (about 3.5mb). All I can say is - a great piece of software. Although I think I will install one of the other editors to speed up productivity. Regards, Tyrone. ----- Original Message ----- From: "Derek Parnell" <ddparnell at bigpond.com> To: "EUforum" <EUforum at topica.com> Sent: Tuesday, March 11, 2003 8:19 AM Subject: Re: pass by reference > > ----- Original Message ----- > From: "Tyrone Faulkner" <tyrone at idx.com.au> > To: "EUforum" <EUforum at topica.com> > Sent: Tuesday, March 11, 2003 12:40 AM > Subject: pass by reference > > > > Is it possible to pass by reference when calling a procedure or do I > > have to declare the appropriate variables (objects) as global? > > > > Yes and No. You can't do it by using the variable's name. You can do by > passing a index to the variable. > > In general, the only way that two or more routines can reference the same > variable name, is if they share the same scope. > > Here one way that it can be done. It's not pretty and you have to wonder if > its worth the effort. > > sequence PBR PBR = {} > constant kTax = 1, kComment = 2, kState = 3, kAmount = 4 > sequence vWHTRate > vWHTRate = {0.15, 0.125, 0.0125, 0.175, 0.30, 0.56, 0.10} > procedure WithholdingTax(integer pCustomer) > integer lRateIdx > > lRateIdx = find(PBR[pCustomer][kState], > {"vic","qld","nsw","wa","sa,"tas","nt"}) > > if RateIdx != 0 then > PBR[pCustomer][kTax] = PBR[pCustomer][kAmount] * > vWHTRate[lRateIdx+1] > PBR[pCustomer][kComment] = sprintf("WHT %2.1f%%", > vWHTRate * 100) > end if > end procedure > > procedure AddCust() > sequence lNewCust > > lNewCust = repeat(0,4) > lNewCust[kTax] = 0.0 > lNewCust[kComment] = "" > lNewCust[kState] = "vic" > lNewCust[kAmount] = 17.43 > > PBR = append(PBR,lNewCust) > > -- Pass the customer by reference (sort of) > WithHoldingTax( length(PBR) ) > end procedure > > > ---------------- > cheers, > Derek Parnell > > > > TOPICA - Start your own email discussion group. FREE! > >