no runtime errors but also nothing on the screen when useing the debugger

timshalk

New member
Joined
Feb 25, 2011
Messages
1
Programming Experience
Beginner
hello,

I made a console application that show when someone get 100 euro from a bankaccount his bankaccount is in negatief with 100. when I look at my code and to the errors list, nothing is wrong. no runtime errors but when I use the debugger nothing is on the sreen. anybody know what I have forgot?


Class Bankrekening
Public Event NegatiefSaldoBekomen As EventHandler(Of NegatiefSaldoBekomenEventargs)
Public Property Nummer As String
Protected _Saldo As Decimal
Public Sub Stort(ByVal bedrag As Decimal)
_Saldo += bedrag
End Sub
Public Sub HaalAf(ByVal bedrag As Decimal)
_Saldo -= bedrag
End Sub
Public ReadOnly Property Saldo As Decimal
Get
Saldo = _Saldo
End Get
End Property
End Class
Class NegatiefSaldoBekomenEventArgs : Inherits EventArgs
Public Property NegatiefSaldo As Decimal
End Class
Module BankrekeningClient
Sub Main()
Dim bankrekening1 As New Bankrekening With {.Nummer = "0001"}
Dim bankrekening2 As New Bankrekening With {.Nummer = "0002"}

AddHandler bankrekening1.AddressOf, Bankrekening_NegatiefSaldoBekomen()
AddHandler bankrekening2.AddressOf, Bankrekening_NegatiefSaldoBekomen()

bankrekening1.HaalAf(100)
' eventafhandling : Bankaccount with number 0001 have got a negatief saldo off 100 .

bankrekening2.HaalAf(200)
' eventafhandling : Bankaccount with number 0001 have got a negatief saldo off 100 .

Console.ReadLine()
End Sub
Sub bankrekening1_NegatiefSaldoBekomen(ByVal sender As Bankrekening,
ByVal e As NegatiefSaldoBekomenEventArgs)
Console.WriteLine("Bankrekening with number " & sender.Number &
" have got a negatief saldo off " & e.NegatiefSaldo)
End Sub

Private Function Bankrekening_NegatiefSaldoBekomen() As Object
Throw New NotImplementedException
End Function

End Module

line (*) makes that the eventafhandeling were the message "Bankrekening met nummmer 0001 a negatief saldo have become off -100." is written on console.
line (**) makes that the eventafhandeling were the message "Bankrekening met nummmer 0002 a negatief saldo have become off -200." is written on console.


greets
 
[edit] just noticed the date on this one.. a few months ago.. probably already solved by now? o well.. hope it helps someone

:confused: Does this really compile? Did you check your syntax? If this is all of the related code to make this main method work then it looks like you have some syntax errors?.. (i think?)

I modified your code so i can compile it and get something similar to what you wanted
"Bankrekening met nummmer 0001 a negatief saldo have become off -100."
"Bankrekening met nummmer 0002 a negatief saldo have become off -200." is written on console.

the code below outputs:
VB.NET:
Bankrekening with number 0001 have got a negatief saldo off -100
Bankrekening with number 0002 have got a negatief saldo off -200


i added a RaiseEvent, and also fixed the sytnax errors.

code:
Class Bankrekening
    Public Event NegatiefSaldoBekomen As EventHandler(Of NegatiefSaldoBekomenEventargs)
    Public Property Number As String 'you spelled number wrong, you had 'Public Property Nummer As String
    Protected _Saldo As Decimal
    Public Sub Stort(ByVal bedrag As Decimal)
        _Saldo += bedrag

        RaiseEvent NegatiefSaldoBekomen(Me, New NegatiefSaldoBekomenEventArgs With {.NegatiefSaldo = Saldo}) 'added this
    End Sub
    Public Sub HaalAf(ByVal bedrag As Decimal)
        _Saldo -= bedrag

        RaiseEvent NegatiefSaldoBekomen(Me, New NegatiefSaldoBekomenEventArgs With {.NegatiefSaldo = Saldo}) ' added this
    End Sub
    Public ReadOnly Property Saldo As Decimal
        Get
            Saldo = _Saldo
        End Get
    End Property
End Class

Class NegatiefSaldoBekomenEventArgs : Inherits EventArgs
    Public Property NegatiefSaldo As Decimal
End Class

Module BankrekeningClient
    Sub Main()
        Dim bankrekening1 As New Bankrekening With {.Number = "0001"}
        Dim bankrekening2 As New Bankrekening With {.Number = "0002"}

        AddHandler bankrekening1.NegatiefSaldoBekomen, AddressOf Bankrekening_NegatiefSaldoBekomen 'modified this, you had 'AddHandler bankrekening1.AddressOf, Bankrekening_NegatiefSaldoBekomen()
        AddHandler bankrekening2.NegatiefSaldoBekomen, AddressOf Bankrekening_NegatiefSaldoBekomen 'modified this, you had 'AddHandler bankrekening2.AddressOf, Bankrekening_NegatiefSaldoBekomen()

        bankrekening1.HaalAf(100)
        ' eventafhandling : Bankaccount with number 0001 have got a negatief saldo off 100 .

        bankrekening2.HaalAf(200)
        ' eventafhandling : Bankaccount with number 0001 have got a negatief saldo off 100 .

        Console.ReadLine()
    End Sub

    'renamed this, it was 'bankrekening1_NegatiefSaldoBekomen
    Sub Bankrekening_NegatiefSaldoBekomen(ByVal sender As Object, ByVal e As NegatiefSaldoBekomenEventArgs) 'modified this to match sig you providied above, you had 'ByVal sender As Bankrekening
        Console.WriteLine("Bankrekening with number " & DirectCast(sender, Bankrekening).Number & " have got a negatief saldo off " & e.NegatiefSaldo)'added cast
    End Sub

    'deleted your other method... i think it was a duplicate created by VS a empty stub..
End Module


hope that helps?
 
Last edited:
Back
Top