Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date Calculation
Message
From
04/01/2007 09:06:05
Mike Yearwood
Toronto, Ontario, Canada
 
 
To
03/01/2007 15:51:23
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows 2000 SP4
Network:
Windows 2000 Server
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01181507
Message ID:
01182184
Views:
22
Sam

>No. I have looked at both tables and both curdue and daterecv column have dates in it. Thanks, Sam

Good scientific method requires that you investigate by using a pair of dates for which your function is returning different results. Please show us such a pair.

I must also point out that code that COUNTS the days by looping gets slower as the number of days between the two dates increases.

This performance problem will be magnified by calling the UDF in an SQL command, as it will operate on every row in the table. I know some people say don't bother optimizing until later, but I say don't add slow parts in the first place.

The UDF is a component and it is good practice for a component to hide complexity from the rest of the application's components at runtime. So it's not important if the UDF is easy to code, just that it works and is fast and reliable.

In the interest of modern FoxPro code, look at this version of your UDF:

You should use LPARAMETERS not just PARAMETERS. t represents a parameTer. l represents local. Use Vartype() instead of type whenever possible. Declare variables as LOCAL. Such a function should generate an error instead of returning 0 when bad dates are passed to it. That may be part of the reason you're having a problem.
LPARAMETERS m.td1,m.td2

if (vartype(m.td1)="D" and vartype(m.td2)="D")	&& both variables present?
  LOCAL m.lnwd, m.lnD
  m.lnwd=0	&& variable to hold total number of weekdays
  for m.lnD=0 to ABS(m.td2-m.td1)
    if between(DOW(m.td1+m.lnD,1),2,6)	&& 2=Mon 6=Fri
      m.lnwd=m.lnwd+1
    endif
  endfor
  return m.lnwd
else
  return 0
endif
See also: http://fox.wikis.com/wc.dll?Wiki~Weekdays~VFP
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform