Variables vs Fields

S

SHealy

Hi All,

Can someone help me here? I'm looking for the difference within Word
between variables and fields.

Are variables only available in VBA or is a field within Word classed as a
variable too?

Thanks!

Sian
 
P

Pesach Shelnitz

Hi,

Fields are those things enclosed in curly brackets ({}) that you see when
you press Alt+F9. The fields that begin with the code DOCVARIABLE are
variables.
 
G

Greg Maxey

Pesash,

If I may ...

Break

SHealy,

Variables are created and stored in the document using VBA:

Sub ScratchMacro()
ThisDocument.Variables("TestVar").Value = "This is the TestVar text value"
End Sub

There is a type of field named DocVariable. It can be used to reference and
display a variables text value in a document:

{ DocVariables "TestVar" } returns "This is the TextVar text value"
 
C

Cindy M.

Hi SHealy,
Can someone help me here? I'm looking for the difference within Word
between variables and fields.

Are variables only available in VBA or is a field within Word classed as a
variable too?

A lot depends on what *you* mean by the terms "field" and "variable". If
you're coming from a .NET/C# environment, where class-level variables are
sometimes referred to as fields, your question could mean something quite
different?

Field: In Word parlance, a field is an object in the document that Word uses
to provide dynamic data for the user. Common examples are Date (when updated
shows the current date), Page (shows the page number of the page where Word's
pagelayout calculations indicates the field is going to show up when printed)
and FileName (shows the file name of the document file).

VBA does not traditionally use this term to identify class-level members in
its code.

Variable: Word has something called a "document variable". VBA uses the term
"variable" as commonly used in programming terms - something to hold a value
or object that is being used or manipulated in the code.

The Word object, document Variable, is traditionally used to store/persist
String information in the document in a manner not visible or accessible to
the user. (A document Property is visible to the user; doc Variables predate
doc Properties by a few years.) The content of a document Variable can be
displayed to the user via a DocVariable field, but cannot be changed through
it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top