I have a vbscript that will read in commands from a text file. I am thinking of using the Execute and Eval commands to execute the commands from the file. Obviously, I will read in the file as a string, and parse the string into Eval and Execute commands. However, I am not sure if this is possible, and how to go about doing it?
For example, let's say I have the following file:
x = 3
y = 4
z = x + y
Print z
In my vbscript, I want something like the following:
' Read in file to string
' Split the string at the newline (commandList)
For Each str in commandList:
Execute(str)
Next str
The output would be:
7
I have tried the following to get a proof of concept:
Execute("x = 1")
However, I keep getting a "Function terminated during evaluation" error. Not sure what I am doing wrong. I am not too familiar with vbscript.
vbscript? Please edit your question and show your text file containing commands to be executed and an adequate code snippet (refer to How to Ask).Execute("x = 1"). Tried changing one of the spaces to a non-breaking space (U+00A0), got "Syntax Error". Tried defining a function/sub x(), got "Illegal assignment". Tried presetting x to an object, just overwrote it with the value. I suspect a clue might be in the sample input. Which host environment provides a "print" statement? Perhaps it is the environment that doesn't like the Execute statement.