Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating type specifiers

Status
Not open for further replies.

peter11

Instructor
Mar 16, 2001
334
US
I have been told that the "%" is a "type specifier". and it is a leftover from pre-Visual versions of Basic.

How would update the following code for VB6?
Dim ratx%(2, 2), raty%(2, 2), ratpos%(2, 2)
 
You can still use the type specifiers, of course, but if you want to update your code, it would look like this:
Dim ratx(2, 2) As Integer, raty(2, 2) As Integer, ratpos(2, 2) As Integer

The type specifiers and corresponding data types are:
% - Integer
& - Long
! - Single
# - Double
$ - String
Other data types (e.g. Date, Boolean) were never assigned a type specifier.

Type specifiers occur in 5 contexts that I can think of.
1. In Dim statements; translate as shown above.
2. After variables names elsewhere in code; just remove the type specifier character.
3. In Const statements, after the constant value; translate as follows:
Const Pi = 3.14159# -> Const Pi As Double = 3.14159
4. (Rare) After function names in their declarations; translate as follows:
Function F!(Value As Integer) -> Function F(Value As Integer) As Single
5. (Rare) After function names in function calls; just remove the type specifier character.

Rick Sprague
 
Just for completeness and history: There also is a Deftype statement that you can place in the General Section of a Module and that types a variable, based on its initial character.

DefStr A - Q defines all module's variables that start with letters A through Q as Strings.

Other Deftypes are: DefBool, DefByte, DefInt, DefLng, DefCur, DefSng, DefDbl, DefDate, DefObj and DefVar.

This too is history: The statement is no longer supported (and for good reasons) in VB.NET
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top