September 26th, 2013, 09:59 AM
Trying to use string for object
I still have the same problem, but I think I can now state it more clearly:
The key aspects of the program I am concerned about are
Dim Neuron(3, 3) As Integer
Dim NeurNameBase As String = "Neuron"
Dim NeurName As String
For row As Integer = 1 To 3 Step 1
For column As Integer = 1 To 3 Step 1
NeurName = NeurNameBase & row.ToString & "x" & column.ToString 'Assemble string which I want to use as Object – this works ok
'Then Various code included here, to decide whether Neuron should be made active (depends on inputs)
'If Neuron should be active, then carry out various actions, including changing colour of object (Neuron on form) to RED
NeurName.BackColor = Color.Red ‘THIS IS WHAT I CANNOT DO
My problem is using the string NeurName (Neuron1x1, Neuron1x2, Neuron1x3, Neuron2x1, …… Neuron3x3) in some way, to change the colour of the objects on the form, which have the same names.
From what has been said already (and some blundering around the net), it looks as though I need to call up one of the controls by matching it with the string.
I have tried
Me.Controls(“NeurName”) = Color.Red
But I get the error ‘NullReferenceException was unhandled’ with ‘Object reference not set to an instance of an object’
However, I do have the objects on the form, with the appropriate names – am I missing something?
Am I getting any closer?
A small example which works would be really useful.
Many thanks for any help/advice
Toto, I have a feeling we're not in GW-BASIC anymore.
Click Here to Expand Forum to Full Width