Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SafeDivide

Status
Not open for further replies.

nitro0586

Technical User
Sep 24, 2003
3
US
I have this statement in a control and I am getting the following error? "Illegal variable use. - (IIF"

Any Suggestions?
 
What statement do you have ? Only "SafeDivide" ?
 
I have this in a control

SafeDivide(IIF(Year([HEADER_RR.ORIGONPLANDT])>= "2005",[LIBLEADERDETAIL_RR.HOMECNT]/DateDiff("d",[HEADER_RR.ORIGONPLANDT],EndDate)*7,[LIBLEADERDETAIL_RR.HOMECNT]/YTDWEEKSVAR,0))

Do you know what I am doing wrong? I just started using this software.
Any help would be much appreciated.
 
I think your syntax is wrong. iif should be IIF(<expresstion to evaluate>,<then expression>,<else expression>) and safedivide takes
safedivide(<numerator>,<denominator>,<if denom 0 return expression>). So you have

SafeDivide(IIF
(Year([HEADER_RR.ORIGONPLANDT])>= "2005",[LIBLEADERDETAIL_RR.HOMECNT]/DateDiff("d",HEADER_RR.ORIGONPLANDT],EndDate)*7,[LIBLEADERDETAIL_RR.HOMECNT]/YTDWEEKSVAR,0)
)
and you probably want

IIF((Year([HEADER_RR.ORIGONPLANDT])>= "2005"),
safedivide([LIBLEADETAIL_RR.HOMECNT],
DateDiff("d",[HEADER_RR.ORIGONPLANDT],EndDate)*7,
<your divide default>),
safedivide([LIBLEADERDETAIL_RR.HOMECNT],YTDWEEKSVAR,0))

In other words (pseudo code here):
if Year([HEADER_RR.ORIGONPLANDT])>= "2005") then
if DateDiff("d",[HEADER_RR.ORIGONPLANDT],EndDate)* 7 <> 0 then
([LIBLEADETAIL_RR.HOMECNT]/
DateDiff("d",[HEADER_RR.ORIGONPLANDT],EndDate)*7
else
<your divide default>)
end if
else
if YTDWEEKSVAR<>0 then([LIBLEADERDETAIL_RR.HOMECNT]/YTDWEEKSVAR
else
0
end if
end if


or something like that??


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top