Re: Class, property and list
Your issue has to do with the scope of your object. When you declare an object inside a function, it will only exist for that function. Declare it for the class, and it will exist for the whole class. I would suggest something like....
Code:
Public Class Form1
Private bakjesList As New List(Of Class_BaanAsBakje)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bakjesList.Clear()
ListBox1.Items.Clear()
For i = 0 To 100
Dim bakje As Class_BaanAsBakje = New Class_BaanAsBakje(i, i + 1, i + 3)
bakjesList.Add(bakje)
ListBox1.Items.Add(bakje.XlineBakje & " " & bakje.YlineBakje & " " & bakje.Waarde)
Next
Dim test As Integer
test = bakjesList.Count()
bakjesList.RemoveAt(5)
For i = 0 To bakjesList.Count - 1
ListBox1.Items.Add(bakjesList(i).XlineBakje & " " & bakjesList(i).YlineBakje & " " & bakjesList(i).Waarde)
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim test2 As Integer
test2 = bakjesList.Count()
End Sub
End Class
Re: Class, property and list
True that was the solution as slowly i start to understand that public is not as public as in VB6......
Thanx for showing your experience, as its clearly a noob error, but as stated before it feels so different to vb6, the learning curve is much different as well....
But I keep continuing..... :)
Re: Class, property and list
It is different, but you will find that it is also easier in many ways, and also in many ways more powerful.
Keep plugging away and come back here when you need help :)
Re: Class, property and list
Quote:
Originally Posted by
Joska Paszli
True that was the solution as slowly i start to understand that public is not as public as in VB6......
Thanx for showing your experience, as its clearly a noob error, but as stated before it feels so different to vb6, the learning curve is much different as well....
But I keep continuing..... :)
Actually if you dim a variable inside a function using VB6 you will get an error if you try to reference that variable in a different function. The variable is only known to the function where it is defined and must be defined outside the functions to be visible to the entire form, module or class and must be Public to be seen outside the form, module or class this is the same in VB6 and VB.Net. While there are some differences they are very much the same as well.
Re: Class, property and list
This is issue is at the very heart of OOP. You must understand scope properly in order to use it properly. I'd suggest you get a book on that, or google it :
https://www.google.co.za/search?q=oo...ient=firefox-a
Re: Class, property and list
true i have 2 books now but still i find it is not getting enough weight in books or examples.... also te most common examples are for such a small, simple example (ofcourse) but a step by step explanation what u can do with it in combination with each other could get more attention.... also the flexibility and power makes it hard but now after 2 weeks/100 hours i see more and more light... a steep learning curve.... i cant say i miss vb6 but i still miss the speed in which i can programm.... it really takes much time
Re: Class, property and list
Once you have a handle on the VB.Net classes and usage you may find that you can write programs faster in VB.Net and that you can with a little planning reuse a lot of your code.
I think the thing that stumped me the most was the transition from ADO Connections and Recordsets to ADO.Net datasets, datatables and datareaders.