; Write a record in the table field by field. If an error occurs, the error message is
; written in an error table and it beeps. The process aborts for this record and continues
; with the next one
;
Proc WriteFields() Logical
Var
LoopVar SmallInt
Errors TCursor
TheError String
EndVar
Try
Threads.InsertRecord()
For LoopVar From 1 To N_FIELDS
StripDoubleQuotes(Fields[LoopVar])
If Not Threads.SetFieldValue(LoopVar,Fields[LoopVar]) Then
TheError=ErrorMessage()
; ErrorShow()
Errors.Open(ErrorTable)
Errors.Edit()
Errors.InsertRecord()
Errors.SetFieldValue(1,FileName)
Errors.SetFieldValue(2,NLines)
Errors.SetFieldValue(3,TheError)
Errors.Close()
Beep()
NErrors=NErrors+1
QuitLoop
EndIf
EndFor
Fields.Empty()
Return TRUE
OnFail
ErrorShow()
Return FALSE
EndTry
EndProc
;
; Retrieve all fields in a record. Then it verifies the number of fields read.
; If it's OK it writes the record in the table, otherwise it does nothing and
; go to the next record.
;
; NB : What shall I do if the number of fields is not good ?...
;
Proc RetrieveFields(FileName String) Logical
Var
FieldRead String
EndVar
MyReadLine(Line)
Fields.Empty()
PosInLine=0
While TRUE
If Not ReadField(FieldRead) Then
Return TRUE
EndIf
Fields.AddLast(FieldRead)
If Fields.Size()=N_FIELDS Then
If Not WriteFields() Then
Return FALSE
EndIf
EndIf
EndWhile
EndProc
;
; Opens a thread on the table and compute each file found in the 'SourcePath' path.
; An info message is printed at the bottom of the window:
; Name of file / File number / Number of files / Number of errors
;
method run(var eventInfo Event)
Var
List FileSystem
BeginTime LongInt
TableName,
SourcePath String
FBI FileBrowserInfo
NewTable Table
EndVar
If MsgQuestion("Create Table","You will choose the path where files to import are located (wildcard '*.*' will be used)\n\nOK to proceed?")="No" Then
Return
EndIf
FBI.AllowableTypes=fbFiles
FBI.PathOnly=TRUE
If Not FileBrowser(SourcePath,FBI) Then
Return
EndIf
If MsgQuestion("Create Table","You will be asking for the name and location of the import table.\nGive a name up to 8 characters...\n\nOK to proceed?")="No" Then
Return
EndIf
While TRUE
If Not FileBrowser(TableName) Then
Return
EndIf
If Not IsTable(TableName) Then
QuitLoop
EndIf
If MsgQuestion("","The table '"+TableName+"' exists... Do you want to append?")="Yes" Then
QuitLoop
EndIf
EndWhile
If Not IsTable(TableName) Then
NewTable=Create TableName With ; I suggest you the values below to save more space.
; Tested over 2500 CompuServe thread files with no broblem
"File" : "A130", ; A12 (If only the file name is given, no path with it)
"Type" : "A50", ; A40
"Forum" : "A50",
"Section" : "A50",
"Message_ID" : "A6",
"Parent_ID" : "A6",
"Subject" : "A255", ; A80
"To" : "A50",
"To_ID" : "A50", ; A11 (Be careful, CompuServe addresses are 11 char. long but
; some other adresses can be longer like Internet addresses)
"From" : "A50",
"From_ID" : "A50", ; A11 (see above for extra comment)
"Creation_Date" : "A8",
"Creation_Time" : "A8",
"Message_Body" : "M25" ; M100 (You can make this field as short as you want because datas
; are stored in a separated .MB file)
; Each record uses 1024 bytes with the initial mode
; and 512 bytes with the suggested one
EndCreate
EndIf
If MsgQuestion("Create Table","You will be asking for the name and location of the error table.\nGive a name up to 8 characters...\n\nOK to proceed?")="No" Then
Return
EndIf
While TRUE
If Not FileBrowser(ErrorTable) Then
Return
EndIf
If Not IsTable(ErrorTable) Then
QuitLoop
EndIf
If MsgQuestion("","The table '"+TableName+"' exists... Do you want to append?")="Yes" Then
QuitLoop
EndIf
EndWhile
If Not IsTable(ErrorTable) Then
NewTable=Create ErrorTable With
"File" : "A130",
"Line" : "I",
"Error" : "A150"
EndCreate
EndIf
BeginTime=CpuClockTime()
Try
Threads.Open(TableName)
Threads.Edit()
If SourcePath.Substr(SourcePath.Size())<>"\\" Then
SourcePath=SourcePath+"\\"
EndIf
List.EnumFileList(SourcePath+"*.*",Files)
Files.RemoveItem(".")
Files.RemoveItem("..")
NFiles=Files.Size()
If MsgQuestion("","The directory '"+SourcePath+"' contains "+String(NFiles)+" file(s)\n\nOK to proceed?")="No" Then