Connecting Tech Pros Worldwide Help | Site Map

Question about handling multiple FileSystemObjects

Newbie
 
Join Date: Mar 2009
Posts: 3
#1: Mar 10 '09
Folks,
Looking for a little advice on how to get this portion of my program working. I am developing a terminal emulation program to help us out at work. It is using multiple winsock controls to connect to various devices. As well, I wish to keep log files for each interaction. I had initially designed this using the FileSystemsObject and then using the OpenTextFile method. Where I am falling down is how to keep track of the textstream objects that will be created. I had thought of just creating a listbox (not visible to the user) to just store the textstream handle in it but this does not work. When you try to use the string that was stored in a .Write method it bombs because it is expecting a textstream object, not a string. I know I may not have explaind this very well but I am really open for further discussion on this. I am at a standstill. Below is a small code snip-it to give a little idea of where I was going.....

'Open the log file for either 'Overwrite' or 'Append'
If (StrComp("Overwrite", retString, vbTextCompare) = 0) Then
Set fs = CreateObject("Scripting.FileSystemObject")
log_handle = "log_handle" & Str(activeTab)
lstFileNumArray.List(CInt(lstControlArray.List(act iveTab))) = log_handle
Set log_handle = fs.OpenTextFile(strLogFile, ForWriting, True)

ElseIf (StrComp("Append", retString, vbTextCompare) = 0) Then
Set fs = CreateObject("Scripting.FileSystemObject")
log_handle = "log_handle_" & Str(activeTab)
lstFileNumArray.List(CInt(lstControlArray.List(act iveTab))) = log_handle
Set log_handle = fs.OpenTextFile(strLogFile, ForAppending, True)
Else
MsgBox "Can't open log file " & strLogFile
End If
vdraceil's Avatar
Familiar Sight
 
Join Date: Jul 2007
Location: tamil nadu, INDIA
Posts: 236
#2: Mar 11 '09

re: Question about handling multiple FileSystemObjects


Yes,'fs.OpenTextFile(strLogFile, ForWriting, True)' will return a textstream,so 'log_handle'-the one which receives the return value must be a textstream and not a string.
'Dim log_handle as textstream' would do,i suppose.
If you have so much of textstreams to use,try an array.
'Dim log_handle(25) as textstream'
I dont know if it would work,but try.
Is this what you want?Have i got you correctly?
Newbie
 
Join Date: Mar 2009
Posts: 3
#3: Mar 12 '09

re: Question about handling multiple FileSystemObjects


vdraceil,
Thanks for the reply..... I am realy stuck here. I tried what you advised last night but it doesn't work. VB fired off an error when I tried to run it because you can't assign a teststream to an array. Any other thoughts?

Thanks!
Newbie
 
Join Date: Mar 2009
Posts: 3
#4: Mar 12 '09

re: Question about handling multiple FileSystemObjects


vdraceil,
Ok, I think I have found out how to fix it. Instead of defining log_handle as an array of textstreams I just defined it as an array of type variant. It does seem to be working now. I will finish incorporating this idea and then test the heck out of it.

I cant thank you enough for the idea!!!!!
Reply