Back Again! - Type Mismatch only when Scheduled

Hi,

Sorry to say, This problem has re-occurred, I seem to have a problem with one line in my code!

I am calling a function called “GetCalendarWeek” (located in the Script Library) and I want to put the returned value in a field (Text Field) on the form - I have done all the suggestions from the previous post, but its still happening…here is the code and the offending function :

Sub Initialize

Dim session As New NotesSession

Dim database As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim db As NotesDatabase

Dim kpidoc As NotesDocument





Set db = session.CurrentDatabase

Set view = db.GetView("KPIDailyStatsVW")

Call view.Refresh

Msgbox "Here"

Set kpidoc = db.CreateDocument

Msgbox "Create Document - OK"

kpidoc.Form = "KPIWeeklyStatsFRM"

Msgbox "Set Form - OK"

--------- ******'Problem with the line below - Type Mismatch when sheduled **********---------------

kpidoc.YearWeekTX = GetCalendarWeek

Msgbox "All OK"



'Initialising Variables

dayofweek = Weekday(Now)

std = 0  'Standard Input Actuals

eng = 0 'Engineered Input Actuals

erimo = 0

erind = 0

ermar = 0

eroil = 0

eroilp = 0

erpwr = 0

erwtr = 0

ereng = 0

erstd = 0

ertot = 0

qsimo = 0

qsind = 0

qsmar = 0

qsoil = 0

qsoilp = 0

qspwr = 0

qswtr = 0

qseng = 0

qsstd = 0

qstot = 0

bdeng = 0

bdstd = 0 

bdtot = 0

engot = 0

englt = 0

engtot = 0

engotval = 0

engltval = 0

engtotval = 0

engop = 0

stdot = 0

stdlt = 0

stdtot = 0

stdotval = 0

stdltval = 0

stdtotval = 0

stdop = 0



If dayofweek < 7 Then

	kpidate = Now - dayofweek

	query$ = "FIELD DateDT >= " & Format$(kpidate, "dd/mm/yyyy") & " And FIELD DateDT <= " & Format$(Now, "dd/mm/yyyy")

	j = view.FTSearch( query$, maxDocs% )

	Set doc = view.GetFirstDocument

	Do While Not (doc Is Nothing)

		Call CalculateTotals(doc)

		Set doc = view.GetNextDocument(doc)

	Loop

	Call SetFormTotals(kpidoc, Cint(j))

	Call view.clear

Else

	query$ = "FIELD DateDT = " & Format$(Now, "dd/mm/yyyy")

	j = view.FTSearch( query$, maxDocs% )

	Set doc = view.GetFirstDocument

	Do While Not (doc Is Nothing)

		Call CalculateTotals(doc)

		Set doc = view.GetNextDocument(doc)

	Loop

	Call view.clear

	Call SetFormTotals(kpidoc, Cint(j))

End If

End Sub

The offending function:

Function GetCalendarWeek

%REM

This function calculates the calendar week number

(ISO standard) for a given date value. The format

function of LotusScript (parameter “ww”) does not solve

this problem.

Monday is the first day of the week. Week #1 is the week

that contains the 4th of January (ISO 8601). The week at the

end/beginning of the year belongs to the next/previous year,

if there are 3 days or less of that week in the year in question.

Christian Meis, 4.2.2000

%END REM

Dim InputDateOffset As Integer

Dim YearInQuestion As Integer

Dim January4 As Variant

Dim January4Offset As Integer

Dim FirstMondayOfYear As Variant

Dim January1Offset As Integer

Dim December31Offset As Integer

Dim weeknum As Integer

Dim inputdate As Variant



inputdate = Now

'Add 2 to inputdate as Weir Week Starts on a Saturday not Monday like ISO Week

inputdate = inputdate + 2

’ The year value is preset with that of the input date

YearInQuestion = Year( inputdate )

’ Calculate offset to monday from the input date

InputDateOffset = CalculateIsoWeekday( inputdate )

’ Calculate offsets for the first/last day of the year

January1Offset = CalculateIsoWeekday( Cdat( "01/01/" & Cstr( YearInQuestion ) ) )

December31Offset = CalculateIsoWeekday( Cdat( "31/12/" & Cstr( YearInQuestion ) ) ) 

’ If the input date is before the 4th of January and the year starts with

’ a friday, saturday or sunday, the week belongs to the previous year

’ if the entered date is not a monday or tuesday

If Month( inputdate ) = 1 And Day( inputdate ) < 4 And January1Offset> 3 And InputDateOffset > 1 Then

	YearInQuestion = YearInQuestion - 1

End If

’ If the input date is after the 28th of December and the year ends with

’ a monday, tuesday or wednesday, then the week belongs to the following year

’ if the entered date is not a saturday or sunday

If Month( inputdate ) = 12 And Day( inputdate ) > 28 And December31Offset < 3 And InputDateOffset < 5 Then

	YearInQuestion = YearInQuestion + 1

End If

’ The 4th of January defines week #1

January4 = Cdat( "04/01/" & Cstr( YearInQuestion ) )

’ Offset to the monday of week #1

FirstMondayOfYear = Cdat( January4 - CalculateIsoWeekday( January4 ) )

’ The time range between the monday of week #1 and the monday

’ of the week in question is divided by 7, plus 1 for the first week

weeknum = ( inputdate - InputDateOffset - FirstMondayOfYear ) \ 7 + 1

’ The return value is a string with the week number and the year

If Len(Cstr( weeknum )) = 1 Then

	GetCalendarWeek = Cstr( YearInQuestion ) & "W0" & Cstr( weeknum ) 

Else

	GetCalendarWeek = Cstr( YearInQuestion ) & "W" & Cstr( weeknum ) 

End If

End Function

Does anyone have any suggestions as to why this isn’t working…I have been working on this for weeks and I have no hair left to Pull!!!

Thanks

F1H

Subject: Back Again! - Type Mismatch only when Scheduled

When this is run locally, it uses the locale settings(date format etc.) on your workstation.When it is run scheduled, it uses the server locale settings (If it is MS Server, it defaults to US format).

A difference between them will give the symptoms you describe.

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Thank you all very much for your replies, I will try the changes you suggest and let you know if it works…

Didn’t know about the Locale and server locale settings had this big an impact…I will keep that in mind… thanks!

F1H

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Now this is really starting to confuse me!!!

Its still happening :

29/01/2007 12:57:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: Here

29/01/2007 12:57:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: Create Document - OK

29/01/2007 12:57:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: Set Form - OK

29/01/2007 12:57:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) error message: Type mismatch

Here is my code now…have I gone wrong anywhere? :

Sub Initialize

Dim session As New NotesSession

Dim database As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim db As NotesDatabase

Dim kpidoc As NotesDocument

Dim strYearWeekTX As String



Set db = session.CurrentDatabase

Set view = db.GetView("KPIDailyStatsVW")

Call view.Refresh

Msgbox "Here"

Set kpidoc = db.CreateDocument

Msgbox "Create Document - OK"

kpidoc.Form = "KPIWeeklyStatsFRM"

Msgbox "Set Form - OK"

'Problem with the line below - Type Mismatch when sheduled

kpidoc.YearWeekTX = GetCalendarWeek()

Msgbox "All OK"



'Initialising Variables

dayofweek = Weekday(Now)

std = 0  'Standard Input Actuals

eng = 0 'Engineered Input Actuals

erimo = 0

erind = 0

ermar = 0

eroil = 0

eroilp = 0

erpwr = 0

erwtr = 0

ereng = 0

erstd = 0

ertot = 0

qsimo = 0

qsind = 0

qsmar = 0

qsoil = 0

qsoilp = 0

qspwr = 0

qswtr = 0

qseng = 0

qsstd = 0

qstot = 0

bdeng = 0

bdstd = 0 

bdtot = 0

engot = 0

englt = 0

engtot = 0

engotval = 0

engltval = 0

engtotval = 0

engop = 0

stdot = 0

stdlt = 0

stdtot = 0

stdotval = 0

stdltval = 0

stdtotval = 0

stdop = 0



If dayofweek < 7 Then

	kpidate = Now - dayofweek

	query$ = "FIELD DateDT >= " & Format$(kpidate, "dd/mm/yyyy") & " And FIELD DateDT <= " & Format$(Now, "dd/mm/yyyy")

	j = view.FTSearch( query$, maxDocs% )

	Set doc = view.GetFirstDocument

	Do While Not (doc Is Nothing)

		Call CalculateTotals(doc)

		Set doc = view.GetNextDocument(doc)

	Loop

	Call SetFormTotals(kpidoc, Cint(j))

	Call view.clear

Else

	query$ = "FIELD DateDT = " & Format$(Now, "dd/mm/yyyy")

	j = view.FTSearch( query$, maxDocs% )

	Set doc = view.GetFirstDocument

	Do While Not (doc Is Nothing)

		Call CalculateTotals(doc)

		Set doc = view.GetNextDocument(doc)

	Loop

	Call view.clear

	Call SetFormTotals(kpidoc, Cint(j))

End If

End Sub

function :

Function GetCalendarWeek() As String

%REM

This function calculates the calendar week number

(ISO standard) for a given date value. The format

function of LotusScript (parameter “ww”) does not solve

this problem.

Monday is the first day of the week. Week #1 is the week

that contains the 4th of January (ISO 8601). The week at the

end/beginning of the year belongs to the next/previous year,

if there are 3 days or less of that week in the year in question.

Christian Meis, 4.2.2000

%END REM

Dim InputDateOffset As Integer

Dim YearInQuestion As Integer

Dim January4 As Variant

Dim January4Offset As Integer

Dim FirstMondayOfYear As Variant

Dim January1Offset As Integer

Dim December31Offset As Integer

Dim weeknum As Integer

Dim inputdate As Variant



inputdate = Now

'Add 2 to inputdate as Weir Week Starts on a Saturday not Monday like ISO Week

inputdate = inputdate + 2

’ The year value is preset with that of the input date

YearInQuestion = Year( inputdate )

’ Calculate offset to monday from the input date

InputDateOffset = CalculateIsoWeekday( inputdate )

’ Calculate offsets for the first/last day of the year

January1Offset = CalculateIsoWeekday( Cdat( "01/01/" & Cstr( YearInQuestion ) ) )

December31Offset = CalculateIsoWeekday( Cdat( "31/12/" & Cstr( YearInQuestion ) ) ) 

’ If the input date is before the 4th of January and the year starts with

’ a friday, saturday or sunday, the week belongs to the previous year

’ if the entered date is not a monday or tuesday

If Month( inputdate ) = 1 And Day( inputdate ) < 4 And January1Offset> 3 And InputDateOffset > 1 Then

	YearInQuestion = YearInQuestion - 1

End If

’ If the input date is after the 28th of December and the year ends with

’ a monday, tuesday or wednesday, then the week belongs to the following year

’ if the entered date is not a saturday or sunday

If Month( inputdate ) = 12 And Day( inputdate ) > 28 And December31Offset < 3 And InputDateOffset < 5 Then

	YearInQuestion = YearInQuestion + 1

End If

’ The 4th of January defines week #1

January4 = Cdat( "04/01/" & Cstr( YearInQuestion ) )

’ Offset to the monday of week #1

FirstMondayOfYear = Cdat( January4 - CalculateIsoWeekday( January4 ) )

’ The time range between the monday of week #1 and the monday

’ of the week in question is divided by 7, plus 1 for the first week

weeknum = ( inputdate - InputDateOffset - FirstMondayOfYear ) \ 7 + 1

’ The return value is a string with the week number and the year

If Len(Cstr( weeknum )) = 1 Then

	GetCalendarWeek = Cstr( YearInQuestion ) & "W0" & Cstr( weeknum ) 

Else

	GetCalendarWeek = Cstr( YearInQuestion ) & "W" & Cstr( weeknum ) 

End If

End Function

This is a Function inside a particular script library, does that matter?

Thanks for the help.

F1H

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Put some print or msgbox statements inside the function GetCalendarWeek.

The error will probably be in this function or a function that is called from here.

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Thanks Andrew & Alex,

I have checked the format of the date on the server, using your code Andrew, and the format is DMY. I am currently putting MsgBox’s in all the functions so I can trap the real line, and you were right Andrew, it does look like to be :

January1Offset = CalculateIsoWeekday( Cdat( "01/01/" & Cstr( YearInQuestion ) ) )

December31Offset = CalculateIsoWeekday( Cdat( "31/12/" & Cstr( YearInQuestion ) ) ) 

But if the date format on the server is right enough, where is it going wrong?

Thanks for all replies.

F1H

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Its happening in another function :

Function GetCalendarWeek() As String

%REM

This function calculates the calendar week number

(ISO standard) for a given date value. The format

function of LotusScript (parameter “ww”) does not solve

this problem.

Monday is the first day of the week. Week #1 is the week

that contains the 4th of January (ISO 8601). The week at the

end/beginning of the year belongs to the next/previous year,

if there are 3 days or less of that week in the year in question.

Christian Meis, 4.2.2000

%END REM

Dim InputDateOffset As Integer

Dim YearInQuestion As Integer

Dim January4 As Variant

Dim January4Offset As Integer

Dim FirstMondayOfYear As Variant

Dim January1Offset As Integer

Dim December31Offset As Integer

Dim weeknum As Integer

Dim inputdate As Variant



inputdate = Now

'Add 2 to inputdate as Weir Week Starts on a Saturday not Monday like ISO Week

inputdate = inputdate + 2

’ The year value is preset with that of the input date

YearInQuestion = Year( inputdate )

’ Calculate offset to monday from the input date

InputDateOffset = CalculateIsoWeekday( inputdate )



Msgbox "Into ISO"

’ Calculate offsets for the first/last day of the year

January1Offset = CalculateIsoWeekday( Cdat( "01/01/" & Cstr( YearInQuestion ) ) )

December31Offset = CalculateIsoWeekday( Cdat( "31/12/" & Cstr( YearInQuestion ) ) ) 



Msgbox "ISO OK"

’ If the input date is before the 4th of January and the year starts with

’ a friday, saturday or sunday, the week belongs to the previous year

’ if the entered date is not a monday or tuesday

If Month( inputdate ) = 1 And Day( inputdate ) < 4 And January1Offset> 3 And InputDateOffset > 1 Then

	YearInQuestion = YearInQuestion - 1

End If

’ If the input date is after the 28th of December and the year ends with

’ a monday, tuesday or wednesday, then the week belongs to the following year

’ if the entered date is not a saturday or sunday

If Month( inputdate ) = 12 And Day( inputdate ) > 28 And December31Offset < 3 And InputDateOffset < 5 Then

	YearInQuestion = YearInQuestion + 1

End If

’ The 4th of January defines week #1

January4 = Cdat( "04/01/" & Cstr( YearInQuestion ) )

’ Offset to the monday of week #1

FirstMondayOfYear = Cdat( January4 - CalculateIsoWeekday( January4 ) )

’ The time range between the monday of week #1 and the monday

’ of the week in question is divided by 7, plus 1 for the first week

weeknum = ( inputdate - InputDateOffset - FirstMondayOfYear ) \ 7 + 1



Msgbox "OK"

’ The return value is a string with the week number and the year

If Len(Cstr( weeknum )) = 1 Then

	GetCalendarWeek = Cstr( YearInQuestion ) & "W0" & Cstr( weeknum ) 

Else

	GetCalendarWeek = Cstr( YearInQuestion ) & "W" & Cstr( weeknum ) 

End If

End Function

At the line that Andrew mentioned, its going into another function…this one :

Function CalculateIsoWeekday( tmpdate As Variant ) As Integer

%REM

This function converts the weekday-numbers from the

standard function to an offset acc. to the ISO version

monday → 0, … , sunday → 6

%END REM

Msgbox "In ISO"



Dim n As Integer



n = Weekday( tmpdate )



If n = 1 Then ' sunday to end of week

	n = n + 7

End If



CalculateIsoWeekday = n - 2



Msgbox "ISO OK"

End Function

*****ADDED :

Log Entry for function - IT IS THE DECEMBER THATS MESSING IT UP!!!

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: Here

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: Create Document - OK

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: Set Form - OK

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: In ISO

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: 1/31/07 1:51:36 PM

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: ISO OK

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: Into ISO

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: In ISO

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: 1/1/07

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: ISO OK

29/01/2007 01:51:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) error message: Type mismatch

any ideas as how to fix?

Thanks

F1H

Subject: RE: Back Again! - Type Mismatch only when Scheduled

It’s the CDat call that is attempting to transform the dd/mm/yyyy date to an internal date that’s failing.

A solution may be to switch from using CDat to DateNumber.

DateNumber ( year , month , day )

When you checked the server date format, did you ensure that the agent was being run on the server by the server?

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Andrew,

Thanks for your reply, really appreciate the help…

The agent was being ran by me on the server, I dont have access to a server ID, so I cant sign it as that. (unfortunately)

How would I encorporate the DateNumber(year,month,day) amendment and where should it go?

I’m sorry for all the questions, but I have been dumped into the deepend and I didn’t even write this.

Thanks!

F1H

Subject: RE: Back Again! - Type Mismatch only when Scheduled

So the agent was being run by you, explaining why it is still being reported as DMY.

In instances of CDat(“dd/mm/yyyy”), replace this with

DateNumber(yyyy, mm, dd) where the yyyy, mm and dd are numbers not strings.

For example, the code:

’ Calculate offsets for the first/last day of the year

January1Offset = CalculateIsoWeekday( Cdat( “01/01/” & Cstr( YearInQuestion ) ) )

December31Offset = CalculateIsoWeekday( Cdat( “31/12/” & Cstr( YearInQuestion ) ) )

becomes

’ Calculate offsets for the first/last day of the year

January1Offset = CalculateIsoWeekday( DateNumber(YearInQuestion, 1, 1))

December31Offset = CalculateIsoWeekday( DateNumber( YearInQuestion, 12, 31))

Subject: RE: Back Again! - Type Mismatch only when Scheduled

29/01/2007 02:27:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: 12/31/0729/01/2007 02:27:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: ISO OK

29/01/2007 02:27:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: ISO OK

29/01/2007 02:27:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: In ISO

29/01/2007 02:27:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: 4/1/07

29/01/2007 02:27:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: ISO OK

29/01/2007 02:27:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: OK

29/01/2007 02:27:36 PM AMgr: Agent (‘3. Create Weekly KPI’s’ in ‘OWReport.nsf’) message box: All OK

Above is the log…check out the first line!!! - Its still putting the date in the wrong format…here is the revised code :

Function GetCalendarWeek() As String

%REM

This function calculates the calendar week number

(ISO standard) for a given date value. The format

function of LotusScript (parameter “ww”) does not solve

this problem.

Monday is the first day of the week. Week #1 is the week

that contains the 4th of January (ISO 8601). The week at the

end/beginning of the year belongs to the next/previous year,

if there are 3 days or less of that week in the year in question.

Christian Meis, 4.2.2000

%END REM

Dim InputDateOffset As Integer

Dim YearInQuestion As Integer

Dim January4 As Variant

Dim January4Offset As Integer

Dim FirstMondayOfYear As Variant

Dim January1Offset As Integer

Dim December31Offset As Integer

Dim weeknum As Integer

Dim inputdate As Variant



inputdate = Now

'Add 2 to inputdate as Weir Week Starts on a Saturday not Monday like ISO Week

inputdate = inputdate + 2

’ The year value is preset with that of the input date

YearInQuestion = Year( inputdate )

’ Calculate offset to monday from the input date

InputDateOffset = CalculateIsoWeekday( inputdate )



Msgbox "Into ISO"

’ Calculate offsets for the first/last day of the year

January1Offset = CalculateIsoWeekday( Datenumber(YearInQuestion, 1, 1))

December31Offset = CalculateIsoWeekday( Datenumber( YearInQuestion, 12, 31))

Msgbox "ISO OK"

’ If the input date is before the 4th of January and the year starts with

’ a friday, saturday or sunday, the week belongs to the previous year

’ if the entered date is not a monday or tuesday

If Month( inputdate ) = 1 And Day( inputdate ) < 4 And January1Offset> 3 And InputDateOffset > 1 Then

	YearInQuestion = YearInQuestion - 1

End If

’ If the input date is after the 28th of December and the year ends with

’ a monday, tuesday or wednesday, then the week belongs to the following year

’ if the entered date is not a saturday or sunday

If Month( inputdate ) = 12 And Day( inputdate ) > 28 And December31Offset < 3 And InputDateOffset < 5 Then

	YearInQuestion = YearInQuestion + 1

End If

’ The 4th of January defines week #1

January4 = Cdat( "04/01/" & Cstr( YearInQuestion ) )

’ Offset to the monday of week #1

FirstMondayOfYear = Cdat( January4 - CalculateIsoWeekday( January4 ) )

’ The time range between the monday of week #1 and the monday

’ of the week in question is divided by 7, plus 1 for the first week

weeknum = ( inputdate - InputDateOffset - FirstMondayOfYear ) \ 7 + 1



Msgbox "OK"

’ The return value is a string with the week number and the year

If Len(Cstr( weeknum )) = 1 Then

	GetCalendarWeek = Cstr( YearInQuestion ) & "W0" & Cstr( weeknum ) 

Else

	GetCalendarWeek = Cstr( YearInQuestion ) & "W" & Cstr( weeknum ) 

End If

End Function

Anyone have any ideas, this is really confusing…it should now have the date in the correct format shouldn’t it?

Thanks

F1H

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Since the code is now running, we’ve established that the problem was in the differing ways of handling the short dates between your PC and the server.

I think now the question is what format will be used as the standard.

Looking back at your initial post, one concern is the query string that is used to select the dates uses the dd/mm/yyyy format. This means that incorrect documents are now being selected by the server.

As previously stated, I’ve found that the mm/dd/yyyy format is more the standard. Changing the server short date format to conform to this agents’s requirements would affect all date-related functions in other databases on the server.

If the standard is dd/mm/yyyy, then the server’s International Short date needs to be corrected. If the standard is mm/dd/yyyy, then all date-related aspects of the agent have to be corrected.

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Thanks…you are a great help!

Sorry to drag this out…as you probably have a job and I apologise for taking up so much of you time on this…how would i change the server’s International Short date?

I have Domino Administrator on my machine…could it be done that way?

Thanks

F1H

Subject: RE: Back Again! - Type Mismatch only when Scheduled

Take a look at this:http://www-10.lotus.com/ldd/nd6forum.nsf/55c38d716d632d9b8525689b005ba1c0/1dde6b0f37e9b18a85257236005879c8?OpenDocument

I had a problem where the format returned on the server was different between NotesDateTime class and variants.

Try runnng the code locally and on the server.

MS date formats are held in the server registry in idate keys.

Subject: RE: Back Again! - Type Mismatch only when Scheduled

You’re right, Here is my output from that agent:

29/01/2007 03:29:48 PM AMgr: Agent (‘test’ in ‘OWReport.nsf’) printing: dtToday = 29/01/2007

29/01/2007 03:29:48 PM AMgr: Agent (‘test’ in ‘OWReport.nsf’) printing: vtoday = 1/29/07

How in the world do you fix this? where can you change this…do you have to go into the registry?

Which method do you think I should go with, change the server, or change the code?

Thanks

F1H

Subject: Puzzled Now!!

The Agent now runs - great!

But instead of getting week 5…i’m getting week -6, I am completely confused now!!!

I have changed the date format in the initial agent to mm/dd/yyyy so it should tie in with the server…

Sub Initialize

Dim session As New NotesSession

Dim database As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument

Dim db As NotesDatabase

Dim kpidoc As NotesDocument

Dim strYearWeekTX As String

Set db = session.CurrentDatabase

Set view = db.GetView(“KPIDailyStatsVW”)

Call view.Refresh

Set kpidoc = db.CreateDocument

kpidoc.Form = “KPIWeeklyStatsFRM”

'Problem with the line below - Type Mismatch when sheduled

kpidoc.YearWeekTX = GetCalendarWeek(Now)

'Initialising Variables

dayofweek = Weekday(Now)

std = 0 'Standard Input Actuals

eng = 0 'Engineered Input Actuals

erimo = 0

erind = 0

ermar = 0

eroil = 0

eroilp = 0

erpwr = 0

erwtr = 0

ereng = 0

erstd = 0

ertot = 0

qsimo = 0

qsind = 0

qsmar = 0

qsoil = 0

qsoilp = 0

qspwr = 0

qswtr = 0

qseng = 0

qsstd = 0

qstot = 0

bdeng = 0

bdstd = 0

bdtot = 0

engot = 0

englt = 0

engtot = 0

engotval = 0

engltval = 0

engtotval = 0

engop = 0

stdot = 0

stdlt = 0

stdtot = 0

stdotval = 0

stdltval = 0

stdtotval = 0

stdop = 0

If dayofweek < 7 Then

kpidate = Now - dayofweek

query$ = "FIELD DateDT >= " & Format$(kpidate, “mm/dd/yyyy”) & " And FIELD DateDT <= " & Format$(Now, “mm/dd/yyyy”)

j = view.FTSearch( query$, maxDocs% )

Set doc = view.GetFirstDocument

Do While Not (doc Is Nothing)

Call CalculateTotals(doc)

Set doc = view.GetNextDocument(doc)

Loop

Call SetFormTotals(kpidoc, Cint(j))

Call view.clear

Else

query$ = "FIELD DateDT = " & Format$(Now, “mm/dd/yyyy”)

j = view.FTSearch( query$, maxDocs% )

Set doc = view.GetFirstDocument

Do While Not (doc Is Nothing)

Call CalculateTotals(doc)

Set doc = view.GetNextDocument(doc)

Loop

Call view.clear

Call SetFormTotals(kpidoc, Cint(j))

End If

End Sub

Anyone have any suggestions??

Thanks for all the help.

F1H

Subject: RE: Puzzled Now!!

Are you testing this on your PC which is still set to DMY?

I forget how to go about changing this to MDY. Looking up now but perhaps someone who remembers can provide the info.

Subject: RE: Puzzled Now!!

Thanks for your reply, Andrew,

I am still testing it on my PC, but the agent is running on the server.

Just to recap, the problem seems to be because the PC’s date format is dd/mm/yyyy and the server’s date format is mm/dd/yyyy. If anyone could provide any info as to how to fix this that would be great!

Thanks

F1H

Subject: RE: Puzzled Now!!

If the week returned is -6 instead of 5, and the agent is running then this more likely indicates that the GetCalendarWeek function is faulty.

I investigated ISO-weeks after examining your code.

From information from:

and code derived from:

I’ve created the following functions: ISOYearWeek and YearStart (code below).

Replace your calls to GetCalendarWeek with ISOYearWeek(Today).

I’ve done some preliminary testing (well, one call).

Please post if your tests come out fine so I can add this to my big library of stuff.

Function ISOYearWeek(pDate As Variant) As String

'-Returns the ISO Year and Week in format yyyyww for a given date

'

Dim tYear As Integer

Dim tYearStart As Variant

Dim ISOWeekNum As Integer



tYear = Year(pDate)

tYearStart = YearStart(tYear)



ISOWeekNum = (pDate - tYearStart) \ 7 + 1



ISOYearWeek = Cstr(tYear) + "W" + Right("0" + Cstr(ISOWeekNum), 2)

End Function

Function YearStart(WhichYear As Integer) As Variant

'-Returns the date of the first Monday of a given year.

' In the ISO system, the first week of a year is the first week in which a Thursday occurs

' and a year always begins on a Monday.

' Therefore, if January 1st is on a Monday, Tuesday, Wednesday or Thursday, it is in week 01.

' If January 1st is on a Friday, Saturday or Sunday, it is in week 52 or 53 of the previous year

' and the next week is week one.

Dim WkDay As Integer

Dim NewYear As Variant



NewYear = Datenumber(WhichYear, 1, 1)



'-Get the weekday, adjusting so that Monday = Day 1, Sunday = Day 7

' instead of the Notes Standard, Sunday = Day 1 to Saturday = Day 7

' To do this, we just get the weekday of the previous day

WkDay = Weekday(NewYear-1)



'-Monday to Thursday (WkDay 1 to 4), adjust to Monday

If WkDay < 5 Then

	YearStart = NewYear - (WkDay-1)

Else

	'-Friday, Saturday or Sunday, adjust to the next Monday

	YearStart = NewYear + (8-WkDay)

End If

End Function

Subject: Solution Found - Works Perfectly, Thanks Andrew

Hi Andrew,

Thank you for your massive effort - it looks like you have stripped out all of the rubbish and streamlined the whole code, aswell as fix the big(s). Very Very nice coding!

Anyway, I have done what you have suggested and have done a MANUAL test, which is

working great! I then scheduled it…it worked perfectly!!!

Really appreciate your help - Thank you very much. Do you have your own library??? - Is it available online at all?

Thank you once again Andrew - You have been a great help.

Kind Regards

Jamie Grant