Sub viga1() On Error GoTo veahaldus a = 7 a = 5 / 0 MsgBox a Exit Sub veahaldus: MsgBox "Tekkis viga: " & Err.Description Resume Next End Sub Sub peaprogramm() viga1 MsgBox "programmi ots" End Sub Sub nimeteatamine(ByVal nimi As String) MsgBox nimi nimi = "nimetu" MsgBox nimi End Sub Sub nimetest1() Dim eesnimi As String eesnimi = "Juku" nimeteatamine eesnimi MsgBox "Pärast on nimi " & eesnimi End Sub Sub vaheta(ByRef a As Integer, ByRef b As Integer) Dim c As Integer c = a a = b b = c End Sub Sub vahetustest() Dim k As Integer, l As Integer k = 3 l = 5 MsgBox k & " " & l vaheta k, l MsgBox k & " " & l End Sub Sub inimtest1() Dim poiss1 As inimene Set poiss1 = New inimene poiss1.eesnimi = "Juku" poiss1.synniaasta = 1988 MsgBox poiss1.eesnimi End Sub Sub inimtest2() Dim lapsed(5) As inimene Set lapsed(0) = New inimene lapsed(0).eesnimi = "Kati" Set lapsed(3) = New inimene lapsed(3).eesnimi = "Mati" 'MsgBox lapsed(0).eesnimi 'MsgBox lapsed(0) Is Nothing inimloetelu lapsed End Sub Sub inimloetelu(ByRef m() As inimene) For i = LBound(m) To UBound(m) If Not m(i) Is Nothing Then MsgBox m(i).eesnimi End If Next i End Sub Sub inimtest3() Dim poiss1 As inimene Dim mees1 As New inimene Dim taat1 As New inimene Dim memm1 As New inimene Dim naine1 As New inimene Dim abi As inimene Set poiss1 = New inimene poiss1.eesnimi = "Juku" mees1.eesnimi = "Madis" naine1.eesnimi = "Malle" Set poiss1.isa = mees1 Set poiss1.ema = naine1 taat1.eesnimi = "Johannes" memm1.eesnimi = "Maali" Set mees1.ema = memm1 Set poiss1.isa.isa = taat1 Set taat1.isa = New inimene taat1.isa.eesnimi = "Jakob" Set abi = poiss1 'Do ' MsgBox abi.eesnimi ' Set abi = abi.isa 'Loop Until abi Is Nothing trykiSugupuu poiss1 'MsgBox poiss1.isa.ema.eesnimi End Sub Sub trykiSugupuu(x As inimene) If x Is Nothing Then Exit Sub MsgBox x.eesnimi trykiSugupuu x.isa trykiSugupuu x.ema End Sub Sub inimtest4() Dim poiss1 As New inimene poiss1.eesnimi = "Juku" poiss1.synniaasta = 1988 MsgBox poiss1.vanus & " " & poiss1.tutvustus End Sub Sub inimtest5() Dim poiss1 As New inimene poiss1.synniaeg = 2988 MsgBox poiss1.synniaeg End Sub Sub inimtest6() Dim poiss1 As New inimene Do sa = InputBox("Palun sünniaasta") Loop Until sa < 2002 poiss1.synniaeg = sa MsgBox poiss1.synniaeg End Sub Sub inimtest7() Dim poiss1 As New inimene viga = False On Error GoTo veahaldur Do sa = InputBox("Palun sünniaasta") poiss1.synniaeg = sa Loop Until Not viga MsgBox poiss1.synniaeg Exit Sub veahaldur: MsgBox "Tekkis viga moodulis: " & Err.Source & ": " & Err.Description viga = True Resume Next End Sub '--- klass Public eesnimi As String Public synniaasta As Integer Public isa As inimene Public ema As inimene Public Function vanus() As Integer vanus = Year(Now) - synniaasta End Function Public Property Get tutvustus() As String tutvustus = eesnimi & ", sündinud " & synniaasta End Property Public Property Let synniaeg(uusaeg As Integer) If uusaeg > Year(Now) Then Err.Raise vbObjectError + 1, "Inimene", "Liiga suur sünniaasta" synniaasta = -1 Else synniaasta = uusaeg End If End Property Public Property Get synniaeg() As Integer synniaeg = synniaasta End Property