Using an Imported Text File - Create Appointment/Schedule with Rounding Capability for Conflicts

Author: Tripp W Black

Created: 03/01/2001 at 09:33 AM


Notes Developer Tips
LotusScript, Agents

Here is the FINAL code. Just to recap, it makes appointments automatically.
Users at the Expo will have a card slider. Lucky for me, it just dumps it into a text file. So I have an agent that will read in the text file, and create appointments.

It takes each line, tests the time with the one before it, and if they are the same, it bumps it up to the nearest quarter hour.

So if one line has a time of 11:25, it will round it to 11:30. If the next line has a time of 11:29, since there is already an appointment at 11:30, it will create it at 11:45 and so on.

Thanks for everyone's help!!!
Jess :-)

Sub Initialize
' Declared a type RecType, with each field name
Dim arrayOfRecs() As RecType
Dim arrayOfTimes() As NotesDateTime
Dim result As Variant
Dim array(1 To 2) As NotesDateTime
Dim txt As String
Dim fileNum As Integer
Dim doc As NotesDocument
Dim db As NotesDatabase
Dim counter As Integer
Dim countRec As Integer
fileNum% = Freefile()
counter% = 0
Open "c:\leads.txt" For Input As fileNum%
Do While Not Eof(fileNum%)
' Read each line of the file.
Line Input #fileNum%, txt$
' Increment the line count.
counter% = counter% + 1
' Return the file pointer to the beginning of the file.
Seek fileNum%, 1
' The file has counter number of lines in it, so arrayOfRecs()
' is defined with that number of elements.
Redim arrayOfRecs(1 To counter%)
Redim arrayOfTimes(2 To counter%)
' Read the contents of the file into arrayOfRecs.
For countRec% = 1 To counter%
Input #fileNum%, arrayOfRecs(countRec%).Prefix$,arrayOfRecs(countRec%).FirstName$,arrayOfRecs(countRec%).MiddleName$,_
Close fileNum%
' Begin creating a new document for each person.
Set db = New NotesDatabase( "", "massage.nsf" )
For countRec% = 2 To counter%
Set doc = New NotesDocument ( db )
doc.FirstName = arrayOfRecs(countRec%).FirstName$
doc.LastName = arrayOfRecs(countRec%).LastName$
doc.Title = arrayOfRecs(countRec%).Title$
doc.Company1 = arrayOfRecs(countRec%).Company1$
doc.Address1 = arrayOfRecs(countRec%).Address1$
doc.Address2 = arrayOfRecs(countRec%).Address2$
doc.City = arrayOfRecs(countRec%).City$
doc.StateProv = arrayOfRecs(countRec%).StateProv$
doc.ZipPost = arrayOfRecs(countRec%).ZipPost$
doc.Country = arrayOfRecs(countRec%).Country$
doc.Phone1 = arrayOfRecs(countRec%).Phone1$
doc.Phone2 = arrayOfRecs(countRec%).Phone2$
doc.Fax = arrayOfRecs(countRec%).Fax$
doc.Email = arrayOfRecs(countRec%).Email$
doc.InterNetAddr = arrayOfRecs(countRec%).InterNetAddr$
doc.Date = arrayOfRecs(countRec%).Date$
doc.Notes = arrayOfRecs(countRec%).Notes$
doc.Completed = "No"

'Date evaluations
formatString = |@ReplaceSubstring("| & doc.Date(0) & |" ; "-" ; "/")|
newval = Evaluate(formatString)
doc.Date = newval(0)

'Time evaluations
Dim m_dateTime As NotesDateTime
doc.Time = Format(arrayOfRecs(countRec%).Time$,"hh:mm AM/PM")
datestring = doc.Date(0) + " " + doc.Time(0)
Set arrayOfTimes(countRec%) = New NotesDateTime(datestring)
numMinute = Val(Mid$( arrayOfTimes(countRec%).LocalTime, 15, 2))
newMinute = Round( numMinute/15, 0)*15
adjMinute = newMinute - numMinute
Call arrayOfTimes(countRec%).AdjustMinute(adjMinute,True)

If(countRec% > 2) Then
If(arrayOfTimes(countRec%-1).localTime >= arrayOfTimes(countRec%).localTime) Then
arrayOfTimes(countRec%).localTime = arrayOfTimes(countRec%-1).localTime
Call arrayOfTimes(countRec%).AdjustMinute(15,True)
End If
End If

Set doc.Time = arrayOfTimes(countRec%)

Call doc.Save( True, True )
End Sub

I've been playing around for a bit, and a neat thing I've discovered is that it is very easy to change the round time for any other application.

It's just a matter of changing these two lines:
For example, if you wanted it to round and set to the nearest 10 minutes...

newMinute = Round( numMinute/10, 0)*10
Call arrayOfTimes(countRec%).AdjustMinute(10,True)

previous page