470,599 Members | 1,438 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,599 developers. It's quick & easy.

appending I and % to Integers

could someone explain the following to me :

Appending the literal type character I to a literal forces it to the Integer
data type. Appending the identifier type character % to any identifier
forces it to Integer.
Nov 21 '05 #1
4 1518
This is what they mean:

Dim val1 As Integer = 5 'Normal
Dim val2 As Integer = 5% 'With %
Dim val3 As Integer = 5I 'With I

Note that the above sample is not useful because 5 is an interger by
default. But, for example, if you want to make sure that 5 is a single then
you could use this:

Dim val4 As Single = 5.0!

Hope that helps.
Lance
Nov 21 '05 #2
This is what they mean:

Dim val1 As Integer = 5 'Normal
Dim val2 As Integer = 5% 'With %
Dim val3 As Integer = 5I 'With I

Note that the above sample is not useful because 5 is an interger by
default. But, for example, if you want to make sure that 5 is a single then
you could use this:

Dim val4 As Single = 5.0!

Hope that helps.
Lance
Nov 21 '05 #3
John,
Appending the literal type character I to a literal forces it to the
Integer
data type. If you don't give a type on a numeric literal it defaults to Integer, you
can use a type character to ensure that it is specifically that type.

For example try the following, watching "value" in the Auto Watch window:

Dim value As Object

' Integer (32-bit integer) literals
value = 1
value = 2I
value = 3%

' Short (16-bit integer) literals
value = 1S

' Long (64-bit integer) literals
value = 1L
value = 2&

' Decimal literals
value = 1D
value = 2@

' Single literals
value = 1.0F
value = 2.0!

' Double literals
value = 1.0R
value = 2.0#

I normally favor the alpha character (I, S, L, F, R, D) over the special
character (%, &, !, #, @). The special characters are a hold over from
original Basic (pre Visual Basic).

The one I find missing is Byte literals.

Appending the identifier type character % to any identifier
forces it to Integer. Allows both of the follow to work with Option Strict On. I never use the
type characters on identifiers (the second line).

Dim x As Integer
Dim y%

As you can see you can use either I or % as a suffix on a numeric literal,
however you cannot use the I suffix on an identifier, as there is no way to
determine if the suffix is a type character or part of the identifier.

Hope this helps
Jay

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uP******************@TK2MSFTNGP10.phx.gbl... could someone explain the following to me :

Appending the literal type character I to a literal forces it to the
Integer
data type. Appending the identifier type character % to any identifier
forces it to Integer.

Nov 21 '05 #4
John,
Appending the literal type character I to a literal forces it to the
Integer
data type. If you don't give a type on a numeric literal it defaults to Integer, you
can use a type character to ensure that it is specifically that type.

For example try the following, watching "value" in the Auto Watch window:

Dim value As Object

' Integer (32-bit integer) literals
value = 1
value = 2I
value = 3%

' Short (16-bit integer) literals
value = 1S

' Long (64-bit integer) literals
value = 1L
value = 2&

' Decimal literals
value = 1D
value = 2@

' Single literals
value = 1.0F
value = 2.0!

' Double literals
value = 1.0R
value = 2.0#

I normally favor the alpha character (I, S, L, F, R, D) over the special
character (%, &, !, #, @). The special characters are a hold over from
original Basic (pre Visual Basic).

The one I find missing is Byte literals.

Appending the identifier type character % to any identifier
forces it to Integer. Allows both of the follow to work with Option Strict On. I never use the
type characters on identifiers (the second line).

Dim x As Integer
Dim y%

As you can see you can use either I or % as a suffix on a numeric literal,
however you cannot use the I suffix on an identifier, as there is no way to
determine if the suffix is a type character or part of the identifier.

Hope this helps
Jay

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:uP******************@TK2MSFTNGP10.phx.gbl... could someone explain the following to me :

Appending the literal type character I to a literal forces it to the
Integer
data type. Appending the identifier type character % to any identifier
forces it to Integer.

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by bucket79 | last post: by
17 posts views Thread by Grant Austin | last post: by
reply views Thread by John A Grandy | last post: by
18 posts views Thread by Paul Roberts | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.