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

From Java to VBscript, could use some help.

Status
Not open for further replies.

99Chuck99

Programmer
Dec 11, 2003
67
US
How would I write this in VBscript. Thanks in advance.

<SCRIPT language=javascript event=onclick for=Command0>
try { if (MSODSC.CurrentSection == null)
MSODSC.DataPages(0).NewRecord();
else
MSODSC.CurrentSection.DataPage.NewRecord(); }
catch (e)
{ alert (e.description);}
</SCRIPT>
 
Have you tried this ?
On Error Resume Nexr
If IsNull(MSODSC.CurrentSection) Then
MSODSC.DataPages(0).NewRecord
Else
MSODSC.CurrentSection.DataPage.NewRecord
End If
If Err.Number Then
MsgBox Err.Description
Err.Clear
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
If VBScript's "On Error Resume Next" and repeated "If Err.Number <> 0" checks after every statement are too painful for you, you can have a poor man's try catch block as follows:

Code:
Class MSODSCNewRecord

Sub Class_Initialize()
   On Error Resume Next 
   If IsNull(MSODSC.CurrentSection) Then
      MSODSC.DataPages(0).NewRecord
   Else
      MSODSC.CurrentSection.DataPage.NewRecord
   End If
End Sub

Sub Class_Terminate()
   If Err.Number <> 0 Msgbox Err.Number & " " & Err.Source & Err.Description
End Sub

End Class

Dim BlockExecuter

Set BlockExecuter = New MSODSCNewRecord
Set BlockExecuter = Nothing
The difference here is that Class_Terminate() will always run, even for errors that are not normally trappable in VB. And it allows you to group error handling around statements which need it. It's not pretty, and probably should be used for special cases (well, maybe not, but I only recently learned about this method) so use it based on your own evaluation.

As I'm thinking about it now, if you put On Error Resume Next in your main code, and On Error GoTo 0 (the way to turn off Resume Next, don't ask why) in your class blocks, you may get nearly the same thing as a try/catch block. The problem with On Error Resume Next is that it really can end up trying each next statement all the way to the end, even if they don't make sense any more after an error.

[COLOR=black #d0d0d0]When I walk, I sometimes bump into things. I am closing my eyes so that the room will be empty.[/color]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top