I have a problem similar to Variable with Value of a Label Name
But instead of a label, I am trying to use a ListBox
Private Sub processLog(ByVal logFileName As String, ByVal logCateory As String)
Dim variableListBox As New ListBox
variableListBox = DirectCast(Me.Controls(logCateory), ListBox)
variableListBox.Items.Add("HELLO")
End Sub
What could possible be wrong with the above code, it return NullReferenceException was unhandled Object reference not set to an instance of an object. on the line, variableListBox.Items.Add("HELLO").
I have also a timer to call the above Sub:
Private Sub tmrProcessLogs_Tick(sender As Object, e As EventArgs) Handles tmrProcessLogs.Tick
processLog(fileGeneral, lbxGeneral.Name.ToString)
End Sub
logCateoryin the container, a debugger could help you to find the exact problem.logCategoryis the variable use to pass the name of the control. When the timer ticks, asubis called with parameters in which the second parameter is the name of thecontrol