Declared values end of instructions

D

Dave Neve

Hello

I'd like to check if the code below has been inserted in the right place for
it to be at 'module level'

I'd also like to know why there is a compilation error on the = sign
(expected: end of instructions)

Option Explicit
Private intPrivate As Integer =0
Public intPublic As Integer =0
Shared intShared As Integer =0
End Sub

I'm trying to run it on VBA (Word 2002) but it was taken from a VB.NET book.
 
J

Jay Freedman

Dave, you have to stop reading VB books and assuming things will work
the same in VBA. They don't, often enough that confusion is
inevitable. Get a VBA book, or read the VBA help when something
doesn't work.

In this case, VBA doesn't support initialization of variables in their
declaration statements. You have to declare the variables

Private intPrivate As Integer
Public intPublic As Integer
Shared intShared As Integer

and then, inside some Sub or Function, assign their values.

In the specific case of Integer, Long, Single, and Double variables,
VBA automatically initializes them to 0 (or 0.0), so you don't need to
initialize them explicitly unless their initial values are nonzero.

If the values should never change, you can use the Const statement
instead of Private, Public, or Dim. You do supply the (initial and
only) value of a constant in the Const statement -- that is the only
declaration statement in VBA that takes a value.
 
D

Dave Neve

Hi

I wish it were so easy.

The help in Word VBA is horrendous. In the summer, I did FrontPage from the
help page and with the support of a Microsoft group and I managed to publish
a site.

I haven't found any books on VBA. VB.Net andVB. Framework but not VBA

But I will take your advice and put away this book in the hope of finding
something better.

Thanks
 
J

Jezebel

In this case, VBA doesn't support initialization of variables in their
declaration statements.

VB doesn't support this either.

As a general principle (in both languages) there's usually no point in using
Integers. Since the operating system is 32 bit, Longs are the 'native' data
type. Integers are actually more work for the system (it has to mask out the
top 16 bits) - and thus slower - with no space saving. They are supported
only for backward compatability.
 
C

Cindy M -WordMVP-

Hi Dave,
The help in Word VBA is horrendous. In the summer, I did FrontPage from the
help page and with the support of a Microsoft group and I managed to publish
a site.

I haven't found any books on VBA. VB.Net andVB. Framework but not VBA
A VB book could be "translated" to VBA for lots of things, but certainly
*nothing* written for the .NET environment. .NET is a totally new language,
and even (or especially) seasoned VB programmers are having to relearn
practically from the ground up.

Look for
- Word 2000 VBA Programmer's Reference from Wrox press
- Writing Macros from O'Reilly publishing
- or even a Step-by-Step book from MS Press if you're really still at the
declaration stage

and read through the material on the mvps.org/word website

And BTW, all the basics about programming (such as variable declaration) that
you learned in programming Front Page is applicable in Word (and in Excel).

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Sep 30 2003)
http://www.mvps.org/word

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