Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to add a "variable" to a delegate .. Can I do This ?

How to add a "variable" to a delegate .. Can I do This ?

Scheduled Pinned Locked Moved Visual Basic
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Georg Kohler
    wrote on last edited by
    #1

    Below is portion of my current code ... obviously I'm having a serious problem with this :) Here is my question: In the following line I need to replace one of these two entries with a "variable" AddHandler Io_event.Input0, AddressOf F_DriveOK Any ideas on how to do this ? I need to add these handles dynamically - meaning the customer can change the mapping and therefore I need to update the handler to point to A) a different Address or B) change the input that point to a specific address What I have now works but is already pages long as I already have +40 Inputs and +25 Mapto locations :doh: It's definitely time to fix this ....

    Public Sub Add_InputHandle(ByVal VirtualNumber As Integer, ByVal MapTo As Integer)

               Select Case VirtualNumber
            Case 0
                Select Case MapTo
                    Case 0
                        AddHandler Io\_event.Input0, AddressOf F\_DriveOK
                    Case 1
                        AddHandler Io\_event.Input1, AddressOf F\_DriveOK
                    Case 2
                        AddHandler Io\_event.Input2, AddressOf F\_DriveOK
    

    .....
    .....
    .....
    End Select

            Case 1
                Select Case MapTo
    
                    Case 0
                        AddHandler Io\_event.Input0, AddressOf F\_Estop
                    Case 1
                        AddHandler Io\_event.Input1, AddressOf F\_Estop
                    Case 2
                        AddHandler Io\_event.Input2, AddressOf F\_Estop
    

    .....
    .....
    .....
    End Select
    End select

    Thanks Georg

    C S 2 Replies Last reply
    0
    • G Georg Kohler

      Below is portion of my current code ... obviously I'm having a serious problem with this :) Here is my question: In the following line I need to replace one of these two entries with a "variable" AddHandler Io_event.Input0, AddressOf F_DriveOK Any ideas on how to do this ? I need to add these handles dynamically - meaning the customer can change the mapping and therefore I need to update the handler to point to A) a different Address or B) change the input that point to a specific address What I have now works but is already pages long as I already have +40 Inputs and +25 Mapto locations :doh: It's definitely time to fix this ....

      Public Sub Add_InputHandle(ByVal VirtualNumber As Integer, ByVal MapTo As Integer)

                 Select Case VirtualNumber
              Case 0
                  Select Case MapTo
                      Case 0
                          AddHandler Io\_event.Input0, AddressOf F\_DriveOK
                      Case 1
                          AddHandler Io\_event.Input1, AddressOf F\_DriveOK
                      Case 2
                          AddHandler Io\_event.Input2, AddressOf F\_DriveOK
      

      .....
      .....
      .....
      End Select

              Case 1
                  Select Case MapTo
      
                      Case 0
                          AddHandler Io\_event.Input0, AddressOf F\_Estop
                      Case 1
                          AddHandler Io\_event.Input1, AddressOf F\_Estop
                      Case 2
                          AddHandler Io\_event.Input2, AddressOf F\_Estop
      

      .....
      .....
      .....
      End Select
      End select

      Thanks Georg

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      I would create two variables, then set their values in the case statements, and finally do the add handler using those variables. You could also store lookup tables for those values, but this code will have to go somewhere.

      Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

      G 1 Reply Last reply
      0
      • C Christian Graus

        I would create two variables, then set their values in the case statements, and finally do the add handler using those variables. You could also store lookup tables for those values, but this code will have to go somewhere.

        Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

        G Offline
        G Offline
        Georg Kohler
        wrote on last edited by
        #3

        That sounds good - but correct me if I'm wrong - I don't think you can use a variable in an Address of statement. So somehow you would have to create another delegate for the adress of statement ??? I did try lot's of different ways a while back - non of them worked ...meaning I was somehow not on the right track :-O Can you give me a short example of how your would do this?

        C 1 Reply Last reply
        0
        • G Georg Kohler

          That sounds good - but correct me if I'm wrong - I don't think you can use a variable in an Address of statement. So somehow you would have to create another delegate for the adress of statement ??? I did try lot's of different ways a while back - non of them worked ...meaning I was somehow not on the right track :-O Can you give me a short example of how your would do this?

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          I dunno about addressof , but I'd just create two variables, whatever the types, at the top. Then in my switch statements, I would assign them. I'd do the delegate stuff at the bottom, using the variables.

          Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

          1 Reply Last reply
          0
          • G Georg Kohler

            Below is portion of my current code ... obviously I'm having a serious problem with this :) Here is my question: In the following line I need to replace one of these two entries with a "variable" AddHandler Io_event.Input0, AddressOf F_DriveOK Any ideas on how to do this ? I need to add these handles dynamically - meaning the customer can change the mapping and therefore I need to update the handler to point to A) a different Address or B) change the input that point to a specific address What I have now works but is already pages long as I already have +40 Inputs and +25 Mapto locations :doh: It's definitely time to fix this ....

            Public Sub Add_InputHandle(ByVal VirtualNumber As Integer, ByVal MapTo As Integer)

                       Select Case VirtualNumber
                    Case 0
                        Select Case MapTo
                            Case 0
                                AddHandler Io\_event.Input0, AddressOf F\_DriveOK
                            Case 1
                                AddHandler Io\_event.Input1, AddressOf F\_DriveOK
                            Case 2
                                AddHandler Io\_event.Input2, AddressOf F\_DriveOK
            

            .....
            .....
            .....
            End Select

                    Case 1
                        Select Case MapTo
            
                            Case 0
                                AddHandler Io\_event.Input0, AddressOf F\_Estop
                            Case 1
                                AddHandler Io\_event.Input1, AddressOf F\_Estop
                            Case 2
                                AddHandler Io\_event.Input2, AddressOf F\_Estop
            

            .....
            .....
            .....
            End Select
            End select

            Thanks Georg

            S Offline
            S Offline
            Skymir
            wrote on last edited by
            #5

            Does the sender object not pass through? It seems to me you should be able to ID the sender inside the delegate and work from that side of the problem. Use one delegate for all of the inputs, that delegate checks the sender ID and matches it to a function based on it's MapTo setting. I forget if you can create a collection of functions in VB.Net, but even without it, that should at least cut the list down to one look up for the MapTo and a 25 option select statement.

            The true man wants two things: danger and play. For that reason he wants woman, as the most dangerous plaything.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups