Re: Loop within (InStr) Loop problem - how do I re-read file in se

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: Ralph (Ralph_at_discussions.microsoft.com)
Date: 10/19/04


Date: Tue, 19 Oct 2004 04:17:01 -0700

Azz,

If I dare ask (sorry, I am a VBS newbie...)......could I be reading in file
"C:\temp\ODAS_info.txt" as a "scripting.dictionary" object instead, to
possibly speed things up, or can't a "dictionary" hold a 2-dimensional array
(as I seem to have read somewhere...)?

Thanks,

Ralph

"Azz" wrote:

> Hi Ralph,
>
> At the begining you set the value of this variable to a string
> representation of your file path.
> :objTextFile2 = "C:\temp\ODAS_info.txt"
>
> On your first time through first time through your ODAS Sub you 'Set'
> objTextFile2 to
> an object
>
> :Set objTextFile2 = objFSO.OpenTextFile(objTextFile2, ForReading, True)
>
> On your second time through your ODAS Sub you try and open a text file with
> the first parameter 'objTextFile2' which at this point is an object and not
> a string,
> therefore causing a type mismatch.
>
> Solution:-
>
> Create a new variable to hold your file path string
> e.g.
> strTextFile2 = "C:\temp\ODAS_info.txt"
>
> Change the line in ODAS Sub from this.
>
> :Set objTextFile2 = objFSO.OpenTextFile(objTextFile2, ForReading, True)
>
> To this.
> :Set objTextFile2 = objFSO.OpenTextFile(strTextFile2, ForReading, True)
>
> Azz P
>
>
>
> "Ralph" <ralph_bergstrom@hotmail.com> wrote in message
> news:a6cf5884.0410180250.329e3fef@posting.google.com...
> > I have a script that has to do a loop within another loop, but I seem
> > to have a problem with the script not re-reading the second file.
> >
> > Script in a nutshell:
> >
> > 1) Get name of subfolder (within folder)
> > 2) Find name of subfolder in CSV file
> > 3) If found, output name of subfolder and second field from CSV file
> > and "reset" CSV file to beginning of file to be able to re-read from
> > beginning
> > 4) If not found, note this on screen/in file, "reset" CSV file to
> > beginning of file to be able to re-read from beginning
> >
> > Problem:
> > I seem to be able to read objTextFile2 in OK line by line, but I can't
> > figure out why I'm still getting the "Type mismatch:
> > 'objFSO.OpenTextFile'" -message.
> >
> > Would anyone out there know what I'm doing wrong...?
> >
> > Thanks,
> >
> > Ralph
> >
> > SCRIPT INFO:
> > ============
> >
> > objInputFile structure:
> > \\<servername1>\users01
> > \\<servername2>\users02
> > \\<servername3>\users01
> > \\<servername4>\users02
> > ---- etc etc etc
> >
> > objTextFile2 structure:
> > JohnA, Police department
> > JohnB, Fire department
> > JohnC, IS
> > JohnD, Accounting
> > ---- etc etc etc
> >
> > Script:
> > ========================================================
> > Option Explicit
> > 'On Error Resume next
> >
> > objInputFile = "C:\temp\homedirs.txt"
> > objTextFile2 = "C:\temp\ODAS_info.txt"
> >
> > Dim UserID, Department, arrODASinfo
> > Dim objTextFile2
> > Dim objInputFile, subFolder
> > Dim objFSO, objshell, folder, strNextLine, strNextLine2, strSize
> > Const ForAppending = 8
> > Const ForWriting = 2
> > Const ForReading = 1
> >
> > Set objFSO = CreateObject("Scripting.FileSystemObject")
> > set objshell = CreateObject("WScript.Shell")
> > Set objInputFile = objFSO.OpenTextFile(objInputFile, ForReading, True)
> > 'Set objTextFile2 = objFSO.OpenTextFile(objTextFile2, ForReading,
> > True)
> >
> > Do Until objInputFile.AtEndofStream
> > strNextLine = objInputFile.ReadLine
> > set folder = objFSO.getfolder (strNextLine)
> > For Each subfolder In folder.subfolders
> > ODAS
> > WScript.Echo subfolder.path & "," & subfolder.name & "," &
> > subfolder.size & "," & Department
> > Next
> >
> > Loop
> > Msgbox "Done"
> > Wscript.Quit
> >
> >
> > ' Subroutine to match username with department name
> > Sub ODAS
> > Set objTextFile2 = objFSO.OpenTextFile(objTextFile2, ForReading, True)
> > Do Until objTextFile2.AtEndOfStream
> > strNextLine2 = objTextFile2.Readline
> > arrODASinfo = split(strNextLine2, ",")
> > UserID = arrODASinfo(0)
> > Department = arrODASinfo(1)
> > If InStr (subFolder.name, UserID) Then
> > Exit Do
> > End If
> > Loop
> > objTextFile2.close
> > Set objTextFile2 = Nothing
> > End Sub
> > ==========================================================
>
>
>



Relevant Pages