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
- Next message: Ralph: "Re: Loop within (InStr) Loop problem - how do I re-read file in se"
- Previous message: McKirahan: "Re: vbs code to the web page"
- In reply to: Ralph: "Loop within (InStr) Loop problem - how do I re-read file in second loop?"
- Next in thread: Ralph: "Re: Loop within (InStr) Loop problem - how do I re-read file in se"
- Reply: Ralph: "Re: Loop within (InStr) Loop problem - how do I re-read file in se"
- Reply: Ralph: "Re: Loop within (InStr) Loop problem - how do I re-read file in se"
- Messages sorted by: [ date ] [ thread ]
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
> ==========================================================
- Next message: Ralph: "Re: Loop within (InStr) Loop problem - how do I re-read file in se"
- Previous message: McKirahan: "Re: vbs code to the web page"
- In reply to: Ralph: "Loop within (InStr) Loop problem - how do I re-read file in second loop?"
- Next in thread: Ralph: "Re: Loop within (InStr) Loop problem - how do I re-read file in se"
- Reply: Ralph: "Re: Loop within (InStr) Loop problem - how do I re-read file in se"
- Reply: Ralph: "Re: Loop within (InStr) Loop problem - how do I re-read file in se"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|