How to add a "variable" to a delegate .. Can I do This ?
-
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 SelectCase 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 selectThanks Georg
-
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 SelectCase 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 selectThanks Georg
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 )
-
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 )
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?
-
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?
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 )
-
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 SelectCase 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 selectThanks Georg
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.