|
-
Dec 3rd, 2009, 10:45 PM
#1
Thread Starter
Junior Member
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.....
-
Dec 3rd, 2009, 10:53 PM
#2
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:
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.
-
Dec 4th, 2009, 12:24 AM
#3
Thread Starter
Junior Member
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?
-
Dec 4th, 2009, 01:26 AM
#4
Re: OOP Classes - can't clear list of data saved
 Originally Posted by Ahshia
"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.
-
Dec 4th, 2009, 11:31 AM
#5
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|