Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WMI Script - VB Doesn't pick up error 1

Status
Not open for further replies.

SpankYou

Programmer
Feb 24, 2003
211
0
0
GB
Hey,

I've adapted this WMI script from the Script Center on Microsoft's site. the code itself works fine, but this picks up all drives including A: and E: (my floppy and CDROM), as there is not always a disk in these drives it comes up with the error, Run Time Error '71' Disk Not Ready, so I added and Error Handler, Now It picks up the error for the A: and misses the Drive out if blank, but for the E: it still comes up with the Error, the Error Handler doesn't even acknowledge that there is an error. I can not figure out for the life of me what the problem is. I have even made the error handler non specific, so it will miss out any drive that causes the code to error, but still it didn't pick the error up, Anyone have any ideas?
Thanks in advance for any help

Sam

On Error GoTo ErrorHandler
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO.Drives
For Each objDrive In colDrives

Me.List2.RowSource = Me.List2.RowSource & ";;Drive letter: " & objDrive.DriveLetter
Me.List2.RowSource = Me.List2.RowSource & ";Free space: " & objDrive.FreeSpace
Me.List2.RowSource = Me.List2.RowSource & ";Total size: " & objDrive.TotalSize
Miss:
Next

Exit Sub

ErrorHandler:
If Err.Number = 71 Then
GoTo Miss
End If

"You couldn't fool your mother on the foolingest day of your life if you had an electrified fooling machine." - Homer
 
Hmm, not sure if this is going to help, but:

I've found that this way of error handling is a one shot-shot thing. That is, it will find the specified error once, and jump to the marker in the code ("miss:" in the code you wrote). If the same error happens again before you exit the function, the error handler is not invoked.

The a: drive is the first to be checked, and throws up the error, no problem, but that's it, your one shot used. The e: drive error is therefore not handled.

I know this isn't a solution, but it might help clarify the problem.

Steve
 
Use Resume to clear the error before reentering the loop:

ErrorHandler:
If Err.Number = 71 Then
Resume Miss
Else
Resume ExitSub
End If

ExitSub:

End Sub

Paul Bent
Northwind IT Systems
 
Cheers Paul,

Worked Like A Dream! If thats what your into dreaming of course?!? and stevie thanks for clearing it up, strangely in 5 years of programming (off and on) I don't think I have ever had to pick an error up more than once, Anyways cheers to you both.

Sam

"You couldn't fool your mother on the foolingest day of your life if you had an electrified fooling machine." - Homer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top