What does the percent sign mean as part of the variable name?

I am just looking at some VB.NET code, and I came across this:

Dim var% 

Later var set to 0.

What is the purpose of the percent sign ( % )?

(google and SO search didn't help me)

+7
source share
3 answers

Dim varname% is the ancient BASIC syntax for " varname is an integer". This was a very long time in the history of the BASIC family and is supported in Visual Basic.NET (although I personally would not recommend it - it can be quite opaque as you discovered).

+12
source

This is short for Integer-type var declarations and has roots in the early, early days of BASIC (yes ... the old DOS BASIC school).

So this is:

 Dim var% 

equivalent to:

 Dim var As Integer 

Here is the actual MS documentation: https://support.microsoft.com/en-us/kb/191713

  % Integer & Long ! Single # Double $ String @ Currency 
+10
source

Inserting the% sign at the end of a variable name in Visual Basic indicates that it is an integer. This was used by programmers in the old days of VB, I'm not sure why it is still present in VB.NET. Do not use it in new code, as you know that in future versions of VB.NET it may disappear.

&: Long

%: Integer

'#: Double

!: Single

@: Decimal

$: String

+4
source

All Articles