Forum Discussion

rjamison's avatar
rjamison
Occasional Contributor
14 years ago

Problems with Error Trapping the 'Set' command

I have a web page that changes the locations of items using CSS and DIVs.  This is conditional, so it makes it difficult to know which panel index to do the 'Set' on.  I tried to trap the error with the following code:

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



  Err.Clear


  On Error Resume Next    


  Set OrderNumtxt = panel.Panel(1).Panel(0).Panel(0).Panel(1).Panel(0).Panel(1).Panel(0) _


                         .Panel(1).Panel(1).Panel(0).Panel("HN_OR_OrderSummary") _


                         .Panel("orderSummaryZone").Panel(0).Panel(1).Panel(0)  


  If Err.Number <> 0 Then


    x = 1


  Else


    x = 0


  End If


  


  msgbox(x)


  '   x shows up as 0 here when the 'Set' in the 3rd line fails.





  if x = 0 then


                         


    Set OrderNumtxt = panel.Panel(1).Panel(0).Panel(0).Panel(1).Panel(0).Panel(1).Panel(0) _


                           .Panel(2).Panel(1).Panel(0).Panel("HN_OR_OrderSummary") _


                           .Panel("orderSummaryZone").Panel(0).Panel(1).Panel(0)






  end if                         


  '  This one 'Set's correctly and I can now assign a value to OrderNum



  OrderNum = mid(OrderNumtxt.innerText, 15, 13)

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



My test script reports errors on the first 'Set' attempt, but I need to suppress the error count.  Can anyone help out on this?



Thanks.

1 Reply

  • Hi,



    On Error Resume Next allows you to catch VBScript exceptions. If you get errors like 'object not found' or similar, these are not exceptions and they don't affect error count. Such errors are not related to VBScript's engine, they are just 'logical' errors TC posts to the log.



    To check whether your script was able to obtain the target object correctly, wait for this object and check the result's Exists property value.