Sub Question

  • Thread starter Thread starter HardySpicer
  • Start date Start date
H

HardySpicer

I have a sub which I call from a dll

controller.SendCommand(Code.A, number)

number is an integer and poses no problem. Code.A can be Code.B,Code.C
etc as it comes from what I assume is a class.

I am trying to replace Cose.A etc with a string of the same value but
it throws up an error. Is there a proper way to do this? I know the
strins is correct ie I can have

string = "Code.A" and call

controller.SendCommand(string, number)

and it gives the error.


Hardy
 
What is the error message?

You need to determine the type of object that the sub is expecting in that
argument. Code.A (or B or C) is probably not a string type. For instance,
if the sub is expecting to receive a font object in that parameter, then
passing the _name_ of a font will not work.

Where you use the command
controller.SendCommand(Code.A, number)

right click the Code.A argument and look at its definition.
 
What is the error message?

You need to determine the type of object that the sub is expecting in that
argument.  Code.A (or B or C) is probably not a string type.  For instance,
if the sub is expecting to receive a font object in that parameter, then
passing the _name_ of a font will not work.

Where you use the command
     controller.SendCommand(Code.A, number)

right click the Code.A argument and look at its definition.

The first part is integer and the second a constant ie Code is defined
as integer and A an integer.

How does that help?

Thanks
 
It doesn't help much, unfortunately.

The construct 'Code.A' indicates an object named Code with a member named A.
I'm guessing that A is a property and the property type is integer. In that
case you would pass an integer as the first argument, instead of the string
you were attempting to use. But it doesn't make sense that Code is
apparently declared as an integer.

What is the error you were getting when you used a string as the first
argument?

What is the line of code that is listed as the definition for Code.A?

What is the error message?

You need to determine the type of object that the sub is expecting in that
argument. Code.A (or B or C) is probably not a string type. For instance,
if the sub is expecting to receive a font object in that parameter, then
passing the _name_ of a font will not work.

Where you use the command
controller.SendCommand(Code.A, number)

right click the Code.A argument and look at its definition.

The first part is integer and the second a constant ie Code is defined
as integer and A an integer.

How does that help?

Thanks
 
Hardy,

In my idea can you only call a complete program, not direct a Sub from a
program direct from another external program (as it is not linked or
whatever)

Will you give us a sample how you did it, can be quiet interesting.

Cor
 
Hardy,

In my idea can you only call a complete program, not direct a Sub from a
program direct from another external program (as it is not linked or
whatever)

Will you give us a sample how you did it, can be quiet interesting.

Cor

Ok here is what I am really doing. Trying to turn on X-10 lights.
These are lights in a house which are lettered and numbered eg
A1,A2,B1,B2 etc up to 16 I think! They are controlled via the mains
wiring.
Now what follows I learned on this group a few days back: I create a
load of classes - this is the one for urning on light A1.

Class X10_command
Inherits BaseCommand
Public Overrides Sub Execute()
' Does all the A indexes

controller.SendCommand(X10HouseCode.A, device_number,
X10Command.TurnOn)
End Sub
End Class



I have an array of string defined at the top of the form

Private _commandNames As String() = New String(100)
Private _typeLookup As New Dictionary(Of String, String)()

and this in the Load_form bit

Sub init_commands()
' init lookup stuff for example
Dim types() As Type = Assembly.GetExecutingAssembly().GetTypes
()
For Each t As Type In types
If t.BaseType.Equals(GetType(BaseCommand)) Then
_typeLookup.Add(t.Name, t.FullName)
End If
Next

I then have:

These _commandNames needed for switching devices etc and commands
For i = 0 To however many I need
_commandNames(i) = action_string(i)
Next

where action_string(i) is an array of strings with all commands
including the above X10_command.

Then to execute any command I have this

Public Sub select_command(ByVal com_number As Integer)
' Next is the command number from 0 to number commands-1

' go up to number of actions -1 as max index

Dim command As BaseCommand = _
DirectCast(Assembly.GetExecutingAssembly().CreateInstance
(GetCommand(com_number), True), BaseCommand)

command.Execute()

End Sub



Now to execute any command i I can just do

select_command(i)

Works beautifully! Trouble is I need to repeat this for as many
letters (the numbers are ok) and commands, On,Off,Dim,Brighten etc So
what I want is to take the DLL that has
controller.SendCommand(X10HouseCode.A, device_number,
X10Command.TurnOn)

and replace X10HouseCode.A and X10Command.TurnOn dynamically so they
can be for example

X10HouseCode.B or X10Command.TurnOff for example. Then I would only
need one class instead of numerous.

Hardy
 
Hardy,

I'm still not sure what you are doing.

However, as I understand it well, I would for this definitly use the
Registry.
The Registry is easy to invoke in .Net and especially made for this kind of
things.

Don't hesitate to use it, as you see how much Microsoft uses the registry
themselves for all kind not OS programs, then you are just a low lever user
of that.

Just my idea,

Cor


Hardy,

In my idea can you only call a complete program, not direct a Sub from a
program direct from another external program (as it is not linked or
whatever)

Will you give us a sample how you did it, can be quiet interesting.

Cor

Ok here is what I am really doing. Trying to turn on X-10 lights.
These are lights in a house which are lettered and numbered eg
A1,A2,B1,B2 etc up to 16 I think! They are controlled via the mains
wiring.
Now what follows I learned on this group a few days back: I create a
load of classes - this is the one for urning on light A1.

Class X10_command
Inherits BaseCommand
Public Overrides Sub Execute()
' Does all the A indexes

controller.SendCommand(X10HouseCode.A, device_number,
X10Command.TurnOn)
End Sub
End Class



I have an array of string defined at the top of the form

Private _commandNames As String() = New String(100)
Private _typeLookup As New Dictionary(Of String, String)()

and this in the Load_form bit

Sub init_commands()
' init lookup stuff for example
Dim types() As Type = Assembly.GetExecutingAssembly().GetTypes
()
For Each t As Type In types
If t.BaseType.Equals(GetType(BaseCommand)) Then
_typeLookup.Add(t.Name, t.FullName)
End If
Next

I then have:

These _commandNames needed for switching devices etc and commands
For i = 0 To however many I need
_commandNames(i) = action_string(i)
Next

where action_string(i) is an array of strings with all commands
including the above X10_command.

Then to execute any command I have this

Public Sub select_command(ByVal com_number As Integer)
' Next is the command number from 0 to number commands-1

' go up to number of actions -1 as max index

Dim command As BaseCommand = _
DirectCast(Assembly.GetExecutingAssembly().CreateInstance
(GetCommand(com_number), True), BaseCommand)

command.Execute()

End Sub



Now to execute any command i I can just do

select_command(i)

Works beautifully! Trouble is I need to repeat this for as many
letters (the numbers are ok) and commands, On,Off,Dim,Brighten etc So
what I want is to take the DLL that has
controller.SendCommand(X10HouseCode.A, device_number,
X10Command.TurnOn)

and replace X10HouseCode.A and X10Command.TurnOn dynamically so they
can be for example

X10HouseCode.B or X10Command.TurnOff for example. Then I would only
need one class instead of numerous.

Hardy
 
Ok here is what I am really doing. Trying to turn on X-10 lights.
These are lights in a house which are lettered and numbered eg
A1,A2,B1,B2 etc up to 16 I think! They are controlled via the mains
wiring.
Now what follows I learned on this group a few days back: I create a
load of classes - this is the one for urning on light A1.

Class X10_command
Inherits BaseCommand
Public Overrides Sub Execute()
' Does all the A indexes

controller.SendCommand(X10HouseCode.A, device_number,
X10Command.TurnOn)
End Sub
End Class



I have an array of string defined at the top of the form

Private _commandNames As String() = New String(100)
Private _typeLookup As New Dictionary(Of String, String)()

and this in the Load_form bit

Sub init_commands()
' init lookup stuff for example
Dim types() As Type = Assembly.GetExecutingAssembly().GetTypes
()
For Each t As Type In types
If t.BaseType.Equals(GetType(BaseCommand)) Then
_typeLookup.Add(t.Name, t.FullName)
End If
Next

I then have:

These _commandNames needed for switching devices etc and commands
For i = 0 To however many I need
_commandNames(i) = action_string(i)
Next

where action_string(i) is an array of strings with all commands
including the above X10_command.

Then to execute any command I have this

Public Sub select_command(ByVal com_number As Integer)
' Next is the command number from 0 to number commands-1

' go up to number of actions -1 as max index

Dim command As BaseCommand = _
DirectCast(Assembly.GetExecutingAssembly().CreateInstance
(GetCommand(com_number), True), BaseCommand)

command.Execute()

End Sub



Now to execute any command i I can just do

select_command(i)

Works beautifully! Trouble is I need to repeat this for as many
letters (the numbers are ok) and commands, On,Off,Dim,Brighten etc So
what I want is to take the DLL that has
controller.SendCommand(X10HouseCode.A, device_number,
X10Command.TurnOn)

and replace X10HouseCode.A and X10Command.TurnOn dynamically so they
can be for example

X10HouseCode.B or X10Command.TurnOff for example. Then I would only
need one class instead of numerous.

Hardy

Not sure I follow one hundred percent here... but, couldn't you just pass the
values you want to use to the execute sub?
 
Back
Top