+ Reply to Thread
Results 1 to 6 of 6

Thread: VB.NEt Class calling itself

  1. #1
    s_muhilan is offline VB.NET Forum Newbie s_muhilan is on a distinguished programming path ahead
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Oct 2008
    Posts
    14
    Reputation
    25

    Default VB.NEt Class calling itself

    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

  2. #2
    r3plica's Avatar
    r3plica is offline VB.NET Forum Enthusiast r3plica done a little coding in his/her time r3plica done a little coding in his/her time r3plica done a little coding in his/her time
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2010
    Age
    30
    Posts
    81
    Reputation
    63

    Default

    "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.
    If I solve your issue or you are happy with my response, please provide me with reputation by clicking the reputation link at the top right of my posts - thanks

  3. #3
    s_muhilan is offline VB.NET Forum Newbie s_muhilan is on a distinguished programming path ahead
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Oct 2008
    Posts
    14
    Reputation
    25

    Default

    Hi
    I want to intilize the mvarTransporter variable in the constructer of the class.

  4. #4
    r3plica's Avatar
    r3plica is offline VB.NET Forum Enthusiast r3plica done a little coding in his/her time r3plica done a little coding in his/her time r3plica done a little coding in his/her time
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2010
    Age
    30
    Posts
    81
    Reputation
    63

    Default

    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?
    If I solve your issue or you are happy with my response, please provide me with reputation by clicking the reputation link at the top right of my posts - thanks

  5. #5
    s_muhilan is offline VB.NET Forum Newbie s_muhilan is on a distinguished programming path ahead
    .NET Framework
    .NET 3.0 (VS 2005/2008)
    Join Date
    Oct 2008
    Posts
    14
    Reputation
    25

    Default

    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.

  6. #6
    r3plica's Avatar
    r3plica is offline VB.NET Forum Enthusiast r3plica done a little coding in his/her time r3plica done a little coding in his/her time r3plica done a little coding in his/her time
    .NET Framework
    .NET 3.5
    Join Date
    Mar 2010
    Age
    30
    Posts
    81
    Reputation
    63

    Default

    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.
    If I solve your issue or you are happy with my response, please provide me with reputation by clicking the reputation link at the top right of my posts - thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts