Results 1 to 5 of 5

Thread: OOP Classes - can't clear list of data saved

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Question OOP Classes - can't clear list of data saved

    Hi, bare with me here

    ok I posted on here a while back, like month to 2 months ago about creating an array of data (user inputed data). But was suggested to go the class route. After weeks of lengthly reading came up with a list collection class.


    '*********************Device Class*******************
    Public Class Device

    Private _PosList As List(of Position)

    Public Sub New()
    _PosList = New List(of Position)
    End Sub

    Public Property PositionList() As List(Of Position)
    Get
    Return _PosList
    End Get
    Set(ByVal value As List(Of Position))
    _PosList = value
    End Set
    End Property

    Public Sub AddPosition(ByVal aPos As Position)
    _PosList.Add(aPos)
    End Sub
    End Class

    '*********** This is the position class******************

    Public Class Position

    Private _DataInfo As String

    Public Sub New(ByVal info As String)
    _DataInfo = info
    End Sub

    Public Property DataInformation() As String
    Get
    Return _DataInfo
    End Get
    Set(ByVal value As String)
    _DataInfo = value
    End Set
    End Property

    End Class

    '******* Main Form Class *******************************

    'In here I then created my objects from the class

    Public Class Main

    Private DeviceList as New List(of Device)
    Private Device1 as New Device()

    'Module that creates the objects *******
    Private sub MyDevices()

    DeviceList.Add(Device1)
    Device1.AddPosition(New Position(txtYXD1B1.Text))
    End Sub

    Private Sub Button_Click(....)
    Me.MyDevices()

    SomeTextBox.Text = (DeviceList(0).PositionList(0).DataInformation.ToString)

    ******************************************************

    That is pretty much the short version of it. The issue is, when I first enter my data in and click the button. The information is displayed correctly everything is great, but if I decide to change the data and reclick on the button again, the displayed data doesnt update itself. For some reason the data in the object wont clear or reset. I have tried DeviceList.Clear() in my subroutine of MyDevices() before adding my devices and in the button click event before calling MyDevices(). Nothing seems to do it. I have even added a

    Public Sub RemovePosition(ByVal aPos As Position)
    _PosList.Remove(aPos)
    End Sub

    and then remove them manually but the same issue occures.

    Help.....

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: OOP Classes - can't clear list of data saved

    If we were to "bare" with you we'd all have to take out clothes off together. Nobody wants that. We can "bear" with you though.

    With regards to posting code, please use the Code and VBCode buttons provided to wrap your code snippets in tags that will format it and make it much easier to read.

    As for the question, get rid of this line:
    vb.net Code:
    1. Private Device1 as New Device()
    Now, each time you want to add a new Device to the collection, create a new Device and add it. Don't keep adding the same one Device object over and over again.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: OOP Classes - can't clear list of data saved

    "Now, each time you want to add a new Device to the collection, create a new Device and add it. Don't keep adding the same one Device object over and over again. " Quote...

    I kind of see what you mean. But what do you mean just create a new device.

    Exmaple:

    private sub button_click(...)
    dim device1 as new device()
    end sub

    Like that so that its created when the button is clicked?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: OOP Classes - can't clear list of data saved

    Quote Originally Posted by Ahshia View Post
    "Now, each time you want to add a new Device to the collection, create a new Device and add it. Don't keep adding the same one Device object over and over again. " Quote...

    I kind of see what you mean. But what do you mean just create a new device.

    Exmaple:

    private sub button_click(...)
    dim device1 as new device()
    end sub

    Like that so that its created when the button is clicked?
    Exactly.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Nov 2009
    Posts
    16

    Re: OOP Classes - can't clear list of data saved

    ok, let me give that a shot, thanks

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