Kod aplikacji
Private Sub btnOblicz_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnOblicz.Click Dim sngPoleSera, sngPole1, sngPole2, sngPole3 As Single
Dim sngPole As Single
Try
sngPoleSera = pole(txtR.Text) ' wywołanie własnej funkcj pole sngPole1 = pole(txtR1.Text) ' wywołanie własnej funkcj pole sngPole2 = pole(txtR2.Text) ' wywołanie własnej funkcj pole sngPole3 = pole(txtR3.Text) ' wywołanie własnej funkcj pole
sngPole = sngPoleSera - sngPole1 - sngPole2 - sngPole3 txtPole.Text = sngPole.ToString
If sngPole <= 0 Then
Err.Raise(9000, "Błędne dane", _
"Pole musi być większe od zera") End If
Catch ex As Exception
MsgBox(Err.Description, MsgBoxStyle.Exclamation, Err.Source) End Try
End Sub
Private Function pole(ByVal strPromien As String) ' Własna funkcja testujaca poprawność danych,
' generująca odpowiednie błędy o właściwych numerach i komentarze ' oraz (co najważniejsze) wyliczająca pole.
Dim sngR As Single pole = 0
Try
sngR = CSng(strPromien) If sngR > 0 Then
pole = Math.PI * sngR * sngR Else
Err.Raise(9001) End If
Catch ex As Exception
If Err.Number = 9001 Then
Err.Raise(9001, "Funcja Pole", "Promień " & _ strPromien.ToString & _
" musi być większy od zera") Else
Err.Raise(9013, "Funcja Pole", strPromien.ToString & _ " nie jest liczbą")
End If End Try End Function
Private Sub btnKoniec_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnKoniec.Click End
End Sub