Really Baffled any clues as to what is going on?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



I am working on a script, it has an input file of machine names. I am
prompting for the name of that file and doing some error handling if the file
does not exist or the iput is blank. When the logic is in the MAIN body of
the script everything works great! Here is the logic in as a part of MAIN.

__________________________________________________________________
On Error Resume Next
Set objFS = CreateObject("Scripting.FileSystemObject")

Dim fstrInputFile
Dim fstrLogFilePath
Dim fstrErrMsg
Dim fServerList

' Get Name of Input File and Check to see if its valid
fstrInputFile = InputBox("Enter name of file containing machines to modify
Including Full path)","Machines To
Modify","C:\MigrationTools\ListOfWorkstations.txt")

Set fServerList = objFS.OpenTextFile(fstrInputFile)

If fstrInputFile = "" Then
MsgBox ("Operation Cancelled, no input file supplied")
Wscript.Quit(1)
ElseIf Err Then
MsgBox ("Error: "& Err.Description)
Wscript.Quit(1)
End if

' Get Path to Store Log File and Check to see if its valid and Writable
fstrLogFilePath = InputBox("Enter the directory to store the Log File","Log
File Path","C:\MigrationTools\Logs")

If fstrLogFilePath = "" Then
MsgBox ("Operation Cancelled, no path for the log file supplied")
Wscript.Quit(1)
End if
____________________________________________________________________

Now if I move this logic down in to a function and put the results into and
array, everything works as long as there fstrInputFile acutally exisits,
otherwise at the Set fServerList = objFS.OpenTextFile(fstrInputFile) line the
script just dies. Help would be appericated.

Here is the logic in a sub..
____________________________________________________________________
On Error Resume Next
Set objFS = CreateObject("Scripting.FileSystemObject")

'Get the path to required Inputfile And the Logfile path
GetPathArray = Split(GetPath,",")
strInputFile = GetPathArray(0)
strLogFilePath = GetPathArray(1)

Function GetPath
Dim fstrInputFile
Dim fstrLogFilePath
Dim fstrErrMsg
Dim fServerList

' Get Name of Input File and Check to see if its valid
fstrInputFile = InputBox("Enter name of file containing machines to modify
(Including full path)","Machines To
Modify","C:\MigrationTools\ListOfWorkstations.txt")

Set fServerList = objFS.OpenTextFile(fstrInputFile)

If fstrInputFile = "" Then
MsgBox ("Operation Cancelled, no input file supplied")
Wscript.Quit(1)
ElseIf Err Then
MsgBox ("Error: "& Err.Description)
Wscript.Quit(1)
End if

' Get Path to Store Log File and Check to see if its valid and Writable
fstrLogFilePath = InputBox("Enter the directory to store the Log File","Log
File Path","C:\MigrationTools\Logs")

If fstrLogFilePath = "" Then
MsgBox ("Operation Cancelled, no path for the log file supplied")
Wscript.Quit(1)
End if

GetPath = fstrInputFile & "," & fstrLogFilePath

End Function
____________________________________________________________________
.



Relevant Pages

  • Re: Really Baffled any clues as to what is going on?
    ... > I am working on a script, it has an input file of machine names. ... > Dim fstrLogFilePath ... > fstrInputFile = InputBox("Enter name of file containing machines to ...
    (microsoft.public.scripting.vbscript)
  • Re: Getting INput from a List
    ... If the input file is a Word document, ... and if each line ends with a paragraph mark, ... Dim listDoc As Document ... You would replace the Debug.Print statement with your find/replace code.-- ...
    (microsoft.public.word.vba.general)
  • Help with writing text file
    ... I've developed the following script to: search through an input file, ... Dim objWSO ... Dim InputFileName ... ' Write File Header ...
    (microsoft.public.scripting.vbscript)
  • Re: I need a Script
    ... is input) to display the contents of the input file. ... Dim strBOX ... For intROW = 1 To UBound ... because the window became for moments inacive?); ...
    (microsoft.public.scripting.wsh)