Re: Really Baffled any clues as to what is going on?



Frederick wrote:
> 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.
>

It's a bad idea to use 'On Error Resume Next' (inline error handling) this
way.

'On Error Resume Next' should never be in effect for more than a *very*
short span of statements (the one with the potential to throw the error and
the statements to check for the error. Otherwise use 'On Error GoTo 0' to
go back to having the host for the script catch and report unexpected error.

In your specific case, inline error handling with On Error isn't even
necessary...


bFileExists = objFS.FileExists(fstrInputFile)

....and only proceed with processing if bFileExists is true.



> __________________________________________________________________
> 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
> ____________________________________________________________________

--
Michael Harris
Microsoft MVP Scripting




.



Relevant Pages

  • 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 fstrInputFile ... Dim fstrLogFilePath ... fstrInputFile = InputBox("Enter name of file containing machines to modify ...
    (microsoft.public.scripting.vbscript)
  • RE: export user accounts from NT 4.0 domain
    ... ATTENTION THE SCRIPT MUST BE RUNNED FROM A COMPUTER WHERE EXCEL IS ... from the information in a Microsoft Excel spreadsheet. ... Dim strLast, strFirst, strMiddle, strPW, intRow, intCol ... On Error GoTo 0 ...
    (microsoft.public.windows.server.scripting)
  • Re: Password Expire
    ... We have one fron end Edge server in our DMZ which passes email onto two ... I used to schedule a script to run every 24 hours on my Exchange 2003 ... Dim fso, txtarray, BodyText ... Call ProcessFolder (objContainer, numDays) ...
    (microsoft.public.exchange.admin)
  • Re: LDAP query information
    ... a "Dim" statement. ... execution of the script. ... ' Filter on computer object. ... ' Construct LDAP syntax query. ...
    (microsoft.public.windows.server.scripting)
  • Re: Script: Remote shutdown of all domain computers
    ... When trying to run the script from a XP workstation, where i am logged in as ... Dim strBase, strFilter, strAttributes, strQuery, objRecordSet ... 2000 or above and allow shutdown, ... Public Function AllComputersAs String() ...
    (microsoft.public.windows.server.scripting)