Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Constants with & prefix and variables with % trailer

Posted on 2004-04-23
6
Medium Priority
?
298 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 1000 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
Independent Software Vendors: 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 1000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Suggested Courses

610 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