Passing arguments to VB scripts

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
jhoski
Member
Posts: 11
Joined: Sun Jan 03, 2010 5:00 pm

Passing arguments to VB scripts

Post by jhoski »

Just getting started with housebot scripts and after searching help and here I don't see anything about how to pass arguments to a VB script when using the "Run Script" command in a task.

How is this handled?
Also is it possible to access a specific function directly that has been defined inside the vb script?

Thanks, Jay
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Passing arguments to VB scripts

Post by Osler »

What exactly are you trying to do? Basic arguments are passed via GetPropertyValue() and SetPropertyValue().

Owlet
jhoski
Member
Posts: 11
Joined: Sun Jan 03, 2010 5:00 pm

Re: Passing arguments to VB scripts

Post by jhoski »

Owlet,
Been away and just getting back to this.

Using Get and Set on device properties is not really passing an argument. Its just manipulating information directly in the devices. I could invent a property where I save the data that I wish the vbscript to see, but that is more overhead and not really good programming practice. I'd rather pass the information as an argument.

When you run a VB script stand alone you can use something like this from the command line.

cscript scriptname.vbs parm1 parm2 ...

parm1, parm2 etc. are the arguments to the VB script. I'm looking for the Housebot equivalent of parm1 when using a vbscript from a task.
Actually being able to call a user defined function in the vbscript would be even better. Then I could something like:

myFunction(arg1, arg2)

Thanks, Jay
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Passing arguments to VB scripts

Post by Osler »

jhoski:

I am still not clear exactly what you are trying to accomplish. Good programming practices aside, you have to work with what you have. Are you trying to pass parameters that would be external to HouseBot? If so, I understand your desire for wanting to use command line variables. From within HouseBot GetPropertyValue and SetPropertyValue will give you exactly what you want.

Imagine a null device named "TaskWatcher" with a property "NumTimesRun". It would be a simple device to keep track of how many times a task is run. Then you would have a vbscript run by some task with the following code.

Code: Select all


Main

Private Sub Main
     Dim Temp

     Temp = GetNumTimesRun(GetPropertyValue("TaskWatcher.NumTimesRun")
     SetPropertyValue("TaskWatcher.NumTimesRun", Temp)
End Sub

Private Function GetNumTimesRun(ByVal HBDeviceValue)
     Dim HBTimesRun

     HBTimesRun = CInt(HBDeviceValue)
     HBTimesRun = HBTimesRun + 1
     GetNumTimesRun = CStr(HBTimesRun)
End Function
If you could give me an example of exactly what you want to do, perhaps I could be of more help.

Osler (not Owlet...my fat fingers and my iPhone don't go very well together)
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Passing arguments to VB scripts

Post by Osler »

I just thought about what you may be asking and you can also use an execute program device in conjunction with a task to use cscript to run a script with command line parameters outside of HouseBot. You can use this if you are trying to run some housekeeping script that doesn't do anything HouseBot related (i.e., change property values).

Osler
jhoski
Member
Posts: 11
Joined: Sun Jan 03, 2010 5:00 pm

Re: Passing arguments to VB scripts

Post by jhoski »

More specifically, I have a bunch of x10 door sensors. Some of them have a lot of logic associated with them and using a single VB script for all door logic simplifies things. I would like to tell the VB script which door caused it to be invoked. I know I can set a property before invoking the script and have the script look at that property, however I thought there would be a more straightforward way, like passing the door argument in runscript action.

If not, I can deal with it. Much thanks for looking into it, Jay
Osler
HouseBot Guru
Posts: 742
Joined: Fri Feb 03, 2006 11:18 pm

Re: Passing arguments to VB scripts

Post by Osler »

I see the problem. With what you want to do, a null device with a property set by a task that the script can query is going to be the easiest way to do this. You may look and see if you can add more than just the script name to the task, though. So in the task instead of having X10Watcher.vbs you may be able to add a command line parameter to the actual call to the script (X10Watcher.vbs /Front Door). Not sure if this is even possible, or if it would work. Perhaps Scott can chime in. If not, I think this would be a good feature request.

Osler
Post Reply