How is a variable of type Variant with value Empty represented on the stack?

345 views Asked by At

The following explanation is from the Rhino Developer Docs

Empty

When you declare a variable in VBScript, the variable’s value before the first assignment is undefined, or Empty.

Dim varValue ' Empty value

So basically, Empty says “I am an uninitialized variant.” If you need to detect whether a variable actually is an empty variant and not a string or a number, you can use IsEmpty. Alternatively, you could use TypeName or VarType, but IsEmpty is best.

So Empty is used for declaring variables. If you declare a variable, you reserve storage at the stack, but what is the value of Empty on the Stack?

2

There are 2 answers

0
MC ND On BEST ANSWER

VBScript variables are of type Variant. A variant represents a value that can change type. In memory, the Variant type is a 16 byte structure.

If the variable is empty (Empty value), then the vt member (that stores the type of the data referenced by the variable) will have a value of 0x0000 (VT_EMPTY)

0
CatCat On

What do you mean by stack? VBScript's virtual machine stack or the CPU stack. For theCPU stack use a debugger

You can also start in a debugger.

windbg or ntsd (ntsd is a console program and maybe installed). Both are also from Debugging Tools For Windows.

Download and install Debugging Tools for Windows

http://msdn.microsoft.com/en-us/windows/hardware/hh852363

Install the Windows SDK but just choose the debugging tools.

Create a folder called Symbols in C:\

Start Windbg. File menu - Symbol File Path and enter

srv*C:\symbols*http://msdl.microsoft.com/download/symbols

then

windbg -o -g -G c:\windows\system32\cmd.exe /k batfile.bat

All programs stop after loading but before starting to run the program. Press g to continue. Also programs stop after they finish running all code. Again press g.

You can press F12 to stop it and kb will show the call stack (g continues the program). If there's errors it will also stop and show them.

Type lm to list loaded modules, x *!* to list the symbols and bp [symbolname] to set a breakpoint.

A breakpoint is where the program stops when it encounters the BP. Allowing you to read the stack. kb shows the callstack and the first 4 parameters to the functions.

VB6

If programming in VB6 then this environmental variable link=/pdb:none stores the symbols in the dll rather than separate files. Make sure you compile the program with No Optimisations and tick the box for Create Symbolic Debug Info. Both on the Compile tab in the Project's Properties.

Also CoClassSyms (http://microsoft.com/msj/0399/hood/hood0399.aspx) can make symbols from type libraries. .

See for background https://blogs.msdn.microsoft.com/ericlippert/2004/04/19/runtime-typing-in-vbscript/

--