Solved

Constants with & prefix and variables with % trailer

Posted on 2004-04-23
6
293 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

730 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