Re: pass by reference

new topic     » goto parent     » topic index » view thread      » older message » newer message

----- Original Message -----
From: "Tyrone Faulkner" <tyrone at idx.com.au>
To: "EUforum" <EUforum at topica.com>
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

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu