Problem with VBscript

General HouseBot discussion. Any issues that don't fit into any of the other topics belong here.
Post Reply
spike5884
Senior Member
Posts: 129
Joined: Thu Aug 26, 2004 8:08 am
Location: WI

Problem with VBscript

Post 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
Circe640
Advanced Member
Posts: 206
Joined: Tue Oct 07, 2003 10:01 am
Location: Columbus, OH
Contact:

Post 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
spike5884
Senior Member
Posts: 129
Joined: Thu Aug 26, 2004 8:08 am
Location: WI

Post 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
Anks
Member
Posts: 1
Joined: Wed Sep 29, 2004 7:57 am

Post by Anks »

Try changing this line:



Set g_objEncoder = CreateObject("WMEncEng.WMEncoder")



to



Set g_objEncoder = WScript.CreateObject("WMEncEng.WMEncoder")



Anks.
spike5884
Senior Member
Posts: 129
Joined: Thu Aug 26, 2004 8:08 am
Location: WI

Post by spike5884 »

Set g_objEncoder = WScript.CreateObject("WMEncEng.WMEncoder")


Tried that. Just moves the error up one line.



-- Scott J
Circe640
Advanced Member
Posts: 206
Joined: Tue Oct 07, 2003 10:01 am
Location: Columbus, OH
Contact:

Scott you are needed here

Post 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!!!
spike5884
Senior Member
Posts: 129
Joined: Thu Aug 26, 2004 8:08 am
Location: WI

Post 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
ScottBot
Site Admin
Posts: 2790
Joined: Thu Feb 13, 2003 6:46 pm
Location: Georgia (USA)
Contact:

Re: Scott you are needed here

Post by ScottBot »

Circe640 wrote:SCOTT you need to jump on here!!!
Jumping is easy, it's helping with this issue that is hard. :wink:



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.
Scott
dlmorgan999
HouseBot Special Member
Posts: 409
Joined: Tue Jul 13, 2004 9:13 am
Location: Tigard, OR

Post 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
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Post 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
dlmorgan999
HouseBot Special Member
Posts: 409
Joined: Tue Jul 13, 2004 9:13 am
Location: Tigard, OR

Post 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
Richard Naninck
HouseBot Guru Extraordinaire
Posts: 1121
Joined: Tue Sep 28, 2004 7:49 am
Location: The Netherlands

Post 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
Post Reply