Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


June 15, 2000

Understanding VBScript: Runtime Code Evaluation


RSS
View this exclusive article with VIP access -- click here to join |
See More VBScript Articles Here | Reprints | Or sign up for our VIP Monthly Pass!
SideBar    Where to Find VBScript 5.0 and How It Compares with VBA and JScript
Runtime Code Evaluation

The ability to evaluate code at runtime is a new feature in VBScript 5.0. Because this feature is new, many people aren't familiar with what runtime code evaluation is and how to use it.

What Is Runtime Code Evaluation?
To understand runtime code evaluation, you need to know the difference between how compiled-language scripts (e.g., C or C++ scripts) and interpreted-language scripts (e.g., VBScript or Perl scripts) execute. In a compiled-language script, a compiler reads the script's source code and translates it into low-level instructions that the hardware can understand, which is typically binary code. You then execute the binary code separately. If you use a compiled language, you must write a complete script before you can compile and execute it.

In interpreted-language scripts, a runtime module reads in the source code, translates the source code into binary code, and executes the instructions directly. This module reads, translates, and executes the source code line by line. Thus, you don't need to write a complete script before you execute it. . . .


Already a VIP member?
Please log on to view the full article

Why become a VIP member?

VIP-only online access
VIP CD delivered twice a year: offline access to the entire Windows IT Pro article library
Monthly issue of your choice of Windows IT Pro or SQL Server Magazine

Subscribe Now
Reader Comments
<p>So using Execute you can define a function within a function whose scope is only that of the function that called Execute. So the function defined by Execute would what, have direct access to the defining functions local variables? No, it doesn't, actually. Defining functions within functions is very cool, but it doesn't have any teeth in VBScript:<br>
<blockquote>&#60;vbs&#62;
<br>Option Explicit<br>
sub DefinerFunc
<blockquote>Dim buf<br>
buf = "foobar"<br>
Execute "MsgBox buf"<br>
Execute "sub DefinedFunc: MsgBox buf: end sub"<br>
Call DefinedFunc</blockquote>
end sub<br>
DefinerFunc<br>
&#60;/vbs&#62;</blockquote>

This only outputs "foobar" once, not twice, because DefinedFunc can't see the buf variable defined in DefinerFunc. Too bad. So using Execute within a function to define another function only differs from ExecuteGlobal in that you get your own function naming scope, but the defined function sees only a global scope, even if the defining function is within a class. So you can't really define new member functions, either. Oh well, it's still good for some little stuff, and it's somewhat safer and simpler this way.<p>

Michael Balloni May 01, 2002


<p>Really interesting. Is there anything known about what it does to the performance to add procedures, or even constants, to your current scope? Will it be useful to add constants instead of declaring public variables, for instance in ASP VBScript, where the public variables are a pain?<br>
<br>
For example a function that holds the GUI strings as constants for a chosen language, where the strings are retrieved from the database just once?</p>

Joris Ceelen August 23, 2002


easy way to leave yourself open to vb injection attack - just make sure you are very carefull when you use this with user input.

i.e.
post a statement in the following format:
something to close the preceeding statement
": on error resume next:"
whatever you want to execute
": response.end"

Anonymous User July 19, 2005 (Article Rating: )


You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement