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

From: Azz (Azz_at_azz.com)
Date: 10/19/04


Date: Tue, 19 Oct 2004 11:33:58 +0100

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

  • Re: Loop within (InStr) Loop problem - how do I re-read file in se
    ... > On your first time through first time through your ODAS Sub you 'Set' ... >> I have a script that has to do a loop within another loop, ...
    (microsoft.public.scripting.vbscript)
  • Re: Help with this script if you dopnt mind! issues with the "Do Until....Loop"
    ... The first script runs and the "results" of that script is written to a text file. ... if there are multiple Mailbox Databases (regardless of the number of Exchange Servers in the environment) then the results are not necessarily correct. ... Dim objFSO, objTextFile1, objTextFile2, objTS, strInputFile1, strInputFile2, strOutputFile ... Dim strComputer, objReg, strGUID, strValueName, dwValue ...
    (microsoft.public.scripting.vbscript)
  • Re: free source for bbs
    ... > did it the first time, fixed that, and I know how they did it the ... > second time because my password for the admin script was something ... But we are not laughing with you. ...
    (comp.lang.perl.misc)
  • Re: [kde-linux] Starting ssh at log-in
    ... convenient as possible without losing that security. ... First, if you use password caching anyway, it is only the first time you are ... previous post that your konsole flicks on the screen and then exits. ... script to run rather than a shell. ...
    (KDE)
  • Re: Support Groups
    ... I missed this the first time I read your post. ... I understood he needed to go through a script. ... fan had failed and the script discovered it was the fan on the video card ... Go with the Small Business Group. ...
    (alt.sys.pc-clone.dell)