Class calling itself

s_muhilan

Member
Joined
Oct 6, 2008
Messages
15
Programming Experience
3-5
Hi
I have a class as below in VB.NET. The issue is class calling itself. So vb.NET throwing Stock Overflow exception. But the same class is working fine in VB6 version of code in VB6.

How to resolve this issue?

public class Party

Private mvarpartyCode as string
Private mvarpartyName as string
Private mvarpartyType as string
Private mvarTransporter as Party

Public Sub New()
mvarPartycode= ""
mvarPartyName=""
mvarPartyType=""
mvarTransporter = New Party
End Sub

Public Property For PartyCode variable
Public Property for PartyName variable
Public Property for PartyType variable
Public property for Transporter variable

End Class
 
"mvarTransporter = New Party" is the offending code. If you remove that then it won't call itself, although I am not sure what you are trying to do.
 
but you have declared mvarTransporter as you class, so basically it is initiallising itself over and over again. Why would you want to do that?
 
Hi
As per rule, the class variables need to be intialize at the construter of the class and not in the declaration.
In the declaration, I did not intialize the variable. Even I intialize the variable the declaration itself, It is throwing stock overflow exception.
 
the fact that you have set variable mvarTransporter = New Party means that you are just causing a loop. I can't make it any clearer than that to be honest.
 
Back
Top