开发者

WScript.Echo throwing object required error in vbscript

开发者 https://www.devze.com 2023-04-01 18:45 出处:网络
I\'m trying to display messages as my vbscript program runs. It runs off a command prompt in xp, for example: cscript.exe test.vbs.I don\'t want to use msgBox while this is running as I just want it t

I'm trying to display messages as my vbscript program runs. It runs off a command prompt in xp, for example: cscript.exe test.vbs. I don't want to use msgBox while this is running as I just want it to post the scripts progress, but I don't want any user interaction.

I tried using Wscript.echo "Some text", but I'm getting compile errors when I step through the program using Words built-in vbeditor.

I found this code and it runs fine in another file:

Option Explicit
Dim strComputer
strComputer = "LocalHost"
WScript.Echo "Computer: " _
& strComputer
WScript.Quit

I then tried using Dim an开发者_JS百科d set to setup a Wscript variable, but that didn't work either.

Any ideas as to what I'm doing wrong? I did verify Wscript is running on this machine.

Thanks, James


Word uses VBA (Visual Basic for Applications), not VBScript. Although both languages belong to the Visual Basic family, they have differences. One of them is that the WScript object isn't available in VBA - that's why you're getting errors when debugging your script in Word.

Having said that, your code is valid and runs perfectly fine with both cscript and wscript.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号