-1

I am a novice and am missing something simple. I have two Classes

Public Class Param
    Public Property temperature As String
    Public Property display As Boolean
    Public Property storage As Boolean
    Public Property reason As Boolean
    Public Property stats As Object
    Public Property errors As Object
End Class

Public Class getTemperature
    Public Property method As String
    Public Property params As Param()
    Public Property id As String
End Class

I want to declare and assign values to the objects but I keep getting the error "Object reference not set to an instance of an object" when trying to assign values to items within param. I don't understand, I have created both the object GetTemperature and the object Params, what am I missing?

 Dim GetTemp As New getTemperature    
    GetTemp.method = TextBoxMethod.Text
    GetTemp.id = TextBoxID.Text
    Dim params As New Param
    params.temperature = "true"
    'GetTemp.params(0) = params

I have also tried, but get the same response:

 Dim GetTemp As New getTemperature    
    GetTemp.method = TextBoxMethod.Text
    GetTemp.id = TextBoxID.Text    
    GetTemp.params(0).temperature = "True"
rick9rick
  • 23
  • 3

2 Answers2

0

Try this:

Public Class Param
    Public Property temperature As String
    Public Property display As Boolean
    Public Property storage As Boolean
    Public Property reason As Boolean
    Public Property stats As Object
    Public Property errors As Object
End Class

Public Class getTemperature
    Public Property method As String
    Public Property params As List(Of Param)
    Public Property id As String

    Public Sub New()
        params = New List(Of Param)
    End Sub
End Class

So you could write something like:

        Dim a As New getTemperature
        a.params.Add(New Param)
shadow
  • 1,840
  • 1
  • 14
  • 24
0

It will work if you remove the parenthesis

Public Class getTemperature
    Public Property method As String
    Public Property params As Param
    Public Property id As String
End Class

and then

Dim GetTemp As New getTemperature    
GetTemp.method = TextBoxMethod.Text
GetTemp.id = TextBoxID.Text
Dim params As New Param
params.temperature = "true"
GetTemp.params = params
Slai
  • 19,980
  • 5
  • 38
  • 44