Guide to Game Development/The Programming Language/VB.NET/Variables
Different types of Variables
[edit | edit source]This a table of all the different data types that a variable can be, you don't need to remember all of these, just a few.
For now, just try and remember these:
- Integer
- Double
- Boolean
- Char
- String
Whole Numbers | ||
---|---|---|
The key thing here is to select the smallest one that you can run your program with to save resources, this is especially important with game development as a lot of RAM will be used. | ||
Byte | 8-bits | Unsigned byte: Can hold numbers in range:
0 to 255 (same as 0 to ) |
SByte | 8-bits | Signed byte: Can hold numbers in range:
-128 to 127 (same as to ) |
Short | 16-bits | Signed short: Can hold numbers in range:
-32,768 to 32,767 (same as to ) |
UShort | 16-bits | Unsigned short: Can hold numbers in range:
0 to 65,535 (same as 0 to ) |
Integer | 32-bits | Signed Integer: Can hold numbers in range:
-2,147,483,648 to 2,147,483,647 (same as to ) |
UInteger | 32-bits | Unsigned Integer: Can hold numbers in range:
0 to 4,294,967,295 (same as 0 to ) |
Long | 64-bits | Signed Long: Can hold numbers in range:
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 (same as to ) |
ULong | 64-bits | Unsigned Integer: Can hold numbers in range:
0 to 18,446,744,073,709,551,615 (same as 0 to ) |
Decimal Numbers | ||
The key thing here is to select the smallest one that you can run your program with to save resources, this is especially important with game development as a lot of RAM will be used. | ||
Single | 32-bits | single-precision floating-point numbers ranging in value from -3.4028235E+38 through -1.401298E-45 for negative values and from 1.401298E-45 through 3.4028235E+38 for positive values[1]. |
Double | 64-bits | double-precision floating-point numbers that range in value from -1.79769313486231570E+308 through -4.94065645841246544E-324 for negative values and from 4.94065645841246544E-324 through 1.79769313486231570E+308 for positive values[2]. |
Decimal | 128-bits | Holds signed 128-bit (16-byte) values representing 96-bit (12-byte) integer numbers scaled by a variable power of 10. The scaling factor specifies the number of digits to the right of the decimal point; it ranges from 0 through 28. With a scale of 0 (no decimal places), the largest possible value is +/-79,228,162,514,264,337,593,543,950,335 (+/-7.9228162514264337593543950335E+28). With 28 decimal places, the largest value is +/-7.9228162514264337593543950335, and the smallest nonzero value is +/-0.0000000000000000000000000001 (+/-1E-28)[3]. |
Text | ||
Char | 16-bits | Can hold one of 65536 Unicode character. |
String | 16-bits per character | Can hold many of the 65536 Unicode characters available in an order. |
Boolean | ||
Boolean | 1-bit | Holds a True/False state (0 or 1), one binary digit. |
Miscellaneous | ||
Date | 64-bit[4] | Can hold one date and time. |
Declaration of a variables
[edit | edit source]You can create a variable with the following format:
Dim NameOfVariable As DataTypeOfTheVariable
Examples:
Dim Num1 as Integer
Dim Num2 as Double
Dim Bool1 as Boolean
Dim Char1 as Char
Dim Str1 as String
If you want to make many variables of the same data type it can be done like so:
Dim NameOfVariable,NameOfVariable2,NameOfVariable3,... As DataTypeOfTheVariables
Example:
Dim Num1, Num2, Num3 as Integer
Setting the value for a variable
[edit | edit source]There are two way which you can set the state of a variable:
- On the declaration line
- Standalone statement
- Standalone statement mixed with math (will be shown at a later date).
Example of setting value on a declaration line:
Dim Num1 as Integer = 5
Example of setting value as a standalone statement:
Num1 = 5
Example:
This code:
Dim Num1 as integer = 10
Console.WriteLine(Num1)
Num1 = -4
Console.WriteLine(Num1)
'Stopping the console from closing
Console.ReadLine()
Will output:
10 -4
Naming conventions
[edit | edit source]When naming variables, you should name them using lower camel case[5]
thisIsWhereYouWriteVariablesLikeThis
itIsLowerBecauseTheFirstLetterIsLowerCase