Page 1 of 1
Problem with VBscript
Posted: Thu Oct 14, 2004 10:24 pm
by spike5884
The below code is a small section of a larger script I am trying to get to run within HouseBot. This sample and its larger brother run just fine outside of HB. Running it inside of HB produces an "Object required: 'WScript'". I have tried different things, but cannot get it to run in HB. What needs to be done to get this to run in HB??
Thanks,
Scott J
Code: Select all
Dim g_objEncoder
Set g_objEncoder = CreateObject("WMEncEng.WMEncoder")
call WScript.ConnectObject(g_objEncoder, "Encoder_")
msgbox "something"
set g_objEncoder = nothing
Posted: Fri Oct 15, 2004 12:51 am
by Circe640
What do you mean running 'outside of HouseBot'? VBScripts have to run in some environment and I don't think you mean DOS. My first guess would be that you are using WScript and that object is not know inside the HouseBot environment
Posted: Fri Oct 15, 2004 8:06 am
by spike5884
I mean just what I said, "outside of HouseBot". When I double click on the .vbs file in Windows Explorer it runs just file. So, I am guessing that Windows Explorer is 'setting-up' the environment so that the script will run. The quote below is from the VBScript help:
The WScript object is the root object of the Windows Script Host object model hierarchy. It never needs to be instantiated before invoking its properties and methods, and it is always available from any script file.
To me this means that the WScript object should just be there and not need to be defined. So, the question could become what does HB do to run scripts.
Thanks,
Scott J
Posted: Fri Oct 15, 2004 1:29 pm
by Anks
Try changing this line:
Set g_objEncoder = CreateObject("WMEncEng.WMEncoder")
to
Set g_objEncoder = WScript.CreateObject("WMEncEng.WMEncoder")
Anks.
Posted: Fri Oct 15, 2004 7:10 pm
by spike5884
Set g_objEncoder = WScript.CreateObject("WMEncEng.WMEncoder")
Tried that. Just moves the error up one line.
-- Scott J
Scott you are needed here
Posted: Fri Oct 15, 2004 8:39 pm
by Circe640
I am going to guess that since houseBot is an exe and it is running inside that exe the WScript has to be one of the linked libraries when HB is compiled otherwise the instantiation is outside the HouseBot environment and housebot cannot find the instantiated methods.
SCOTT you need to jump on here!!!
Posted: Fri Oct 15, 2004 10:08 pm
by spike5884
Well, with a lot of digging, I found out that the wscript obj is not available in all VBScript environments. HB must be one of these. From what I found, that is just the way it is. I am thinking that HB(Scott) has no control over it.
The script I am working on, works 'fine' without the "WScript.ConnectObject" line. Only problem is that the events that line defines into the script, control the ending of the script. I am now onto trying to figure out how to define the events in the script without the WScript environment. All the docs out there use the ConnectObject. Wish me luck....
Thanks,
Scott J
Re: Scott you are needed here
Posted: Fri Oct 15, 2004 10:41 pm
by ScottBot
Circe640 wrote:SCOTT you need to jump on here!!!
Jumping is easy, it's helping with this issue that is hard.
Scott J,
It looks like you've uncovered the issue that the WScript object is not available to all VBScript code. It's not actually a part of the Active Script Engine that is used by the Script Device, but is provided by the WSH command line tool, which is why it works when being started from the command prompt (or via the Explorer). There's not really anything I can do to add the support.
Posted: Tue Jun 05, 2007 8:38 pm
by dlmorgan999
Did anyone ever come up with a clever workaround for this issue. I have a need to run a remote command-line application when certain properties in HouseBot change values but I ran up against this issue.
-- Dave
Posted: Wed Jun 06, 2007 12:12 pm
by Richard Naninck
Just leave out the WScript part and you should be fine.
I use lots of these "CreateObject" lines in my code with no problem at all.
Dave,
Can you post some an example of some code that doesn't work for you?
WScript cannot be called from inside HB, but I have never needed it.
Below an example of how WScript stuff can be used:
Code: Select all
Option Explicit
Dim objShell
Dim SendKey
Set objShell = CreateObject ("WScript.Shell")
Do
Sleep 1
SendKey = GetPropertyValue ("Send Meedio Keys.Send Meedio Key")
If SendKey <> "Waiting" Then
SetPropertyValue "Send Meedio Keys.Send Meedio Key", "Waiting"
objShell.AppActivate "meedio essentials"
objShell.SendKeys SendKey
End If
Loop
Set objShell = Nothing
Code: Select all
Option Explicit
On Error Resume Next
Dim objShell
Dim objExec
Dim objStdOut
Dim objRE
Dim strContent
Dim Status
Dim EnergieBeheer
Set objShell = CreateObject ("WScript.Shell")
Set objExec = objShell.Exec ("powercfg.exe /Q")
Set objStdOut = objExec.StdOut
strContent = objStdOut.ReadAll
Set objRE = New RegExp
objRE.Pattern = ("Minimaal energieverbruik")
objEE.IgnoreCase = True
If objRE.Test(strContent) = True Then
Status = "On"
Else
Status = "Off"
End If
SetPropertyValue "CNQ Status Script.Cool And Quiet", Status
Set objRE = Nothing
Set objStdOut = Nothing
Set objExec = Nothing
Set objShell = Nothing
Posted: Wed Jun 06, 2007 1:00 pm
by dlmorgan999
Hi Richard,
Here is my code:
Code: Select all
Dim Temperature
Dim Humidity
Dim WindSpeed
Dim Rainfall
Dim ParameterString
Dim WshShell
Dim intReturn
Temperature = Round(GetPropertyValue("Weather.Outdoor Temperature"), 0)
Humidity = GetPropertyValue("Weather.Outdoor Humidity")
WindSpeed = GetPropertyValue("Weather.Wind Speed")
Rainfall = GetPropertyValue("Weather.Daily Rain")
ParameterString = ParameterString & "/Temperature=" & Temperature & " "
ParameterString = ParameterString & "/Humidity=" & Humidity & " "
ParameterString = ParameterString & "/WindSpeed=" & WindSpeed & " "
ParameterString = ParameterString & "/Rainfall=" & Rainfall & " "
MsgBox "ParameterString='" & ParameterString & "'"
Set WshShell = WScript.CreateObject("WScript.Shell")
intReturn = WshShell.Run("C:\Program Files\SignManager\SignManager " & ParameterString, 1, TRUE)
Are you saying that if I replace this line:
Code: Select all
Set WshShell = WScript.CreateObject("WScript.Shell")
with this line:
Code: Select all
Set WshShell = CreateObject("WScript.Shell")
that it should work okay?
-- Dave
Posted: Wed Jun 06, 2007 1:17 pm
by Richard Naninck
Pretty standard and it should work if you leave out the WScript part like you suggested. Just test it and it will work. At least my code examples work fine and they run in scripts executed by HB.
EDIT:
Instead of WShell.Run, also look at .Exec