Complete list of characters valid in a VBA variable name?

J

John Gunther

I need to know all of the characters than can be part of a valid VBA
variable name.

Dim çà as Integer

This VBA line compiles fine, so ç and à are acceptable.
abcdefghijklmnopqrstuvwxyz are clearly OK too. 0123456789 and _ are OK
as long as they don't come first.

But what I need is a complete list. Does anyone have it, or know where
I can get it?

Why do I need this? See http://invisiblebasic.sourceforge.net/, an open
source Excel/VBA source obfuscation utility--I need a list of such
characters so I can properly recognize variable names regardless of if
the VBA code is created by French or English or ... speaking VBA
coders.

I searched around but could not find this list anywhere...please help.

John
 
T

Tony Jollans

The actual characters depend on your code page but I believe any character
in the range 128-255 is allowable. They are also case insensitive so

Dim çà as Integer

is the same as

Dim ÇÀ as Integer

--
Enjoy,
Tony


I need to know all of the characters than can be part of a valid VBA
variable name.

Dim çà as Integer

This VBA line compiles fine, so ç and à are acceptable.
abcdefghijklmnopqrstuvwxyz are clearly OK too. 0123456789 and _ are OK
as long as they don't come first.

But what I need is a complete list. Does anyone have it, or know where
I can get it?

Why do I need this? See http://invisiblebasic.sourceforge.net/, an open
source Excel/VBA source obfuscation utility--I need a list of such
characters so I can properly recognize variable names regardless of if
the VBA code is created by French or English or ... speaking VBA
coders.

I searched around but could not find this list anywhere...please help.

John
 
T

Tony Jollans

I think it unlikely that code that works today will fail tomorrow, as it
were, but have failed to find any written evidence supporting the validity
of these characters. Locale-specific code pages have, essentially, been
superseded by unicode so I don't expect any changes in this area but whether
what amounts to legacy support will continue is anybody's guess.
 
K

Klaus Linke

It could also be a bit problematic if you'd ever want to use the macro
internationally.
It would likely still run, but since those upper-ASCII characters are
different in different code pages, the variable names would read
differently.

Klaus
 
K

Klaus Linke

It would likely still run, but since those upper-ASCII characters are
different in different code pages, the variable names would read
differently.

Just read in some other newsgroup how it took some French guy ages to find
that é is problematic in the Japanese version.

:-/ Klaus
 
T

Tony Jollans

Interesting. I have never seen anything on this documented anywhere - and I
can easily imagine that code page differences could have an effect.
 
J

John Gunther

Tony, Klauss

Very interested to hear the report that "é is problematic in the
Japanese version".

Based on our discussions, I'm now planning to modify Invisible Basic so
that it RECOGNIZES 128-255 as valid characters in VBA identifiers if
they appear in the original (unobfuscated) code, but I'll play it safe
and only allow, a-z, 0-9 _ in GENERATED obfuscated variable names. A
bit more work to make this distinction, and it makes the obfuscated
code a little bigger, but since I can't be 100% sure introducing such
characters into already working code will not break it, this seems the
wisest course.

Your comments and information were very helpful in resolving this
problem so (unless you have a problem with me doing so) I'll mention
your assistance in documentation for the next Invisible Basic release.

John
 

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