how
>> WScript.Echo CreateObject("WScript.Shell").CurrentDirectory >> E:\trials\SoTrials\answers\trials\AlgoTaBu\SuSo\wsf
proves that there is no rule or law that "your Set scmd must create an instance of WScript.Shell." Proper use of the command to execute in the string variable scmd (or perhaps better than sCmd), and not to create a variable for one-time use only.
Revised version (minus the dumb set):
call main() sub main() Dim scmd scmd = "c:\windows\system32\cscript.exe //nologo c:\s.vbs" createobject("wscript.shell").run scmd,0,false end sub
will work just as well as the Lankymart version.
To highlight everything:
- The Set keyword, its semantics, and the error message are design flaws that make VBScript more difficult to use.
"site:stackoverflow.com vbscript "object required" Set" results in 1,500 hits. Even if many of these hits do not deal with the error "Set x = 'non-object' , this is clearly too much. To explain / excuse those IEDs, you have to consider that BASIC is a Stone Age language. - A person learning VBScript may be surprised at the error
"Set x = 'non-object' twice. If this happens three times (or more often), he / she should be ashamed (and keep silent about it). First of all, this problem should not pollute this site. - When I posted my contribution, all responses / comments - with the exception of Alex K. "Just delete Set" - are emphasized / focused on the .Run entry; one answer called the script "top fervor", one answer even repeated the atrocities. So I tried to indicate that there is exactly one error: a false set.
- I have failed. Evidence: John Saunders changed the name from “VBScript Error” (non-specific, but true) to “Object Required” when calling “Run on Wscript.Shell” (specific but incorrect), Lankymart did psychological / philological research to keep Set on line consumption.
- My only hope: everyone who reads this will be so disgusted from my fight on Seth that he / she will now think twice when entering:
Wtf
Set x = " ---- stop or be damned!!! Set x = obj.getNumber() + 4 ---- oh no!!!
source share