I developed the following Sub to import data (.xml files) from the Windows Explorer into a Notes Database. The routine works but everytime I use it the messagebox “Subscript out of range” appears. As soon as I have confirmed this error message I can refresh the database and the new data is to be seen perfectly correct. Where does the fault come from?
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim ws As New NotesUIWorkspace
filenames = ws.OpenFileDialog(True,,,"c:\dxl",)
filename$ = filenames(0)
i=0
Do While Not (filename$="")
REM Open xml file named after current database
Dim stream As NotesStream
Set stream = session.CreateStream
If Not stream.Open(filename$) Then
Messagebox "Cannot open " & filename$,, "Error"
Exit Sub
End If
If stream.Bytes = 0 Then
Messagebox "File did not exist or was empty",, filename$
Exit Sub
End If
REM Create new database named after current database
Dim dbCopy As NotesDatabase
Set dbCopy = New NotesDatabase(“”, “”)
Call dbCopy.Create(“”, filename$ & “Copy”, True)
REM Import DXL into new database
Dim importer As NotesDXLImporter
Set importer = session.CreateDXLImporter(stream, db)
Call importer.Process
i = i + 1
filename$ = filenames(i)
Loop
End Sub
Subject: Subscript out of range
Bettina,
The error is probably coming from your line
filename$=filenames(i)
i is probably set to 1 and the total number of items in filenames is almost certainly 1 (which means filenames(1) does not exist)
If you turn your LotusScript debugger on, it will show you where the error occurs and you can view all the variables etc
HTH
Mike
Subject: RE: Subscript out of range
I now changed the sequence a bit but it still does not work.I don’t put filenames(1) into the string variable filename$ and then check whether filename$ is empty anymore. I have a new condition which is supposed to look up whether filenames(i) is empty. This should work without getting out of range, shouldn’t it? I also tried “do while filenames(i)”. I thought it would mean something simmilar to “do while filenames(i) exists”. Wrong assumption, isn’t it?
Sub Click(Source As Button)
Dim session As New NotesSession
Dim db As NotesDatabase
Set db = session.CurrentDatabase
Dim ws As New NotesUIWorkspace
filenames = ws.OpenFileDialog(True,,,"c:\dxl",)
filename$ = filenames(0)
i=0
Do While Not (filenames(i) = "")
REM Open xml file named after current database
filename$ = filenames(i)
Dim stream As NotesStream
Set stream = session.CreateStream
If Not stream.Open(filename$) Then
Messagebox "Cannot open " & filename$,, "Error"
Exit Sub
End If
If stream.Bytes = 0 Then
Messagebox "File did not exist or was empty",, filename$
Exit Sub
End If
REM Create new database named after current database
Dim dbCopy As NotesDatabase
Set dbCopy = New NotesDatabase("", "")
Call dbCopy.Create("", filename$ & "Copy", True)
REM Import DXL into new database
Dim importer As NotesDXLImporter
Set importer = session.CreateDXLImporter(stream, db)
Call importer.Process
i = i + 1
Loop
End Sub
Subject: RE: Subscript out of range
which line are you getting the error on, exactly?
Subject: RE: Subscript out of range
I found a solution!!!You can get the upper bound of filenames through UBound(filenames) and then use a for-next loop to perform the routine.
And it works!!!
Thanks again for the help!