[Tutorial] 5# - Dim Statement | Hard

Posts 1–2 of 2 · Page 1 of 1
[Tutorial] 5# - Dim Statement | Hard
In Visual Basic variables is called "Dim Statement".

Dim statement is one thing you must learn to get somewhere in coding.
Quote Originally Posted by MSDN
Dim Statement: Declares and allocates storage space for one or more variables.
In Visual Basic you can use this in many diffrent ways and im going to show/teach you the most used variables.

String
[php]Dim Message as String = "Message HERE"

msgbox(message)[/php]

or:

[php]Dim Message as String = textbox1.text

msgbox(message)[/php]

Boolean
Boolean is a value of only True or False.

[php]Dim A As Boolean = True

If A = True Then
MsgBox("A is " & A.ToString)
End If[/php]

Byte


Quote Originally Posted by MSDN
Byte Data Type
Holds unsigned 8-bit (1-byte) integers ranging in value from 0 through 255.
Use the Byte data type to contain binary data.

The default value of Byte is 0.

[php]Dim BinaryData as byte[/php]

Char
Quote Originally Posted by MSDN
Holds unsigned 16-bit (2-byte) code points ranging in value from 0 through 65535. Each code point, or character code, represents a single Unicode character.

Use the Char data type when you need to hold only a single character and do not need the overhead of String. In some cases you can use Char(), an array of Char elements, to hold multiple characters.

The default value of Char is the character with a code point of 0.
[php]Dim VarChar As Char[/php]

Decimal

Quote Originally Posted by MSDN
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).
[php]Dim Dec As Decimal = 5,3
msgbox(dec)
[/php]

Integer
The Visual Basic Integer variable type is used to store whole numbers between -2,147,483,648 and 2,147,483,648. The Integer variable cannot be used to store numbers containing decimals.

[php]Dim IntegerNumber as integer = 5

msgbox("Number is" & integernumber.tostring)
[/php]


Credits: Techotopica, me, MSDN
Quote Originally Posted by Techotopica
Boolean Variable

The Visual Basic Boolean variable type holds a value of true or false. Internally these are actually stored as the numbers 1 and 0 representing true and false respectively. Boolean values are used in conditional statements to decide whether particular parts of Visual Basic code should be executed or not (see Visual Basic Flow Control for more details on conditional statements).
Char Variable


The Char variable type holds a single character (such as the letter 'B'). The value of a Char can be any character. Internally, a number in the range 0 to 65,553 is used to represent the character value as defined by the ASCII table. As an example when the letter 'Z' is assigned to a Visual Basic Char variable, the number 90 is actually stored in the variable location.
Byte Variable

A Byte variable holds a positive number in the range 0 to 255. Because of the limited range, Byte variables should be used with caution. An attempt to assign a negative value or a value greater than 255 to a Visual Basic Byte variable will result in an error.
Date Variable

The Visual Basic Date variable type holds a date and time value. Dates are declared in the form #mm/dd/yyyy#. For example, May 23, 2007 would be declared as #5/23/2007#. Visual Basic provides a number of mechanisms for working with Date variables (such as calculating a date six months from today's date). These are covered in the Working with Dates and Times in Visual Basic section of this book.
Decimal Variable

The Decimal variable type can store either a whole number or a decimal number up to 29 decimal places. When working with whole numbers, however, it is recommended that the Integer variable type be used as this is more memory efficient than the Decimal variable type.
Double Variable

The Visual Basic Double variable is used to store either very large numbers, or small numbers requiring more than 28 decimal places. To be precise Visual basic Double variables can store positive numbers in the range 4.94065645841246544E-324 to 1.79769313486231570E+308 and negative numbers from -1.79769313486231570E+30 to -4.94065645841246544E-324.
Double variables are typically used when developing scientific applications using Visual Basic and, as such, are generally not used by the average developer.
Integer Variable

The Visual Basic Integer variable type is used to store whole numbers between -2,147,483,648 and 2,147,483,648. The Integer variable cannot be used to store numbers containing decimals.
Object Variable

The Object variable is a catch-all variable type which can be used to store a value of any data type. Because of this flexibility, an Object variable will typically reserve more memory than is needed for most variable types. For this reason, it is more efficient to use the correct variable type for the value you need to store (such as Char for a character or Integer for a whole number) rather than use the Object variable type.
Long Variable

The Visual Basic Long variable type is used to store whole numbers ranging from -9,233,372,036,854,775,808 to 9,233,372,036,854,775,807.
Short Variable

A Short variable in Visual Basic stores a whole number in the range -32,768 to 32,767.
String Variable

The String variable type stores multiple characters that make up words or sentences. String variables are encapsulated in double-quotation marks ("). For example "Hello" is a string, as is "Hello, this is a test".
Visual Basic provides a number of mechanisms for working with and manipulating strings as covered in the Working with Strings in Visual Basic chapter of this book.
End of tutorial

-Hej
Looks great, if i ever get into VB ill come back to these.
Posts 1–2 of 2 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us