Date/Time variables in LotusScript

Hi All, I posted this code last week and someone started me off in (I think) the right direction. But I’m still stuck. This is a hotspot button that adds a vacation request to the user’s calendar. I’m having a hard time getting the 8:00:00 AM time set. I’m confused by data types. Basically, I get stuck when I’m trying to set the string type variable (StartDateTime1) as the newly incremented date variable (StartDateTime2) so I can set the proper fields on the Calendar entry document.

Any help is very appreciated!!!

Sub Click(Source As Button)

Dim Session As New NotesSession

Dim Workspace As New NotesUIWorkspace

Dim TheDocument As NotesDocument

Dim db As notesDatabase

Dim UserName As String

Set UIDoc = Workspace.CurrentDocument

Set TheDocument = UIDoc.Document

Set db = New NotesDatabase("", "")

’ open mail database

db.openmail

Dim EndDate As String

Dim InitiatedDate As String

Dim InitiatedTime As String

Dim Subject As String

Dim Subject2 As String

Dim Descript As String

Dim StartDateTime1 As String

Dim EndDateTime1 As String 



EndDate = UIDoc.FieldGetText("AbsenceToDate")

InitiatedDate = UIDoc.FieldGetText("AbsenceFromDate")

InitiatedTime = UIDoc.FieldGetText("EndTime44")

'Above EndTime44 is a field in the form that is defaulted to 8:00:00 AM	



Subject = UiDoc.FieldGetText("AbsenceType")

Subject2 = UiDoc.FieldGetText("EmpSignature")

StartDateTime1 = UiDoc.FieldGetText("DateTimeStart")

EndDateTime1 = UiDoc.FieldGetText("DateTimeEnd")

'Above DateTimeStart and DateTimeEnd are fields on the form that take the time-only AbsenceFromDate and 

'AbsenceToDate fields and convert them to a date and time field with 8:00:00 AM time stamp



'Below I adjust EndDate by one day so the loop works for a one-day vacation

'Also set StartDateTime2 so that I can adjust it by a day later. This is where I'm stuck. This doesn't seem right. 

Set StartDate1 = New NotesDateTime (InitiatedDate)

Set EndDate2 = New NotesDateTime (EndDate)

Set StartDateTime2 = New NotesDateTime(StartDateTime1)

Call EndDate2.AdjustDay( 1 )



InitiatedDate = Cstr(StartDate1.DateOnly)

Enddate = Cstr(EndDate2.DateOnly)



'begin loop

Do While InitiatedDate <> EndDate

	

	Dim CalendarEntry As New NotesDocument(db)

	Dim rtitem As New NotesRichTextItem(CalendarEntry, "Body")

	Call rtitem.AddNewline(1)

	UserName = Session.CommonUserName

	CalendarEntry.Form = "Appointment"

	CalendarEntry.Principal = UserName

'use the full username instead of the common name, so the hide- whens in the appointment form work.

	CalendarEntry.Chair = Session.UserName

	CalendarEntry.ExcludeFromView = "D"

	CalendarEntry.OrgTable = "CO"

	CalendarEntry.SequenceNum = 1

	CalendarEntry.Subject = Subject+ " - " + Subject2

	CalendarEntry.~$PublicAccess="1"

	CalendarEntry.~_ViewIcon = 10

'AppointmentType set here 4 is reminder

	CalendarEntry.AppointmentType = "4"

	CalendarEntry.StartDate = Cdat(InitiatedDate)

	CalendarEntry.StartTime = Cdat(InitiatedTime)

	

	CalendarEntry.StartDateTime = StartDateTime1

	CalendarEntry.EndDate = Cdat(EndDate)

	CalendarEntry.CalendarDateTime = StartDateTime1

	Call StartDate1.AdjustDay( 1 )

	Call StartDateTime2.AdjustDay( 1)

	InitiatedDate = Cstr(StartDate1.DateOnly)

	Enddate = Cstr(EndDate2.DateOnly)

'This is where I get stuck…

'The debugger tells me StartDateTime1 is a string - just like InitiatedDate! Why won’t it take the value?

	StartDateTime1 = Cstr(StartDateTime2)

	Call CalendarEntry.save(True, False) 

	

Loop

Messagebox"The entry has been added to your calendar.  Your calendar may need to be refreshed."

End Sub

Subject: You have StartDateTime1 declared As String …

You haveDim StartDateTime1 As String

so it will not take any other data type.

You are using a mixture of front-end and back-end classes. If you are using the front-end classes you are generally stuck with using strings because you are forced to use FieldGetText and FieldSetText.

I would always use the back-end classes in preference because there is so much more control over data types, etc.

Also I would suggest you use integer variables to control loops? You have "Do While InitiatedDate <> EndDate " for instance. Consider using DateValue ( stringExpr ) function to turn the strings into date/time values.

I would agree that it is frustrating that LotusScript does not have a DateTime data type? I declare such variables as Variants and then just make sure that they only get DateTime values.

I guess there is NotesDateTime also but that is sometimes a bit of overkill for some purposes?

Don’t know if that helps?

Mark