Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - err object and looping

Reply
 
Old 02-25-2009   #1 (permalink)
Lee


 
 

err object and looping

I have a script that reads folders for files, and then opens them and
e-mails them if they exist.

I have some trouble where if the file is still being created when I discover
it, the script fails.

I've used err.number for other things, but I'm not sure if this will work:
can you loop around an err.number?
like this:

fName = LCase(f1.name)
writelog("Opening File: "&fname) ' Writelog is a separate
function
Set f2 = fso.opentextfile(folderspec3&"\"&fname)
Do While err.number <> 0
Writelog ("Error: " & err.description & "Encountered, Waiting
30 Seconds")
wscript.sleep 30000
Set f2 = nothing
err.clear
Set f2 = fso.opentextfile(folderspec3&"\"&fname)
Loop






My System SpecsSystem Spec
Old 02-25-2009   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: err object and looping


"Lee" <ldspmAT@xxxxxx> wrote in message
news:AA60D3FC-CD7C-408D-86B0-F735BB9F078A@xxxxxx
Quote:

>I have a script that reads folders for files, and then opens them and
>e-mails them if they exist.
>
> I have some trouble where if the file is still being created when I
> discover it, the script fails.
>
> I've used err.number for other things, but I'm not sure if this will work:
> can you loop around an err.number?
> like this:
>
> fName = LCase(f1.name)
> writelog("Opening File: "&fname) ' Writelog is a separate
> function
> Set f2 = fso.opentextfile(folderspec3&"\"&fname)
> Do While err.number <> 0
> Writelog ("Error: " & err.description & "Encountered, Waiting
> 30 Seconds")
> wscript.sleep 30000
> Set f2 = nothing
> err.clear
> Set f2 = fso.opentextfile(folderspec3&"\"&fname)
> Loop
Yes, you can run a loop like yours, provided that you precede it with "on
error resume next". You should also remove the statement "Set f2 =
nothing" - it only generates additional errors which can confuse the issue.

If you wish to test for the existence of your file then the oFSO.FileExists
method would be a more elegant solution.


My System SpecsSystem Spec
Old 02-25-2009   #3 (permalink)
T Lavedas


 
 

Re: err object and looping

On Feb 25, 11:05*am, "Lee" <ldsp...@xxxxxx> wrote:
Quote:

> I have a script that reads folders for files, and then opens them and
> e-mails them if they exist.
>
> I have some trouble where if the file is still being created when I discover
> it, the script fails.
>
> I've used err.number for other things, but I'm not sure if this will work:
> can you loop around an err.number?
> like this:
>
> * * * * * fName = LCase(f1.name)
> * * * * * writelog("Opening File: "&fname) *' Writelog is a separate
> function
> * * * * * Set f2 = fso.opentextfile(folderspec3&"\"&fname)
> * * * * * Do While err.number <> 0
> * * * * * * *Writelog ("Error: " & err.description & "Encountered, Waiting
> 30 Seconds")
> * * * * * * *wscript.sleep 30000
> * * * * * * *Set f2 = nothing
> * * * * * * *err.clear
> * * * * * * *Set f2 = fso.opentextfile(folderspec3&"\"&fname)
> * * * * * Loop
Sure, but you need to take control of the error trapping from the host
with an

On Error Resume Next

statement, maybe something like this ...

On Error Resume Next ' take control of error trapping
Do
err.clear
Set f2 = fso.opentextfile(folderspec3&"\"&fname)
if err.Number <> 0 then
Writelog ("Error: " & err.description _
& "Encountered, Waiting 30 Seconds")
wscript.sleep 30000
Set f2 = nothing
else
exit do
end if
Loop
On Error Goto 0 ' return control to the host

Tom Lavedas
***********
http://there.is.no.more/tglbatch/
My System SpecsSystem Spec
Old 02-25-2009   #4 (permalink)
Al Dunbar


 
 

Re: err object and looping


"T Lavedas" <tglbatch@xxxxxx> wrote in message
news:675d9b87-5bfd-4261-a51b-6b4071422beb@xxxxxx
On Feb 25, 11:05 am, "Lee" <ldsp...@xxxxxx> wrote:
Quote:

> I have a script that reads folders for files, and then opens them and
> e-mails them if they exist.
>
> I have some trouble where if the file is still being created when I
> discover
> it, the script fails.
>
> I've used err.number for other things, but I'm not sure if this will work:
> can you loop around an err.number?
> like this:
>
> fName = LCase(f1.name)
> writelog("Opening File: "&fname) ' Writelog is a separate
> function
> Set f2 = fso.opentextfile(folderspec3&"\"&fname)
> Do While err.number <> 0
> Writelog ("Error: " & err.description & "Encountered, Waiting
> 30 Seconds")
> wscript.sleep 30000
> Set f2 = nothing
> err.clear
> Set f2 = fso.opentextfile(folderspec3&"\"&fname)
> Loop
Sure, but you need to take control of the error trapping from the host
with an

On Error Resume Next

statement, maybe something like this ...

On Error Resume Next ' take control of error trapping
Do
err.clear
Set f2 = fso.opentextfile(folderspec3&"\"&fname)
if err.Number <> 0 then
Writelog ("Error: " & err.description _
& "Encountered, Waiting 30 Seconds")
wscript.sleep 30000
Set f2 = nothing
else
exit do
end if
Loop
On Error Goto 0 ' return control to the host

Tom Lavedas
***********

=============

You might want to consider other reasons for such a failure, as these might
not all resolve themselves. If, for example, the folderspec3 refers to a
mapped folder that is no longer mapped... or if you have only read access...

/Al


My System SpecsSystem Spec
Old 02-25-2009   #5 (permalink)
Lee


 
 

Re: err object and looping

it's a local file on the C:\ Drive.

I do an err.clear before this part of the script, and I have on error resume
next already in place.
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Looping through directory VB Script
Why is my foreach loop only looping through the first object in th PowerShell
Looping and If Structures Vista General
AD Changes and Looping PowerShell
Adding canonical aliases for Compare-Object, Measure-Object, New-Object PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46