CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 1999
    Posts
    29

    Help: Life of Controls in DataSpaces

    If I create a class in a dataspace with a private variable called Count then every time I run a function in this class the private variable is set to zero.
    This is provided I create the object via a DataSpace

    ie X.Y
    Private Count as Long

    Public Function Add(Num as Long) as Long
    Count = Count + Num
    Add = Count
    end function

    ---

    If I use the dataspace.createobject to a global object, then every time I call Add(Num) the value returned by Add is Num not the totaled amount.

    Any ideas how to make this object stay persistent?

    Thanks

    DS


  2. #2
    Join Date
    Feb 2000
    Location
    Indiana
    Posts
    308

    Re: Help: Life of Controls in DataSpaces

    Use a static variable in your function.

    public Function Add(Num as Long) as Long
    static Count as Long
    Count = Count + Num
    Add = Count
    End Function





Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured