FANDOM


The Basics of Variables

the first thing to know is what is a variable?

a variable is a keyword or phrase that is linked to a value stored in the system's memory or an expression that can be evaluated.(1) For example, Total can mean the total of all results.

Types of Variables Edit

In VB.NET, there are 13 different variables types to choose from . They are:

  • Boolean
  • Byte
  • Char
  • Date
  • Decimal
  • Double
  • Integer
  • Long
  • Object
  • SByte
  • Short
  • Single
  • String

Boolean Edit

A Boolean is a variable that holds only true or false. Boolean uses 2 or 4 bytes depending on the platform it is used on. An example of this is:

BooleanEG

Example of Boolean

As you can see you just click one of the buttons and the answer will be displayed in the label with the border











This is the source code:

Public Class frmSandbox
    Dim Answer As Boolean
 
    Private Sub btnTrue_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTrue.Click
        Answer = True
 
        lblAnswer.Text = Answer
    End Sub
 
    Private Sub btnFalse_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnFalse.Click
        Answer = False
 
        lblAnswer.Text = Answer
    End Sub
End Class

Byte Edit

A Byte is a variable that holds numbers. Byte uses 1 byte of memory and has a range of 0 to 255. An example of this is below:

ByteEG

Byte Example

you simply enter between 0 and 255 and click the button to see it displayed.










This is the source code:

Public Class frmSandbox
    Dim Number As Byte
 
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Number = TextBox1.Text
 
        Label3.Text = Number
    End Sub
End Class

CharEdit

Char is a variable that holds a single character. Char uses 2 bytes of memory and has a range of 0 to 65535.

StringEdit

ReferencesEdit

(1) - Wikipedia - Variable(programming)