2 troubleshooting within functions, Troubleshooting within functions, Appendix – Lenze VisiWinNet VisiWinNET Smart Benutzerhandbuch

Seite 257

Advertising
background image

Appendix

Scripts

Troubleshooting within functions

6

l

257

SHP−VWNS DE/EN 6.1

6.4.2

Troubleshooting within functions

Generally two types of errors are distinguished:

ƒ

Syntactic errors

ƒ

Runtime errors

Syntactic errors

Syntactic errors or missing variable declarations are already reported during the creation
of the project. Detecting and eliminating these errors is relatively uncomplicated for the
developer, since they are already reported during the development stage. Programming
errors in the project are shown during the creation (via the menu item Project

® Creation"

or the shortcut Ctrl+Shift+B)in the output window. If the project contains errors that are
detected by the compiler, it cannot be started.

Runtime errors

Runtime errors such as "Division By Zero" or missing object references are only detected
when the corresponding function is executed. The risk with this is that after
commissioning the code is supplied with data from the process which have not been
checked and result in an exception. Here it helps to use the Try−Catch condition with a
defined response for the case of error.

Private Sub ItemServer1_Change(ByVal sender As System.Object, _
ByVal e As VisiWinNET.DataAccess.ChangeEventArgs) Handles ItemServer1.Change
Try
Dim Divident As Double = _
VisiWinNET.Services.AppService.VWGet("Ch1.myDivident")

Dim Divisor As Double = e.Value

Dim Quotient As Double = Divident / Divisor

VisiWinNET.Services.AppService.VWSet("Ch1.myQuotient", Quotient)

Catch ex As Exception ’ooh, an error
If MsgBox("ItemServer1_Change results in: " _
& vbCrLf & ex.Message _
& vbCrLf & "Continue?", _
MsgBoxStyle.YesNo) = MsgBoxResult.No Then

’decision: End application
VisiWinNET.Forms.ProjectForms.StartForm.ShutdownProject()

End If
End Try
End Sub

Example: If a runtime error during the calculation "dividend/divisor= quotient" occurs, the
program run skips to the Catch condition. By means of a message box it is now decided
whether the application is to be closed.

Advertising