Solved

Constants with & prefix and variables with % trailer

Posted on 2004-04-23
6
294 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

726 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