Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Calling UDFs from Main Script

Keywords:  call UDFs

Question:

What is the syntax for calling #DefineFunction that resides in a subroutines.WBC file? Is it like?

MAIN

CALL("C:\subroutines.WBC","UpperP = SomeFunc(param1)")
.
.
subroutines.WBC
#DefineFunction SomeFunc(param1)
param2 = StrUpper(param1)
return param2
#EndFunction
I could not find examples of this sort of thing. Also, the documentation says that the function has to be defined before being used a first time. How do you do that in another file? Do you make a call to the subroutine.WBC where all the #DefinFunctions are? Any examples will help greatly.

Answer:

That depends on what exactly the subroutine.wbc is designd for. Is it A file with all UDFs? If so you can just call the routine.wbc, any time before you attempt to call the UDF...

Main script:

path = FilePath(IntControl (1004, 0, 0, 0, 0))

Call(strcat(path,"library.wbt"),"")

;Now setup the vars and use the UDF
now=TimeYmdHms()
doy=DayOfYear(now)
dow=DayOfWeek(now)
Message(strcat("Day of Year: ",doy),strcat("Day of week: ",dow))

ldm=LastDayOfMonth(now)

Message("Last day of this month",ldm)

exit
Called WBC:
;Library of UDFs

#DefineFunction DayOfYear(ToDate)
    ThisYear=ItemExtract(1,ToDate,":")
    JanFirst="%thisyear%:01:01:00:00:00"
    JanFirstJulian=TimeJulianDay(JanFirst)
    ToJulian=TimeJulianDay(ToDate) 
    doy=ToJulian-JanFirstJulian+1
    return (doy)
#EndFunction


#DefineFunction DayOfWeek(ToDate)
    ToJulian=TimeJulianDay(ToDate) 
    dayofweekcode=(ToJulian+5) mod 7
    day=ItemExtract(dayofweekcode+1, "Sun Mon Tue Wed Thu Fri Sat", " ")
    return(day)
#endfunction


#DefineFunction LastDayOfMonth(today)
   nextmonth=TimeAdd(today,"0000:01:00:00:00:00")
   firstofnextmonth=strcat(strsub(nextmonth,1,8),"01:00:00:00")
   lastdayofthismonth=TimeSubtract(firstofnextmonth,"0000:00:01:00:00:00")
   return(lastdayofthismonth)
#endfunction

return   ;required

Article ID:   W14987