Domino 9 und frühere Versionen > ND6: Entwicklung

Lotus Script - File Import / open

(1/1)

sculer:
Hallo,

ich hab leider bisher noch nicht die lösung hier in den Forum gefunden, daher poste ich es nun mal.

Ich hab folgendes Ziel (in Lotus Script):
Ich will ein Fenster ala @Prompt haben, wo ich eine File angeben kann, welches dann den inhalt der Datei in einer Variable speichert. Somit kann ich dann einen Parser drüber laufen lassen und somit alles sortieren usw.......

Das Problem was ich hab, wie bekomm ich eine File import, so dass ich den inhalt des Files in einer Variablen hab. (bitte kurzes Code Beispiel)

PS: es handelt sich hier um eine html Datei, also Klartext.

Danke Gruß

Glombi:
Aus der Hilfe:

 Dim ws As New NotesUIWorkspace
  REM Get filename from user
  filenames = ws.OpenFileDialog( _
  True, "Select files",, "c:\")
  If Not(Isempty(filenames)) Then
    Forall filename In filenames
     '// ....
    End Forall
  End If

flaite:
Für das Auslesen der Dateien steht dieses Beispiel in der Notes-Hilfe.

--- Code: ---' In this example, LotusScript reads the contents of a
' comma-delimited ASCII file (c:\123w\work\thenames.txt)
' into an array of RecType. RecType is a user-defined
' data type.
' c:\123w\work\thenames.txt consists of the following:
' "Maria Jones", 12345
' "Roman Minsky", 23456
' "Joe Smith", 34567
' "Sal Piccio", 91234

Type RecType
   empId As Double
   employee As String
End Type       
Dim arrayOfRecs() As RecType
' A dynamic array that will get sized to
' the number of lines in c:\123w\work\thenames.txt
Dim txt As String
Dim fileNum As Integer
Dim counter As Integer
Dim countRec As Integer
' Get an unused file number so LotusScript can open a file.
fileNum% = FreeFile()
counter% = 0
Open "c:\123w\work\thenames.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
Loop
' 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%)
' Read the contents of the file into arrayOfRecs.
For countRec% = 1 To counter%
   Input #fileNum%, arrayOfRecs(countRec%).employee$, _
      arrayOfRecs(countRec%).empId#
Next
Close fileNum%
Print arrayOfRecs(2).employee$ & " " arrayOfRecs(2).empId#
' Output:
' Roman Minsky 23456

--- Ende Code ---

Da sollte auf jeden Fall noch ein solides Errorhandling eingebaut werden.
Close fileNum% MUSS auch in solchen Fällen aufgerufen werden, wenn aus welchen Gründen auch immer während des Lesevorgangs ein Fehler auftritt. 
Ausnahme:  Der Computer explodiert während des Lesevorgangs oder jemand zieht den Stecker. 

Navigation

[0] Themen-Index

Zur normalen Ansicht wechseln