Adjust a date

Hi all,

I am having a probelm setting a date filed in my document, if I enter the number of days to adjust, then it is working but if I use a variable of a field value it does not work. here is the code I use. I have tried many ways…

Dim DaysToAdjust As Variant

DaysToAdjust = doc.DaysToStartQuiz(0) 

StartNewDate = Evaluate("@Adjust(@today; 0; 0; 333; 0;0; 0)") ' this is working

’ StartNewDate = Evaluate(“@Adjust(@today; 0; 0; DaysToAdjust; 0;0; 0)”) ’ this is NOT working

docProfile.DateStart = StartNewDate 

thanks p.

Subject: adjust a date

No need to use @adjust

Just add (or subtract) the number of days from your date.

BTW, for future reference, variables within the context of your script are not visible to the Evaluate formula. Only document fields are visible so you could have done:

StartNewDate = Evaluate(“@Adjust(@today; 0; 0; DaysToStartQuiz; 0;0; 0)”)

although as I said, there’s no reason for it in this case. Just do:

StartNewDate = Today() + DaysToAdjust

Subject: RE: adjust a date

thanks for the tip…

the value DaysToStartQuiz comes from a profile document, it is not the current document

Subject: RE: adjust a date

Sorry - I should have said in my previous posting:

StartNewDate = Evaluate(“@Adjust(@today; 0; 0; DaysToStartQuiz; 0;0; 0)”, doc)

instead of just:

StartNewDate = Evaluate(“@Adjust(@today; 0; 0; DaysToStartQuiz; 0;0; 0)”)

That makes it work as intended because otherwise DaysToStartQuiz is Null. But anyway, don’t use Evaluate if you don’t have to.

Subject: RE: adjust a date

I tried this but sill did not work,

Dim ndt As New NotesDateTime( “” )

Set ndt = New NotesDateTime("Now")

StartNewDate = doc.DaysToStartQuiz(0) 

Call ndt.AdjustDay(333 )

' Call ndt.AdjustDay(StartNewDate)

Call ndt.SetAnyTime

Call doc.ReplaceItemValue("DateFailed", 333)' this works

' Call doc.ReplaceItemValue("DateFailed", ndt)' this does notworks

Subject: RE: adjust a date

You can NOT set the value of a field to an object (which is what ndt is) - you would have to get the object’s LSLocalTime property. By the way, what was wrong with using my previous suggestion:

StartNewDate = Today() + DaysToAdjust

that had no need to construct a NotesDateTime object. In fact, now that I see the rest of your code, you can do all of the work above in one line of code:

doc.ReplaceItemValue “DateFailed”, Today() + doc.DaysToStartQuiz(0)

assuming that you have confidence in having valid values in the field DaysToStartQuiz and no error checking is required.

Subject: RE: adjust a date

Yes your previous suggestion was fine, it is just you you suggested if possible not to use evaluate…

thanks all is working great, I have learned good tips with you !

thanks

p.

Subject: RE: adjust a date

Good - I’m glad that we can exchange knowledge. I suppose you can see now that what I meant by not using Evaluate does not necessitate using NotesDateTime.