Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Does Excel do "just-in-time" compilation?

Sort of associated with my last question, but how does Excel execute a VBA
application:

o Is it interpreted or does it compile the VBA code into either native
assembler or some kind of p-code?
o If compiling, does it recompile everything at the start (e.g. auto_open)
or as classes, forms etc. are initiated

I'm suspecting it's not purely interpreted.

Thanks, Rob.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Does Excel do "just-in-time" compilation?

Is it interpreted or does it compile the VBA code into either native
assembler or some kind of p-code?

FYI, an assembler is a program that compiles assembly language source code
to machine language.

I don't know that MS has documented exactly what happens to our VBA source
code. Clearly it's converted to something when we save a file because the
code is not literally visible in the file when viewed with a text editor.
Obviously it's not compiled to machine language since the code runs on PCs
and Macs.

It's pretty clear I think that the code is interpreted at run-time. If you
have a programming error, like setting a range variable to a string, it is
not caught until VB tries to run that line of code. It seems to me that the
"Compile" command on the Debug menu just checks that all referenced subs and
functions can be found, and that variables are declared if Option Explicit
is used. It probably does other things too, since a file bloats after
issuing the command, but it doesn't compile code in traditional sense of
producing code a processor can directly execute.

--
Jim Rech
Excel MVP
"Rob Nicholson" wrote in message
...
| Sort of associated with my last question, but how does Excel execute a VBA
| application:
|
| o Is it interpreted or does it compile the VBA code into either native
| assembler or some kind of p-code?
| o If compiling, does it recompile everything at the start (e.g. auto_open)
| or as classes, forms etc. are initiated
|
| I'm suspecting it's not purely interpreted.
|
| Thanks, Rob.
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Does Excel do "just-in-time" compilation?

FYI, an assembler is a program that compiles assembly language source code
to machine language.


Okay, to be entirely accurate machine code or native instructions :-) I come
from the old Z80/6502 programming days when we programmed in assembler.

I don't know that MS has documented exactly what happens to our VBA source
code. Clearly it's converted to something when we save a file because the
code is not literally visible in the file when viewed with a text editor.
Obviously it's not compiled to machine language since the code runs on PCs
and Macs.


True - you can see the comments (in Unicode) but not a lot else. Basic has
been tokenised since the early days so Exit Sub is stored as a number.

issuing the command, but it doesn't compile code in traditional sense of
producing code a processor can directly execute.


Sounds it's something akin to p-code or the stuff used in the .NET
languages.

Would be nice to know, just for interest :-)

Cheers, Rob.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Does Excel do "just-in-time" compilation?

From post(s) by Chip Pearson:

"Storing P-Code" refers to the way in which VBA code is stored and
executed. VBA code is never compiled into actual machine executable
code (as is C/C++). Instead, it is stored as special codes which are
then read in as data by the VBA run time libraries, which translate
then execute the actual machine level instructions. There's an
interesting "White Paper", "VBA - Maximum Performance vs. File Size"
on the Baarns Group archive site
(http://archive.baarns.com/IE4/index_devonly.asp) which describes
this. Here's a quick summary... VBA is stored in workbooks as
"Opcodes" which are platform-independent (the same for 16 and 32 bit
Excel, for Windows and Mac) translation of the actual VBA text that
you type in and see in the editor. VBA never actually stores your
code as ascii text, although if you open an Excel file in a hex editor
you can see your VBA code as a mix of ascii strings and unreadable
gibberish. When you execute or "compile" a VBA procedure, the Opcodes
are translated to Excodes, which are specific to the platform (e.g.,
32-bit Excel on Windows).


The Java language and Tandem's S-COBOL work in a similar manner --
binary codes which are read as data by the "virtual machine", which
executes actual machine code on their behalf.


Cordially,
Chip Pearson
http://home.gvi.net/~cpearson/excel


-------------< -----------------

Martin,


Actually, just to get the terminology right, "Compiling" a VBA project
creates excodes, not opcodes. VBA always exists as opcodes -- it is never
stored as "text". Any conversion to text that you see on the screen is done
"on the fly" as you view the code.


Opcodes are how VBA is stored -- this is the version and platform
independent state of VBA, and no references are resolved (e.g., the code is
neither "early" nor "late" bound -- it is "unbound"). When you "compile"
the project, the "compiler" creates "excodes" which are specific to the
version and platform, and "early binds" whatever it can.


When you run VBA code which has not been "compiled", the "compilation" is
done on an as-needed basis, I believe module-by-module, rather than at the
project level (not sure about this point, though).


In the Developer Edition of Excel2000, you actually do have the ability to
create DLL files, for creating Com Add-Ins. These are totally different
form XLA Add-Ins, and are supported only in Office2000 applications, not
Office97. However, they provide all the speed (and code security) of
"normal" DLL files. Moreover, actual Application object is passed in during
the connection process (when the user goes to Tools, Com Add-Ins, and choose
your application), so you get the application's reference automatically, as
well as an event when the user terminates the add-in. If you haven't
started learning about Com Add-Ins, they are quite interesting. If you
want a VB6 sample file, send me an email, and I'll be happy to send you an
example project (it doesn't really do much, but it does illustrate the
general concepts).


--
Cordially,
Chip Pearson
Microsoft MVP - Excel

-------------

--
Regards,
Tom Ogilvy




"Rob Nicholson" wrote in message
...
FYI, an assembler is a program that compiles assembly language source

code
to machine language.


Okay, to be entirely accurate machine code or native instructions :-) I

come
from the old Z80/6502 programming days when we programmed in assembler.

I don't know that MS has documented exactly what happens to our VBA

source
code. Clearly it's converted to something when we save a file because

the
code is not literally visible in the file when viewed with a text

editor.
Obviously it's not compiled to machine language since the code runs on

PCs
and Macs.


True - you can see the comments (in Unicode) but not a lot else. Basic has
been tokenised since the early days so Exit Sub is stored as a number.

issuing the command, but it doesn't compile code in traditional sense of
producing code a processor can directly execute.


Sounds it's something akin to p-code or the stuff used in the .NET
languages.

Would be nice to know, just for interest :-)

Cheers, Rob.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Does Excel do "just-in-time" compilation?

From post(s) by Chip Pearson:

Thanks for that - interesting reading.

Cheers, Rob.


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disabling the "&[Time]" or "&[T]" in Excel headers and footers John Mirabella Excel Discussion (Misc queries) 2 January 15th 10 02:54 PM
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
How do I "paste link", and "transpose" at the same time? Zhi Sheng Excel Discussion (Misc queries) 3 August 5th 08 02:40 AM
cannot use "Create List" and "Share Workbook" same time Devendra Excel Discussion (Misc queries) 0 October 26th 06 06:05 AM
"Compilation" d'une feuille Excel / Compiling an excel sheet mk Excel Programming 1 June 15th 04 12:43 PM


All times are GMT +1. The time now is 06:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"