Wednesday, November 4, 2015

Datatypes, Variables, Operators








Subtype

Note: If the variable is not declared, the default data type it would be assigned to is 'Variant' and the default value of Variant is empty/null.


Data types:

Description
EmptyVariant is uninitialized. Value is 0 for numeric variables or a zero-length string ("") for string variables.
NullVariant intentionally contains no valid data.
BooleanContains either True or False.
ByteContains integer in the range 0 to 255.
IntegerContains integer in the range -32,768 to 32,767.
Currency-922,337,203,685,477.5808 to 922,337,203,685,477.5807.
LongContains integer in the range -2,147,483,648 to 2,147,483,647.
SingleContains a single-precision, floating-point number in the range -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values.
DoubleContains a double-precision, floating-point number in the range -1.79769313486232E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values.
Date (Time)Contains a number that represents a date between January 1, 100 to December 31, 9999.
StringContains a variable-length string that can be up to approximately 2 billion characters in length.
ObjectContains an object.
ErrorContains an error number.

Type Declaration Characters: Are the symbols that represents data types.

Identifier type characterData typeExample
%IntegerDim L% 
&LongDim M& 
@DecimalConst W@ = 37.5 
!SingleDim Q! 
#DoubleDim X# 
Note: Dim x% is same as Dim x as Integer.

User Defined types:

Combine variables and fundamental data types to create user-defined data types.

Use Type and End Type statements in the declaration section to create a user defined data types.


In the above example EmpDet is user defined data type that has Byte and Integer variables.
And in the below screen, Student type is used while declaring st1 variable.?????

Implicit and Explicit Declaration of variable:

1. If the variable is declared using Dim it means, it is explicit declaration here you have to mention the data type of the variable that you using
2. Implicit declaration is when you use the variable without declaring it, but the type of variable depends on the value assigned to it.

Scope of the variables:

Public and Private.


Static Variables??
Static variables are used to retain the value of the variable even after the procedure has finished the execution.
syntax: Static <var name> as <data type>

Loop structures in VB include:

1. For .... Next
2. Do...While
3. While .... Wend??
4. With ....End With ??











1 comment:

  1. In the above example for Student User defined type, how st1.name is used???? throw some light on the same....

    ReplyDelete