I have a public property called “Readstream” in Window1 that stores the text when I load a text file. I have two methods that read “Readstream” property, the first one works fine but the second doesn’t get any information when the “readstream” is read. I have include a Msgbox previously to read the “readstream” but it is empty. Why? Could anybody help me?
Readstream is declared as binarystream in a Public property.
[code] // This is the first method to load the text file
Dim readFile as FolderItem
readfile = GetOpenFolderItem(“text/plain”)
If readFile <> Nil Then
SelectInfo.Text = readFile.NativePath
ReadStream = BinaryStream.Open(readFile, False)
TextArea.Text = “”
TextArea.AppendText(ReadStream.Read(1000, Encodings.SystemDefault))
End if[/code]
[code] //This is the second method to parse some text from the “ReadStream” property
Dim rg as New RegEx
Dim myMatch as RegExMatch
rg.SearchPattern = TextField1.Text
myMatch = rg.search(ReadStream.Read (255, Encodings.SystemDefault))
…
myMatch = rg.Search // Get the next match
wend[/code]
Why the “Readstream” is empty in the second method if the property is public (global)?
GLobal can be misleading… more important is what the actual SCOPE is
So… WHERE are these two methods?
Are they in the same window? (ie. the same scope)
Are there more than one declaration in the program? (if so, you have different values in differnent scopes)
Declare the variable in A METHOD, and it will be global to the entire application, regardless of window
It could be wiser to start by simply copying the LR example code whcih you are certain it works, and then proceed with careful modifications when you are sure to understand what it does. Also, the result may depend on the data in ReadStream as well as the Regex pattern you have input in TextArea1.Text.
Yes Michel it’s true but I thought that the ommited code was not necessary to understand you my problem.
I have created a module with the two methods and the “readstream” property included into it. But it didn’t work. Finally I have created a string variable that contains the text of the “ReadStream” property and then I have replaced the property text by the String variable in the second method:
Your first method was reading the first 1000 bytes from the file. Your second method starts processing at byte 1001. If there is less data than that, it will appear empty in the second method.