CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2013
    Posts
    7

    Newbie problem - can I use a string to set a parameter?

    Private Sub Neuron1x2_Click_1(sender As Object, e As EventArgs) Handles Neuron1x2.Click
    If NEURON(1, 2) = 1 Then NEURON(1, 2) = 0 Else NEURON(1, 2) = 1
    If NEURON(1, 2) = 1 Then Neuron1x2.BackColor = Color.Red
    If NEURON(1, 2) = 0 Then Neuron1x2.BackColor = Color.White
    End Sub

    Hi,

    I am trying to develop a simple, visual neural network. I need this to demonstrate principles to students (I teach psychology)

    The 'neurons' are represented by successive rows of ovals on the screen, and are connected (up and down) by lines (the 'axons').

    When the user triggers an event, then the system will run down the rows in succession, checking if an input (incoming axon) is active,
    then summing them for each 'neuron' and comparing with a threshold to see if the neuron should then become active.

    I want the user to be able to set the initial state of the network, by clicking on the neurons, which then become red - as above.

    I want to set the overall system as a two dimensional array, using DIM (x, y), and will then use this to successively run across each row (using y),
    and down each layer (using x).

    I have a very limited knowledge of programming (some early basic and assembler), and am having some difficulty.

    My main problem at the moment is how to change the color, using the array values.

    I am able to use the array values to generate a string (by converting the numbers x and y to strings, then combing them with "Neuron" and "x")
    - for example "Neuron1x2" , but is there any way to use this in the expression?
    Neuron1x2.BackColor = Color.Red

    I appreciate I may be doing this all in completely the wrong way, and/or that this may not be possible.

    Many thanks

    Arthropod

  2. #2
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Re: Newbie problem - can I use a string to set a parameter?

    I'm sure what you want to do is possible, but you leave some of the context open for interpretation, so we need to clarify some things.

    Let's start by getting a better understanding of what you want to do and what you're already doing.

    It appears that you you're already accomplishing your task by handling the click event for a button that corresponds to every element in the NEURON array. Is that code in use, or is it conceptual? Are you trying to do the same thing in a different way, or are you talking about something else entirely?
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  3. #3
    Join Date
    Sep 2013
    Posts
    7

    Re: Newbie problem - can I use a string to set a parameter?

    Quote Originally Posted by Craig Gemmill View Post
    I'm sure what you want to do is possible, but you leave some of the context open for interpretation, so we need to clarify some things.

    Let's start by getting a better understanding of what you want to do and what you're already doing.

    It appears that you you're already accomplishing your task by handling the click event for a button that corresponds to every element in the NEURON array. Is that code in use, or is it conceptual? Are you trying to do the same thing in a different way, or are you talking about something else entirely?
    Hi Craig,

    Thanks for the rapid reply.

    I am using that code - as you say, to handle a click event on the 'neuron' (an oval shape).

    What I want to do is to set the colour by using the information from the array, rather than the Neuron1x2.BackColor

    Is there any way I convert a string (which I can derive from where I am in the array), so that I can put it in front of .BackColor?

    So, if I had a string set by
    Dim T As String = "Neuron1x2"

    Simply putting
    T.BackColor
    does not work

    I am sure I am being quite stupid and ignorant here - my apologies.

    Arthropod

  4. #4
    Join Date
    Sep 2013
    Posts
    7

    Re: Newbie problem - can I use a string to set a parameter?

    Bit more background information:

    The final program will start off with three rows of three 'neurons' (white circles). Each of these will be joined to two of the neurons below.

    A user will first 'set' which neurons they wish, by clicking on them - they will then turn red.

    The use will then click on a box to step through the successive activation of the 'neurons'. This will move down through the rows, with the principle that an active neuron will generate two active 'axons' (lines), and a neuron will only become active when it receives two active inputs.

    As the wave of activation moves downwards, I want to show the neurons being activated (by the colour red). This means that I have to use the array information in some way to do this.

    I am keeping the information about which row is being considered, and which column, in the array ( a nested loop). So, sort of
    DIM NEURON (3,3) As Integer
    For x = 1 to 3 (this is moving down the rows)
    For y = 1 to 3 (this is moving across the rows)
    Code to handle input and whether neuron becomes active
    Next y
    Next x

    Thanks
    Arthropod

  5. #5
    Join Date
    Feb 2000
    Location
    OH - USA
    Posts
    1,892

    Re: Newbie problem - can I use a string to set a parameter?

    There is still some ambiguity here, but let me try to point you in the right direction:

    1) Globally, this is possible using "Reflection", but you shouldn't do this. It's a very resource expensive operation and is usually a last resort.
    2) Since you're setting the background color in the button click event, you will already have access to the control without having to "find" it. For example:
    Code:
    Private Sub Neuron1x2_Click_1(sender As Object, e As EventArgs) Handles Neuron1x2.Click
     If NEURON(1, 2) = 1 Then NEURON(1, 2) = 0 Else NEURON(1, 2) = 1
     If NEURON(1, 2) = 1 Then DirectCast(sender, Control).BackColor = Color.Red
     If NEURON(1, 2) = 0 Then DirectCast(sender, Control).BackColor = Color.White
     End Sub
    This code will cast the "sender" object in to a Control object which allows you to modify the BackColor directly. You can even tie every button to the same click event to make this even easier.
    3) You can use:
    Code:
    Me.Controls("Namehere").BackColor = Color.White
    once you have the variable name as a string.
    Good Luck,
    Craig - CRG IT Solutions - Microsoft Gold Partner

    -My posts after 08/2015 = .NET 4.x and Visual Studio 2015
    -My posts after 11/2011 = .NET 4.x and Visual Studio 2012
    -My posts after 02/2010 = .NET 4.0 and Visual Studio 2010
    -My posts after 12/2007 = .NET 3.5 and Visual Studio 2008
    -My posts after 04/2007 = .NET 3.0 and Visual Studio 2005
    -My posts before 04/2007 = .NET 1.1/2.0

    *I do not follow all threads, so if you have a secondary question, message me.

  6. #6
    Join Date
    Sep 2013
    Posts
    7

    Re: Newbie problem - can I use a string to set a parameter?

    Thanks Craig,

    Unfortunately, I realise I am WAYYYYY out of my depth and need to do some basic study here.

    Many thanks though

    Arthropod

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured