I am trying to build a library of vbscript functions and I would like to build in error checking but I am running into a problem, or at least something I don't understand. I want the function to verify the variables it is passed before it begins. The first thing I want to check is that all the variables are specified, but when I tried to test for missing variables I found the error seems to be generated when the function is called but before control is passed to it

' Sample program to demonstrate CheckFreeSpace Functio


if (CheckFreeSpace ("c:", 1200000)) the

wscript.echo "ROOOOOOOMMMMMMMY!

els

wscript.echo "tight

end i

' End Sample program to demonstrate CheckFreeSpace Functio




Function CheckFreeSpace(drvPath, MBNeeded

' usage: if (CheckFreeSpace("c:", 12)) then something

' checks for free space. If the free space on the drive exceeds the

' amount requested returns true. Otherwise it returns false

' the MBNeeded is megabytes needed. d.FreeSpace returns byte

' so we devide by 1,000,000 to get megabytes, and yes I know abou

' using 1024, but 1,000,000 gets the same number as the DIR command

Dim fso, d,

Set fso = CreateObject("Scripting.FileSystemObject"

Set d = fso.GetDrive(fso.GetDriveName(drvPath)

if (d.FreeSpace/1000000 > MBNeeded) the

CheckFreeSpace = Tru

els

CheckFreeSpace = Fals

end i

End Function

Re: Error checking vbscript functions by Michael

Michael
Tue Apr 27 19:06:59 CDT 2004

hiphophank wrote:
> I am trying to build a library of vbscript functions and I would like
> to build in error checking but I am running into a problem, or at
> least something I don't understand. I want the function to verify
> the variables it is passed before it begins. The first thing I want
> to check is that all the variables are specified, but when I tried to
> test for missing variables I found the error seems to be generated
> when the function is called but before control is passed to it.


You might find this thread on the subject useful...

Google Groups: View Thread "Need Help !!"
http://groups.google.com/groups?th=f9c12a59ea1387a0


--
Michael Harris
Microsoft.MVP.Scripting
Sammamish WA US