Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help passing FileSystemObject to another Sub

Status
Not open for further replies.

KenG

Technical User
Mar 20, 2000
67
US
I want to pass a text file to a couple of different subs (or functions) each will search for a sting using the File, or TextStream, object line by line. I can't figure out how to do this, I get either 'Object doesn't support this method' or a compile error 'Type mismatch'.

As far as I can tell I've declared, and set the objects correctly. And Microsoft Scripting Runtime is referenced.

Any help would be greatly appreciated.
 
Please paste code where is it wrong !!

Eric De Decker
vbg.be@vbgroup.nl

Licence And Copy Protection AxtiveX.

Download Demo version on my Site:
Promotions before 02/28/2001 (free source codebook),visite my site
 
There is some extra stuff in here that I'll remove in the final product.
Thanks,

Here's the code;

[tt]
Private Sub cmdOpen_Click()
Dim FileName As String
Dim fso As New Scripting.FileSystemObject
Dim fil As Scripting.File, ts As Scripting.TextStream
Dim pos As Long, count As Long, strCurrentLine As String

'This function is copied from Balena, "Programming Visual Basic 6.0"
FileName = LoadTextControl(StringToSearch, CommonDialog1, "Olgio output")

If IsEmpty(FileName) Then
MsgBox "Unable to open file"
Exit Sub
End If

Me.txtFileName = FileName
Set fil = fso.GetFile(FileName)
'Set ts = fil.OpenAsTextStream(ForReading)

FindGeneNameLine (fil) 'See below

End Sub
__________________________________________________________

Public Function FindGeneNameLine(filCurrent As Scripting.File)
Dim ts As Scripting.TextStream
Dim pos As Long, count As Long, strCurrentLine As String
Set ts = filCurrent.OpenAsTextStream
'Read the file -line by line- until you find the line
'Can I pass the file object?
With ts
Do Until .AtEndOfStream
strCurrentLine = .ReadLine
If strCurrentLine Like ">*" Then
Me.StringToSearch = "Line #" & .Line & " " & strCurrentLine
Exit Function
End If
Loop
End With

End Function
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top