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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What is up with error trapping?!

Status
Not open for further replies.

WilliamUT

IS-IT--Management
Oct 8, 2002
182
US
The more I program in vbscript the more I appreciate normal visual basic programming! I can't seem to get anything done with this scripting! Anyways below I have provided a function im writing which checks the registy for a key...if the key does not exist my ubound(arrsubkeys) is causing an error...i have tried to error trap this so i can return a false with no sucsess...any suggestions?


function AppInstalled(ApplicationName) 'this checks the registry if the application is already installed returns true / false
Dim oReg,strkeypath, arrSubKeys, subkey, strcomputer, index


strComputer = "."
strKeyPath = "SOFTWARE\myAPPS"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

'*** Here is where the error hits if the key does not exist
'*** if it does exist everything is just fine!
for index = 0 to ubound(arrSubKeys) 'loop through the registry and find if the app is installed
if lcase(arrsubkeys(index)) = lcase(applicationname) then
AppInstalled = true
exit function
end if
next


AppInstalled = False


end function
 
function AppInstalled(ApplicationName) 'this checks the registry if the application is already installed returns true / false
Dim oReg,strkeypath, arrSubKeys, subkey, strcomputer, index


strComputer = "."
strKeyPath = "SOFTWARE\myAPPS"

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")

oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

On Error Resume Next

'*** Here is where the error hits if the key does not exist
'*** if it does exist everything is just fine!
for index = 0 to ubound(arrSubKeys) 'loop through the registry and find if the app is installed
if lcase(arrsubkeys(index)) = lcase(applicationname) then
AppInstalled = true
exit function
end if
next


if err.number <> 0 THEN
response.write &quot;error number: &quot; & err.number & &quot;<br>&quot;
response.write &quot;error descr.: &quot; & err.description& &quot;<br>&quot;
response.write &quot;error source: &quot; & err.source& &quot;<br>&quot;
err.Clear
end if



AppInstalled = False


end function -----------------------------------------------------------------
&quot;Whether you think that you can, or that you can't, you are usually right.&quot;
- Henry Ford (1863-1947)

mikewolf@tst-us.com
 
Try this so other errors wll not be hidden during debugging.
Dim J as Long
On Error Resume next
J = ubound(arrSubKeys)
if err.number <> 0 then J = -1
On Error goto 0
for index = 0 to ubound(arrSubKeys) 'loop through the registry and find if the app is installed
if lcase(arrsubkeys(index)) = lcase(applicationname) then
AppInstalled = true
exit function
end if
next
if J = -1 THEN
response.write &quot;error number: &quot; & err.number & &quot;<br>&quot;
response.write &quot;error descr.: &quot; & err.description& &quot;<br>&quot;
response.write &quot;error source: &quot; & err.source& &quot;<br>&quot;
err.Clear
end if

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Oops. You will not be able to use this

if J = -1 THEN
response.write &quot;error number: &quot; & err.number & &quot;<br>&quot;
response.write &quot;error descr.: &quot; & err.description& &quot;<br>&quot;
response.write &quot;error source: &quot; & err.source& &quot;<br>&quot;
err.Clear
end if

Forms/Controls Resizing/Tabbing Control
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top