Solved

Constants with & prefix and variables with % trailer

Posted on 2004-04-23
6
290 Views
Last Modified: 2010-05-02
Hi,

As I'm broadening my VB knowledge, I came across things like this a couple of times:
Private Const GENERIC_READ = &H80000000

this is usually used with API calls it seems


and things like this:
For i%=0 to 100
    Array(i%) = "Lipsum"
Next i%


Now I suppose the first has something to do with hexadecimals. Just a wild guess, but I'd like to know more about that.
The second one is a puzzler. I used it a couple of times myself, to dynamically create control arrays, but what it means... You got me.
0
Comment
Question by:boeman
6 Comments
 
LVL 11

Expert Comment

by:jmwheeler
ID: 10899002
You got it.  &H is for hexadecimal.  The % I believe is for long integer's.
0
 
LVL 43

Assisted Solution

by:TimCottee
TimCottee earned 250 total points
ID: 10899067
Hi boeman,

&H is hex

Suffixes:
& is long integer
% is integer
$ is string
! is single
# is double

There may be some others but these are the most common.

They are not necessarily required when you explicitly declare a variable but can come in handy when you need to ensure that a specific datatype is used:

Msgbox 32000 + 5000
For example will generate an overflow error because the result of adding these two implicit integers together is larger than the integer datatype can handle.

Msgbox 32000& + 5000
will not because one of them is a long and therefore the result is implicitly cast to a long.

Tim Cottee
Brainbench MVP for Visual Basic
http://www.brainbench.com
0
 
LVL 6

Expert Comment

by:mmusante
ID: 10899076
% is for Integer
& is for Long
$ is for string
# is for Double
! is for single
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Author Comment

by:boeman
ID: 10899236
Thanks TimCottee, that part of the question is clear for me now.

jmwheeler: for the &H, &D etc, it stands for hexadecimal and decimal etc.. But I need some kind of explanation or a nice example.

Tim is going to be rewarded with half of the points for trailing sings.
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 250 total points
ID: 10899391
boeman,

This is one of those questions where perhaps there is no definitive answer. I guess the closest I could offer is this:

& as suffix represents a long integer so & as a prefix also signifies a long integer but the next letter (H, O, D) identifies the base in which the following "number" is represented.

9 &O11 &H9
15 &O17 &HF
16 &O20 &H10
20 &O24 &H14
255 &O377 &HFF

Show the same numbers in decimal, octal and hexadecimal representations. I have never used or seen any code examples using Octal but the functionality is there!

Tim.
0
 
LVL 3

Author Comment

by:boeman
ID: 10900129
OK, thanks for rectifying this issue.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now