Solved

Constants with & prefix and variables with % trailer

Posted on 2004-04-23
6
289 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

758 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

14 Experts available now in Live!

Get 1:1 Help Now