Declare and and define Property in VB - vb.net

I have two Class and I want to save my data into arrays form text box like this:
Students.Name(txtID.Text-1).MathMark = txtMark.Text
but I get error: Object reference not set to an instance of an object
my code is:
Dim StudentsNumber as Integer = txtstdnum.Text
Dim Students as New StudentsInf(StudentsNumber)
Students.Name(txtID.Text-1).MathMark = txtMark.Text
Public Class StudentsInf
Private mName() As String
Sub New(ByVal StudentNumbers As Integer)
ReDim mName(StudentNumbers-1)
End Sub
Public Property Name(ByVal Index As Integer) As LessonsMark
Get
Return mName(Index)
End Get
Set(ByVal Value As LessonsMark)
mName(Index) = Value
End Set
End Property
End Class
Public Class LessonsMark
Private mMathMark() As Object
Public Property MathMark() As Object
Get
Return mMathMark
End Get
Set(ByVal Value As Object)
mMathMark = Value
End Set
End Property
End Class

This:
Private mName() As String
needs to be:
Private mName() As LessonsMark
then you have to create the objects in your constructor, something like:
Sub New(ByVal StudentNumbers As Integer)
ReDim mName(StudentNumbers - 1)
For i As Integer = 0 To StudentNumbers - 1
mName(i) = New LessonsMark()
Next
End Sub
then it looks like your LessonsMark class is declaring an array of objects when it looks like it should be just a string property:
Public Class LessonsMark
Private mMathMark As String
Public Property MathMark As String
Get
Return mMathMark
End Get
Set(ByVal Value As String)
mMathMark = Value
End Set
End Property
End Class

Related

How to make Arrays of Object in VB.net?

I am unable to debug this.
Is my procedure of array-making wrong?
The error it shows is
System.NullReferenceException :'Object reference not set to an instance of an object'
Module Module1
Class Toy
Private Name, ID As String
Private Price As Single
Private MinimumAge As Integer
Dim Count As Integer
Public Sub New()
End Sub
Public Sub SetName(ByVal N As String)
Name = N
End Sub
Public Sub SetID(ByVal I As String)
'VALIDATION CHECK FOR ID !
While Len(I) < 4
Console.WriteLine("Kindly Enter the ID with Lenght of Max 4 Characters")
End While
ID = I
End Sub
Public Sub SetPrice(ByVal SP As Single)
Price = SP
End Sub
Public Sub SetUserAge(ByVal SM As Integer)
'VALIDATION CHECK FOR AGE
While SM < 0 Or SM < 18
Console.WriteLine("Minimum age is 18")
End While
MinimumAge = SM
End Sub
Public Function GetName()
Return Name(Count)
End Function
Public Function GetID()
Return ID
End Function
Public Function GetPrice()
Return Price
End Function
Public Function GetAge()
Return MinimumAge
End Function
End Class
Class ComputerGame
Inherits Toy
Private Category, Consol As String
Public Sub New()
End Sub
Public Sub SetConsole(ByVal C As String)
While C <> "PS4" Or C <> "XBOX"
Console.WriteLine("Invalid console entered")
End While
Consol = C
End Sub
Public Sub SetCategory(ByVal SC As String)
Category = SC
End Sub
Public Function GetConsole()
Return Consol
End Function
Public Function GetCategory()
Return Category
End Function
End Class
Class Vehicle
Inherits Toy
Private Type As String
Private Length, Height, Weight As Single
Public Sub New()
End Sub
Public Sub SetType(ByVal TY As String)
While TY <> "Car" Or TY <> "Bus" Or TY <> "Truck"
Console.WriteLine("vehicle is not in list !")
End While
Type = TY
End Sub
Public Sub SetLength(ByVal SL As Single)
Length = SL
End Sub
Public Sub SetHeight(ByVal SH As Single)
Height = SH
End Sub
Public Sub SetWeight(ByVal SW As Integer)
Weight = SW
End Sub
Public Function GetT()
Return Type
End Function
Public Function GetLength()
Return Length
End Function
Public Function GetHeight()
Return Height
End Function
Public Function GetWeight()
Return Weight
End Function
End Class
Sub Main()
Dim ThisGame(6) As Toy
ThisGame(6) = New Toy
ThisGame(1).SetID("23456a")
ThisGame(2).SetID("236789b")
Console.WriteLine(ThisGame(1).GetID)
Console.ReadKey()
End Sub
End Module
This is what your Toy class should look like using the long method of Properties. Notice that you have Public Properties and a private field to store the values (sometimes called a backer field) Each Property has a Get and a Set procedure where you can add your validation code.
Public Class Toy
Private _Name As String
Public Property Name As String
Get
Return _Name
End Get
Set(value As String)
_Name = value
End Set
End Property
Private _ID As String
Public Property ID As String
Get
Return _ID
End Get
Set(value As String)
If value.Length < 4 Then
Console.WriteLine("Kindly Enter the ID with Lenght of Max 4 Characters")
Exit Property
End If
_ID = value
End Set
End Property
Private _Price As Single
Public Property Price As Single
Get
Return _Price
End Get
Set(value As Single)
_Price = value
End Set
End Property
Private _MinimumAge As Integer
Public Property MinimumAge As Integer
Get
Return _MinimumAge
End Get
Set(value As Integer)
If value < 0 Or value < 18 Then
Console.WriteLine("Minimum age is 18")
Exit Property
End If
_MinimumAge = value
End Set
End Property
Private _Count As Integer
Public Property Count As Integer
Get
Return _Count
End Get
Set(value As Integer)
_Count = value
End Set
End Property
End Class
Current versions have Automatic Properties where the compiler provides the getter, setter, and backer fields. Notice that you can still write your own Get and Set where you need to add code.
Public Class Toy
Public Property Name As String
Public Property Price As Single
Public Property Count As Integer
Private _ID As String
Public Property ID As String
Get
Return _ID
End Get
Set(value As String)
If value.Length < 4 Then
Console.WriteLine("Kindly Enter the ID with Lenght of Max 4 Characters")
Exit Property
End If
_ID = value
End Set
End Property
Private _MinimumAge As Integer
Public Property MinimumAge As Integer
Get
Return _MinimumAge
End Get
Set(value As Integer)
If value < 0 Or value < 18 Then
Console.WriteLine("Minimum age is 18")
Exit Property
End If
_MinimumAge = value
End Set
End Property
End Class
Please read the in line comments in regards to your array.
Sub Main()
Dim ThisGame(6) As Toy 'You are defining and array with 7 elements of Toy
'Each element is Nothing at this point and you will get a null exception error if you
'try to access an element.
ThisGame(6) = New Toy 'Here you have created an instance of your class for the 7th element
'The other six elements are still nothing so the next 3 lines will get
'NullReferenceException: 'Object reference not set to an instance of an object.'
'ThisGame(1).ID = "23456a"
'ThisGame(2).ID = "236789b"
ThisGame(1) = New Toy
ThisGame(1).ID = "23456a"
ThisGame(2) = New Toy
ThisGame(2).ID = "236789b"
'Remember the first element in you array is ThisGame(0)
Console.WriteLine(ThisGame(1).ID)
Console.ReadKey()
End Sub

Getting a property from the instantiator class

Not an experienced programmer, so probably not a hard question.
Developing a small application in VB.net in WPF.
I made 3 classes, EngineeringObject<==Inherits==PartOfInstallation<==Inherits==SensorActor
In the class SensorActor I'm trying to get a property of PartOfInstallation with the function MyBase.Name. But this goes directly to EngineeringObject. How do I solve this?
Public Class EngineeringObject
''Private declarations, alleen objecten die erven kunnen hieraan, of dmv van getters en setters
'Name of part
Private sName As String = "Naam"
'81346 Id's
Private sSystemId As String = "Functie" 'VentilationSystem, Pumpsystem
Private sLocationId As String = "Locatie" 'Room 0.0
Private sObjectId As String = "Object" 'Fan, Pump
'General
Private sPartNumber As String
Private sLinkToDatasheet As String
'Property's
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property SystemId() As String
Get
Return sSystemId
End Get
Set(ByVal value As String)
sSystemId = value
End Set
End Property
Public Property PartNumber() As String
Get
Return sPartNumber
End Get
Set(ByVal value As String)
sPartNumber = value
End Set
End Property
Public Property LinkToDatasheet() As String
Get
Return sLinkToDatasheet
End Get
Set(ByVal value As String)
sLinkToDatasheet = value
End Set
End Property
Public Sub New()
End Sub
End Class
Public Class PartOfInstallation
Inherits EngineeringObject
'src: https://stackoverflow.com/questions/21308881/parent-creating-child-object
'src: https://stackoverflow.com/questions/16244548/how-to-create-a-list-of-parent-objects-where-each-parent-can-have-a-list-of-chil
Private lSensorActor As New List(Of SensorActor)
Public Function GetSensorActor()
Return Me.lSensorActor
End Function
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor)
End Sub
End Class
Public Class SensorActor
Inherits PartOfInstallation
Dim sMyPartOfInstallation As String
Public Property MyPartOfInstallation As String
Get
Return sMyPartOfInstallation
End Get
Set(value As String)
sMyPartOfInstallation = MyBase.Name
End Set
End Property
End Class
If I understand it correctly, based on your comments, you want every SensorActor instantiated within a PartOfInstallation instance to get the same name as that instance.
If so, then just add a second constructor to your SensorActor class allowing you to pass a name for it as well:
Public Class SensorActor
Inherits PartOfInstallation
...your code...
Public Sub New() 'Empty constructor, for if/when you don't want to set the name immediately.
End Sub
Public Sub New(ByVal Name As String)
Me.Name = Name
End Sub
End Class
Now in your PartOfInstallation class you can do:
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me.Name)) 'Here, "Me" refers to the current PartOfInstallation instance.
End Sub
Alternatively you can make the SensorActor constructor take a PartOfInstallation instance instead, allowing you to copy any properties you like:
Public Class SensorActor
Inherits PartOfInstallation
...your code...
Public Sub New()
End Sub
Public Sub New(ByVal BasedOnPOI As PartOfInstallation)
Me.Name = BasedOnPOI.Name
End Sub
End Class
Thus making the code in the PartOfInstallation class:
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me))
End Sub
Read more about constructors: Object Lifetime: How Objects Are Created and Destroyed (Visual Basic) | Microsoft Docs
The result below, if there's room for improvement... always welcome.
SensorActor
Public Class SensorActor
Inherits PartOfInstallation
Dim sTemp As String
Public Overloads Property SystemId() As String
Get
Return Me.sSystemId
End Get
Set(ByVal value As String)
Me.sSystemId = sTemp + "." + value
End Set
End Property
Public Sub New(ByVal BasedOnPOI As PartOfInstallation)
sTemp = BasedOnPOI.SystemId
End Sub
End Class
PartOfInstallation
Public Class PartOfInstallation
Inherits EngineeringObject
'src: https://stackoverflow.com/questions/21308881/parent-creating-child-object
'src: https://stackoverflow.com/questions/16244548/how-to-create-a-list-of-parent-objects-where-each-parent-can-have-a-list-of-chil
Private lSensorActor As New List(Of SensorActor)
Public Function GetSensorActor()
Return Me.lSensorActor
End Function
Public Sub CreateSensorActor()
lSensorActor.Add(New SensorActor(Me))
End Sub
End Class
EngineeringObject
Public Class EngineeringObject
''Private declarations, alleen objecten die erven kunnen hieraan, of dmv van getters en setters
'Name of part
Private sName As String = "Naam"
'81346 Id's
Friend sSystemId As String = "Functie" 'VentilationSystem, Pumpsystem
Private sLocationId As String = "Locatie" 'Room 0.0
Private sObjectId As String = "Object" 'Fan, Pump
'General
Private sPartNumber As String
Private sLinkToDatasheet As String
'Property's
Public Property Name() As String
Get
Return sName
End Get
Set(ByVal value As String)
sName = value
End Set
End Property
Public Property SystemId() As String
Get
Return sSystemId
End Get
Set(ByVal value As String)
sSystemId = "=" + value
End Set
End Property
Public Property PartNumber() As String
Get
Return sPartNumber
End Get
Set(ByVal value As String)
sPartNumber = value
End Set
End Property
Public Property LinkToDatasheet() As String
Get
Return sLinkToDatasheet
End Get
Set(ByVal value As String)
sLinkToDatasheet = value
End Set
End Property
Public Sub New()
End Sub
End Class

How to get all json values with newtonsoft

I'm having a hard time getting through all the JSON values ​​of a string, can anyone help me?
I'm only getting a single value, where am I going wrong?
My codes
Dim address As String = "http://wsloterias.azurewebsites.net/api/sorteio/getresultado/1"
Dim client As WebClient = New WebClient()
Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
Dim json = (reader.ReadToEnd)
Dim objs As RootObject = JsonConvert.DeserializeObject(Of RootObject)(json)
Dim objsSorteio As Sorteio = JsonConvert.DeserializeObject(Of Sorteio)(json)
For Each nums In objsSorteio.Premios
MsgBox(nums.ToString)
Next
Classes
Public Class Premio
Public Property Faixa() As String
Get
Return m_Faixa
End Get
Set(value As String)
m_Faixa = Value
End Set
End Property
Private m_Faixa As String
Public Property NumeroGanhadores() As Integer
Get
Return m_NumeroGanhadores
End Get
Set(value As Integer)
m_NumeroGanhadores = Value
End Set
End Property
Private m_NumeroGanhadores As Integer
Public Property Valor() As Double
Get
Return m_Valor
End Get
Set(value As Double)
m_Valor = Value
End Set
End Property
Private m_Valor As Double
End Class
Public Class Sorteio
Public Property NumSorteio() As Integer
Get
Return m_NumSorteio
End Get
Set(value As Integer)
m_NumSorteio = Value
End Set
End Property
Private m_NumSorteio As Integer
Public Property Numeros() As List(Of Integer)
Get
Return m_Numeros
End Get
Set(value As List(Of Integer))
m_Numeros = Value
End Set
End Property
Private m_Numeros As List(Of Integer)
Public Property Premios() As List(Of Premio)
Get
Return m_Premios
End Get
Set(value As List(Of Premio))
m_Premios = Value
End Set
End Property
Private m_Premios As List(Of Premio)
Public Property Ganhadores() As List(Of Object)
Get
Return m_Ganhadores
End Get
Set(value As List(Of Object))
m_Ganhadores = Value
End Set
End Property
Private m_Ganhadores As List(Of Object)
End Class
Public Class RootObject
Public Property NumeroConcurso() As Integer
Get
Return m_NumeroConcurso
End Get
Set(value As Integer)
m_NumeroConcurso = Value
End Set
End Property
Private m_NumeroConcurso As Integer
Public Property Acumulou() As Boolean
Get
Return m_Acumulou
End Get
Set(value As Boolean)
m_Acumulou = Value
End Set
End Property
Private m_Acumulou As Boolean
Public Property EstimativaPremio() As Double
Get
Return m_EstimativaPremio
End Get
Set(value As Double)
m_EstimativaPremio = Value
End Set
End Property
Private m_EstimativaPremio As Double
Public Property ValorAcumulado() As Double
Get
Return m_ValorAcumulado
End Get
Set(value As Double)
m_ValorAcumulado = Value
End Set
End Property
Private m_ValorAcumulado As Double
Public Property Data() As String
Get
Return m_Data
End Get
Set(value As String)
m_Data = Value
End Set
End Property
Private m_Data As String
Public Property RealizadoEm() As String
Get
Return m_RealizadoEm
End Get
Set(value As String)
m_RealizadoEm = Value
End Set
End Property
Private m_RealizadoEm As String
Public Property DescricaoAcumuladoOutro() As String
Get
Return m_DescricaoAcumuladoOutro
End Get
Set(value As String)
m_DescricaoAcumuladoOutro = Value
End Set
End Property
Private m_DescricaoAcumuladoOutro As String
Public Property ValorAcumuladoOutro() As Double
Get
Return m_ValorAcumuladoOutro
End Get
Set(value As Double)
m_ValorAcumuladoOutro = Value
End Set
End Property
Private m_ValorAcumuladoOutro As Double
Public Property DataProximo() As String
Get
Return m_DataProximo
End Get
Set(value As String)
m_DataProximo = Value
End Set
End Property
Private m_DataProximo As String
Public Property ValorAcumuladoEspecial() As Double
Get
Return m_ValorAcumuladoEspecial
End Get
Set(value As Double)
m_ValorAcumuladoEspecial = Value
End Set
End Property
Private m_ValorAcumuladoEspecial As Double
Public Property Arrecadacao() As Double
Get
Return m_Arrecadacao
End Get
Set(value As Double)
m_Arrecadacao = Value
End Set
End Property
Private m_Arrecadacao As Double
Public Property Sorteios() As List(Of Sorteio)
Get
Return m_Sorteios
End Get
Set(value As List(Of Sorteio))
m_Sorteios = Value
End Set
End Property
Private m_Sorteios As List(Of Sorteio)
End Class
I can not go through all the "Numeros" and also "Premios"
You are over complicating this unnecessarily.
using the URL provided the exposed json data was copied and plugged into a utility site like http://jsonutils.com/. It generated the models with auto properties. Note that it converted collections to array as apposed to Lists like you have in your classes.
Public Class Premio
Public Property Faixa As String
Public Property NumeroGanhadores As Integer
Public Property Valor As Double
End Class
Public Class Sorteio
Public Property NumSorteio As Integer
Public Property Numeros As Integer()
Public Property Premios As Premio()
Public Property Ganhadores As Object()
End Class
Public Class RootObject
Public Property NumeroConcurso As Integer
Public Property Acumulou As Boolean
Public Property EstimativaPremio As Double
Public Property ValorAcumulado As Double
Public Property Data As String
Public Property RealizadoEm As String
Public Property DescricaoAcumuladoOutro As String
Public Property ValorAcumuladoOutro As Double
Public Property DataProximo As String
Public Property ValorAcumuladoEspecial As Double
Public Property Arrecadacao As Double
Public Property Sorteios As Sorteio()
End Class
Basically the same as what you had originally with better readability. Feel free to convert tha arrays back to list if that is your preference.
The first desrialization is already giving you the necessary object. Drill into the properties in order to access the values you need.
'''other code removed for brevity
Dim objs As RootObject = JsonConvert.DeserializeObject(Of RootObject)(json)
Dim objsSorteioList As List(Of Sorteio) = objs.Sorteios.ToList()
For Each objsSorteio In objsSorteioList
For Each prems In objsSorteio.Premios
MsgBox(prems.ToString)
Next
For Each nums In objsSorteio.Numeros
MsgBox(nums.ToString)
Next
Next

How to add datas from one class to another

I have a problem and i don't know how to solve it.
I have 2 different classs, and i need to get a datas that are in fist class to another class.
My first class look like :
Public Class ZnrEk1Ospos
Private _sif_tvrtka As Integer
Private _sif_radnika As Integer
Private _red_broj As Integer
Private _sif_ovl_osobe As Integer
Private _datum_teorija As Date
Private _datum_praksa As Date
Private _prezime_ime As String
Private _strucna_sprema As String
Private _funkcija As String
Private _status_obrasca As Integer
Private _glavni_instruktor As Integer
Private _instruktor_prezime As String
Private _instruktor_sprema As String
Private _instruktor_funkcija As String
Private _evidencijski_broj As String
Private _potvrda As String
Public Sub New()
'Do nothing as all private variables has been initiated
End Sub
Public Sub New(ByVal DataRow As DataRow)
_sif_tvrtka = CInt(DataRow.Item("sif_tvrtka"))
_sif_radnika = CInt(DataRow.Item("sif_radnika"))
_red_broj = CInt(DataRow.Item("red_broj"))
_sif_ovl_osobe = CInt(DataRow.Item("sif_ovl_osobe"))
_datum_teorija = IIf(IsDBNull(DataRow.Item("datum_teorija")), Nothing, DataRow.Item("datum_teorija"))
_datum_praksa = IIf(IsDBNull(DataRow.Item("datum_praksa")), Nothing, DataRow.Item("datum_praksa"))
_prezime_ime = IIf(IsDBNull(DataRow.Item("prezime_ime")), "", Trim(DataRow.Item("prezime_ime")))
_strucna_sprema = IIf(IsDBNull(DataRow.Item("strucna_sprema")), "", Trim(DataRow.Item("strucna_sprema")))
_funkcija = IIf(IsDBNull(DataRow.Item("funkcija")), "", Trim(DataRow.Item("funkcija")))
_status_obrasca = CInt(DataRow.Item("status_obrasca"))
_glavni_instruktor = CInt(DataRow.Item("glavni_instruktor"))
_instruktor_prezime = IIf(IsDBNull(DataRow.Item("instruktor_prezime")), "", Trim(DataRow.Item("instruktor_prezime")))
_instruktor_sprema = IIf(IsDBNull(DataRow.Item("instruktor_sprema")), "", Trim(DataRow.Item("instruktor_sprema")))
_instruktor_funkcija = IIf(IsDBNull(DataRow.Item("instruktor_funkcija")), "", Trim(DataRow.Item("instruktor_funkcija")))
_evidencijski_broj = IIf(IsDBNull(DataRow.Item("evidencijski_broj")), "", Trim(DataRow.Item("evidencijski_broj")))
_potvrda = IIf(IsDBNull(DataRow.Item("potvrda")), "", Trim(DataRow.Item("potvrda").ToString))
End Sub
Public Property sif_tvrtka() As Integer
Get
Return _sif_tvrtka
End Get
Set(ByVal value As Integer)
_sif_tvrtka = value
End Set
End Property
Public Property sif_radnika() As Integer
Get
Return _sif_radnika
End Get
Set(ByVal value As Integer)
_sif_radnika = value
End Set
End Property
Public Property red_broj() As Integer
Get
Return _red_broj
End Get
Set(ByVal value As Integer)
_red_broj = value
End Set
End Property
Public Property sif_ovl_osobe() As Integer
Get
Return _sif_ovl_osobe
End Get
Set(ByVal value As Integer)
_sif_ovl_osobe = value
End Set
End Property
Public Property datum_teorija() As Date
Get
Return _datum_teorija
End Get
Set(ByVal value As Date)
_datum_teorija = value
End Set
End Property
Public Property datum_praksa() As Date
Get
Return _datum_praksa
End Get
Set(ByVal value As Date)
_datum_praksa = value
End Set
End Property
Public Property prezime_ime() As String
Get
Return _prezime_ime
End Get
Set(ByVal value As String)
_prezime_ime = value
End Set
End Property
Public Property strucna_sprema() As String
Get
Return _strucna_sprema
End Get
Set(ByVal value As String)
_strucna_sprema = value
End Set
End Property
Public Property funkcija() As String
Get
Return _funkcija
End Get
Set(ByVal value As String)
_funkcija = value
End Set
End Property
Public Property status_obrasca() As Integer
Get
Return _status_obrasca
End Get
Set(ByVal value As Integer)
_status_obrasca = value
End Set
End Property
Public Property glavni_instruktor() As Integer
Get
Return _glavni_instruktor
End Get
Set(ByVal value As Integer)
_glavni_instruktor = value
End Set
End Property
Public Property instruktor_prezime() As String
Get
Return _instruktor_prezime
End Get
Set(ByVal value As String)
_instruktor_prezime = value
End Set
End Property
Public Property instruktor_sprema() As String
Get
Return _instruktor_sprema
End Get
Set(ByVal value As String)
_instruktor_sprema = value
End Set
End Property
Public Property instruktor_funkcija() As String
Get
Return _instruktor_funkcija
End Get
Set(ByVal value As String)
_instruktor_funkcija = value
End Set
End Property
Public Property evidencijski_broj() As String
Get
Return _evidencijski_broj
End Get
Set(ByVal value As String)
_evidencijski_broj = value
End Set
End Property
Public Property potvrda() As String
Get
Return _potvrda
End Get
Set(ByVal value As String)
_potvrda = value
End Set
End Property
And my second class in wich i want go get data from my first class look like:
Public Class TempEK1OsposTeorija
Private _sif_ovl_osobe As Integer
Private _datum_teorija As Date
Private _datum_praksa As Date
Private _prezime_ime As String
Private _strucna_sprema As String
Now i need to get data in Public Class TempEK1OsposTeorija form class Public Class ZnrEk1Ospos.
Does anybody know how to do that?
You need to create a new instance of that class
Public Class TempEK1OsposTeorija
Private _sif_ovl_osobe As Integer
Private _datum_teorija As Date
Private _datum_praksa As Date
Private _prezime_ime As String
Private _strucna_sprema As String
Public sub PozoviKlasuIvratiPodatke()
' To use the word using you must implement the IDisposable Interface into first class
Using cl as new ZnrEk1Ospos
'get data from first class
_sif_ovl_osobe = cl._sif_ovl_osobe
_datum_teorija = cl._datum_teorija
_datum_praksa = cl._datum_praksa
_prezime_ime = cl._prezime_ime
_strucna_sprema = cl._strucna_sprema
End using
End sub
End class

Class with a list of class in VB

I am trying to write a DLL that will accept an custom input with a nested list(of T)
I created 2 classes, a Main Class ClassPolyPoints and the nested Class classEF
I am getting an error when trying to pass the list(of classEF) object into the ClassPolyPoints object.
Dim TMP_effPoints As New List(Of classEF)
For i = 0 to 10
TMP_effPoints.Add(New classEff(
i,
i*0.125
))
Next
Dim tmpClass As New ClassPolyPoints(9.8765, TMP_effPoints)
Class that contains the nested list(of classEF)
Public Class ClassPolyPoints
Sub New(ByVal x_P0 As Double,
ByVal x_EffPoints As List(Of classEF))
_P0 = x_P0
With _effPoints
For Each a In x_EffPoints
.Add(New classEFF(
a.ID,
a.Eff
))
Next
End With
End Sub
Private _effPoints As List(Of classEff)
Public Property effPoints() As List(Of classEff)
Get
Return _effPoints
End Get
Set(ByVal value As List(Of classEff))
_effPoints = value
End Set
End Property
Private _P0 As Double
Public Property P0() As Double
Get
Return _P0
End Get
Set(ByVal value As Double)
_P0 = value
End Set
End Property
End Class
The nested class
Public Class classEF
Sub New(X_ID As Integer, X_Eff As Double)
_ID = X_ID
_Eff = X_Eff
End Sub
Private _ID As Integer
Public Property ID() As Integer
Get
Return _ID
End Get
Set(ByVal value As Integer)
_ID = value
End Set
End Property
Private _Eff As Double
Public Property Eff() As Double
Get
Return _Eff
End Get
Set(ByVal value As Double)
_Eff = value
End Set
End Property
End Class
You don't need to loop here just assign the list.
Public Class ClassPolyPoints
Sub New(ByVal x_P0 As Double,
ByVal x_EffPoints As List(Of classEF))
Me._P0 = x_P0
Me.effPoints = x_EffPoints
End Sub
'''
The issue is that you forgotten to create an istance of _effPoints before trying to add to the list new elements of class classEF:
That is in class ClassPolyPoints, you have to change the following declaration:
Private _effPoints As List(Of classEff)
into this:
Private _effPoints As New List(Of classEF)