I am trying to write a function call or procedure to clean up some code. The only variable that really changes is the dDptSls6Tx2. I'm wondering if there is a way to read that field only. Hope this is clear enough to explain what I'm trying to do.
If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx2 := 0.0;
If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx3 := 0.0;
If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx4 := 0.0;
If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx5 := 0.0;
Vote for best question.
Score: 0
# Vote: 0
Date Posted: 8-Jul-2014, at 3:20 PM EST
From: Al Herman
Re: while loop in procedure or function with changing variab
Sorry I was doing a copy and paste. The bCustTax2 changes as well.
> {quote:title=Al Herman wrote:}{quote}
> I am trying to write a function call or procedure to clean up some code. The only variable that really changes is the dDptSls6Tx2. I'm wondering if there is a way to read that field only. Hope this is clear enough to explain what I'm trying to do.
>
> If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx2 := 0.0;
> If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx3 := 0.0;
> If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx4 := 0.0;
> If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx5 := 0.0;
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 8-Jul-2014, at 5:10 PM EST
From: Al Herman
Re: while loop in procedure or function with changing variab
> {quote:title=Al Herman wrote:}{quote}
> I am trying to write a function call or procedure to clean up some code. The only variable that really changes is the dDptSls6Tx2. I'm wondering if there is a way to read that field only. Hope this is clear enough to explain what I'm trying to do.
>
> If (bCustTax2 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx2 := 0.0;
> If (bCustTax3 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx3 := 0.0;
> If (bCustTax4 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx4 := 0.0;
> If (bCustTax5 = False) and (DeptSls <> 0) and (tblPs_ID.Value <> '') then dDptSls6Tx5 := 0.0;
Vote for best answer.
Score: 0
# Vote: 0
Date Posted: 8-Jul-2014, at 5:08 PM EST
From: Al Herman
Re: while loop in procedure or function with changing variab
> {quote:title=Tom Brunberg wrote:}{quote}
> Al Herman wrote:
>
> > Sorry I was doing a copy and paste. The bCustTax2 changes as well.
>
> Please Al (and others too), copy - paste actual code, do not edit in the forum editor!
>
> So, bCustTax2, should be bCustTax3, bCustTax4 and bCustTax5 on respective 2nd 3rd and 4th line?
> What does the debugger tell you about these when stepping line for line?
>
>
> --
> Tom Brunberg
> firstname.lastname@welho.com
If as tom says there are 4 bCustTaxX then
{code}
if (DeptSls <> 0) and (tblPs_ID.Value <> '') then
begin
If not bCustTax2 then dDptSls6Tx2 := 0.0;
If not bCustTax3 then dDptSls6Tx3 := 0.0;
If not bCustTax4 then dDptSls6Tx4 := 0.0;
If not bCustTax5 then dDptSls6Tx5 := 0.0;
end
{code}
would be as good as it gets Unless you have 5+ of these variable pairs in which case make it an array of records (and yes I'm typing in place)
{code}
TaxThing = record
bCustTax : Boolean;
dDptSlsTx : Double;
end;
TaxStuffArray = array [ 2..5] of TaxThing;
var
TaxStuff : TaxStuffArray;
....
if (DeptSls <> 0) and (tblPs_ID.Value <> '') then
for I := low( TaxStuff ) to high( TaxStuff ) do
with TaxStuff[ I ] do
If not bCustTax then
dDptSls6Tx := 0.0;
{code}
BTW Boolean = True or false is just a waste of space
--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Edited by: Linden ROTH on Jul 8, 2014 3:17 PM
5 is enough to justify record and array