I have code that reads text from a file and inserts it in a database. The code iterates through five lines of the text file inserts them in the database and then exits the subroutine, skipping the text stream close statement and not raising any errors.
[code] dim fldrFile as FolderItem
dim txtStrm As TextInputStream
dim ConvText As String
dim dr As DatabaseRecord
fldrFile = GetFolderItem(fldrFilePath, 3)
If fldrFile <> Nil Then
txtStrm = TextInputStream.Open(fldrFile)
txtStrm.Encoding = Encodings.WindowsLatin1
While Not txtStrm.EOF
ConvText = txtStrm.ReadLine
ConvText = ConvertEncoding(ConvText, Encodings.UTF8)
dr = New DatabaseRecord
dr.Column("FilesListed") = ConvText
App.FileList.InsertRecord("Files", dr)
If App.FileList.Error Then
MsgBox("Database error: " + App.FileList.ErrorMessage)
ElseIf txtStrm.ReadError Then
MsgBox("TestStream Error: " + Str(txtStrm.LastErrorCode))
End If
Wend
txtStrm.Close
End If[/code]
I am baffled and at a loss. Any ideas would be appreciated. Thanks.
put a break on the READLINE and watch the variables… perhaps your file really only has 5 endoflines, and its 5 HUGE “paragraphs”
or there is a Ctrl-Z embedded in the file that is causing it to think it reached EOF.
Tried stepping through the code. It just hops out of the subroutine after five lines. It skips the txtStrm.Close statement. I tried changing the sorting of the 771 line file, but it still stops after five lines. It does not appear to be the file. It is something in the database or IDE.
I have now found that it has something to do with updating the database from a thread. After a certain interval the thread dies and the program is back in the calling subroutine. I have found that if I increase the thread’s priority that it lasts longer and adds a greater number of records to the database (10 instead of 5). I have no idea why the thread is dying.
Suppose you start a thread like this from a button:
dim t as new MyThread
t.Run
The Thread will start, but as soon as the code for the button ends, the Thread in t will go out of scope and terminate. Instead, you would create a property somewhere more permanent in, say, your Window or a Module, then assign the Thread to that. If a window, and you don’t close it, there will be a reference to the Thread and it will not go out of scope. If a Module, it won’t go out of scope until you quit your app.
An object goes “out of scope” when there is no longer a reference to it anywhere. In other words, as soon as you no longer have a way to access that object, it no longer exists.
Thanks. I did what you suggested, but the behavior is the same. Actually, when the code hits the break point I have set after the database load thread execution, the thread is still in existence in either case: local or app level thread instance. So, for some reason the program is exiting the thread routine when apparently a context switch occurs, not because the thread is ending.
[code] dim i, C as Integer
dim fldrPath, fldrFile as FolderItem
dim strInfo As String
dim dr As DatabaseRecord
fldrPath = GetFolderItem(fldrSearchPath)
C = fldrPath.count
For i = 1 to C
fldrFile = fldrPath.trueItem(i) //uses trueItem so that aliases aren’t resolved
If IsFolder(fldrFile) = True Then //method to check for folders
RecurseFolders(fldrFile.GetSaveInfo(fldrFile)) //Recursive call
Else
IF File_Type(fldrFile) = "pdf" Then
'2_0 Update
dr = New DatabaseRecord
strInfo = fldrFile.GetSaveInfo(fldrFile)
dr.Column("FilesListed") = EncodeBase64(strInfo, 0)
App.FileList.InsertRecord("Files", dr)
If App.FileList.Error Then
MsgBox("Database error: " + App.FileList.ErrorMessage)
End If
End If
End if
I can let you have a hobbled copy. The actual work from the file list won’t work, because it requires an installed copy of dtSearch, but it will process through loading the database all right. What is a good way to get it to you?