Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

Datatypes in VB.

net:
 The data types of a programming element refer to what kind of data it can hold and how it
stores that data.
 A data type, in programming, is a classification that specifies which type of value a variable
has and what type of mathematical, relational or logical operations can be applied to it without
causing an error. A string, for example, is a data type that is used to classify text and an
integer is a data type used to classify whole number

Types of data types in vb.net:


1: Boolean data type.

2: integer data types.

3: Floating Points number.

4: String and chars.

5: Date.

1) Boolean:
A Boolean stores a value indicating True or False. It can be used as an expression in
an If-statement. It can also store the result of an expression. Booleans are used
throughout VB.NET programs.

“Dim values as Boolean”

Value = true

Or

Value = False.

Dim login as Boolean.

Username SBK Password = ‘BSCS’

Login = true

2) Integers:
Integer is a core type in VB.NET programs. It is the default numeric type. Usually
loops use the Integer type for their indexes. An Integer is declared with a Dim
statement. It can store positive values, such as 1, and negative values, such as -1.
In integers we take whole number.

Example:we make a program where you want that users enter their age so, when they enter
their age you need to define variables.

Dim age As byte.


Age=24

3) Floating Points Numbers :


If sometimes user inputs floating point number so, they use floating point numbers data types.
for example: we make a program where students want to enter their percentage

Dim percentage as single

Percentage=78.9

Decimal values cannot be stored in integer because in integernumbers we can store only whole
number that is without decimal point.

4) Strings and Chars :


String is a data type representing textual data in computer program.The Char type is
useful. Chars are value types. This means they are located in the bytes on the
evaluation stack. You can get individual Chars from a String variable.

Example:

Dim username as string

Username = “Fatima”

Dim city as string

City = “Quetta”

Dim school name as string

School name = “ SBK“

5) Date:
A date is value type which contains date values, time values, or date and time values.

Dim today as date

Today = now()

Data Types Available in VB.Net


VB.Net provides a wide range of data types. The following table shows all the data
types available:

Data Storage Allocation Value Range


Type

Boolean Depends on implementing True or False


platform
Integer 4 bytes -2,147,483,648 through 2,147,483,647
(signed)

Decimal 16 bytes 0 through +/-


79,228,162,514,264,337,593,543,950,335
(+/-7.9...E+28) with no decimal point; 0
through +/-
7.9228162514264337593543950335 with
28 places to the right of the decimal

Double 8 bytes
-1.79769313486231570E+308 through -
4.94065645841246544E-324, for
negative values

4.94065645841246544E-324 through
1.79769313486231570E+308, for
positive values

Single 4 bytes
-3.4028235E+38 through -1.401298E-45
for negative values;

1.401298E-45 through 3.4028235E+38


for positive values

String Depends on implementing 0 to approximately 2 billion Unicode


platform characters

Char 2 bytes 0 through 65535 (unsigned)

Date 8 bytes 0:00:00 (midnight) on January 1, 0001


through 11:59:59 PM on December 31,
9999

Operators in VB.Net:
An operator is a symbol that tells the compiler to perform specific mathematical or
logical manipulations. VB.Net is rich in built -in operators and provides following types of
commonly used operators:

 Arithmetic Operators

 Comparison Operators
 Logical/Bitwise Operators

 Assignment Operators

 Concatenation

Arithmetic Operators
This table shows all the arithmetic operators. Assume variable A holds 2 and
variable B holds 7, then:

Operator Description Example

^ Raises one operand to the power of another B^A will


give 49

+ Adds two operands A+B


will give
9

- Subtracts second operand from the first A - B will


give -5

* Multiplies both operands A * B will


give 14

/ Divides one operand by another and returns a floating B / A will


point result give 3.5

\ Divides one operand by another and returns an integer B \ A will


result give 3

MOD Modulus Operator and remainder of after an integer B MOD A


division will give
1

Comparison Operators
This table shows all the comparison operators. Assume variable A holds 10 and
variable B holds 20, then:
Operator Description Example

= Checks if the values of two operands are equal or not; if (A = B)


yes, then condition becomes true. is not
true.

<> Checks if the values of two operands are equal or not; if (A <> B)
values are not equal, then condition becomes true. is true.

> Checks if the value of left operand is greater than the (A > B)
value of right operand; if yes, then condition becomes is not
true. true.

< Checks if the value of left operand is less than the value of (A < B)
right operand; if yes, then condition becomes true. is true.

>= Checks if the value of left operand is greater than or equal (A >= B)
to the value of right operand; if yes, then condition is not
becomes true. true.

<= Checks if the value of left operand is less than or equal to (A <= B)
the value of right operand; if yes, then condition becomes is true.
true.

Logical/Bitwise Operators
This table shows all the logical operators. Assume variable A holds Boolean value True
and variable B holds Boolean Value False, then:

Operator Description Example

And It is the logical as well as bitwise AND operator. If both the (A And
operands are true, then condition becomes true. This B) is
operator does not perform short-circuiting, i.e., it False.
evaluates both the expressions.

Or It is the logical as well as bitwise OR operator. If any of (A Or B)


the two operands is true, then condition becomes true. is True.
This operator does not perform short-circuiting, i.e., it
evaluates both the expressions.

Not It is the logical as well as bitwise NOT operator. Use to Not(A


reverses the logical state of its operand. If a condition is And B) is
true, then Logical NOT operator will make false. True.

Xor It is the logical as well as bitwise Logical Exclusive OR A Xor B


operator. It returns True if both expressions are True or is True.
both expressions are False; otherwise it returns False. This
operator does not perform short-circuiting, it always
evaluates both expressions and there is no short-circuiting
counterpart of this operator.

Name = Fatima

F/name = Sadiq Ali

Assignment = Visual programming

Submitted to = Ma’am Nausheen

Enroll = S14/BSCS/49

Semester = 7th

You might also like