I am not familiar with some of the syntax of your code, and I don't quite follow the logic of it either. But I'll tell you how I do a similar thing and perhaps you can glean something useful from it.
First off I use vb.net and most often the Sharp Develop IDE. I find it most versatile and powerful, being able to connect to any of the Mentor tools in the Expedition tool set, and having many built-in features that enable complex programming.
In any project I create, I add a file-open and file-save dialog. I add these to the main form so that they are available universally. Then I have a read_file function. I set it up to return an arraylist, with each line of the file as an element in the arraylist. The open_file function looks like this:
Public Function read_file(title As String, file as String) as arraylist
Dim file_data As New ArrayList
'this part launches the Open File dialog
if file = "" then
Main_Form.dlg_open.Title = title
Main_Form.dlg_open.FileName = ""
file = ""
if Main_Form.dlg_open.ShowDialog() = dialogresult.OK then
file = Main_Form.dlg_open.FileName
'this part reads the file
Using reader as System.IO.StreamReader = new System.Io.StreamReader(file)
while reader.Peek <> -1
From any other subroutine in the project, I use the following to create an arraylist and read the file into it:
'declare the arraylist
Dim data As New ArrayList
'make sure the file exists
If Not system.IO.File.Exists(open_file_path) Then
tmp = tmp & "There is no " & open_file_path & ". Please try again."
'make sure the arraylist is empty, then read the file into it
data = read_file("", open_file_path)
Now to find something in that file data, I do something like this:
For n = 0 to data.count - 1
If instr(data(n), "stuff to find") > 0 then
'do whatever you want with the string
If your compiler does not support a thing like an arraylist, you could alternatively use an array. I find the arraylist easier because you don't have to ever resize it or know ahead of time how big it needs to be. A little less clumsy to me than normal arrays. For many such reasons, I prefer the vb.net language and the free IDE's that are available for it.
By the way, these methods are very fast. I have used them on files of several hundred thousand lines, and gotten the correct data out in a second or two.
Hope this helps,
Thanks for your assistances, It lead me down a different path to the soultion.
I was successfully able to read the file into a varible as follows. I'm not sure why I had to use the Input with a "$" dollar sign. none of the documetation shows it being done like this. I think the dollar sign indicates a pointer to the file location, but not sure. Although, It does work perfectly.
' if error occurs during open file process, it will generate a runtime error and control is passed to the error handler code.
On Error GoTo ErrorHandler
' open file specified by user input. The file is read into the variable, which is used in the rest of the program.
Open dlg.PathAndNetlistFileName For Input As #1
MsgBox "File I/O error. File does not exist, or path to file is not correct please try again."