Form load ,show and hide properties,VB Datatypes and variables declaration
-
Upload
amanjot-singh-kahlon -
Category
Documents
-
view
226 -
download
0
Transcript of Form load ,show and hide properties,VB Datatypes and variables declaration
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 1/16
Form load ,show and hide properties
VB Datatypes and variablesdeclaration
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 2/16
Form (show and hide)
� Form an be loaded into memory using load <formname> orformname.show
� We can hide the form using formname.hide when we hide theform it remains in the memory
�When we unload <formname> then the form does not exists inthe memory even.
� There are two modes of the form <formname>.show <mode>
1.Modeless:It is the default mode that we can any form at runtime (we can specify 0) in mode.
2.Modal:In this mode the form which is selected takes the
control when it closed then only we can acess the other forms.Formname.show 1 or formname.show vbmodal
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 3/16
Datatypes In VB
� Boolean:this datatype take true or false value.
� Byte:this Datatype allows positive intergers formrange 0-255
� Currency:This datatype holds the values whichcan have four decimal places and 15 digits beforedecimal.
� Date:this datatype holds the date and time value.
�Double:hold numeric value it can hold the valuewith 14 digits after decimal.
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 4/16
� Integer:It hold the non fractional values integer in therange of -32768 to +32767.
� Long:If holds the integer value larger then integerdatatype.
� Object:special datatype that is used to hold and refertothe objects such as controls and forms.
� Single:another datatype for decimal values it hold upto 6decimal places.
� String:Datatype hold multiple characters it can have
numeric ,alphabets and other character.� Variant:it does not accepts string that is fixed length or
datatypes created by user.it is default datatype incase thedatatypes are not specified or unknown.
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 5/16
Declaration of variables
� A named Storage location whose contents can
be varied is called a variable.
�
A variable is associated with two things nameand its data type.
� Variable name refers to the value stored in it
and data type tells what type value can be
stored in the variable.� Dim variablename [as datatype][,variablename [as datatype]].
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 6/16
� Dim X ( a variable x is declared with data type
variant i.e it can hold value of any data type
except fixed length string and user defined
datatype)
� Dim y as integer ,z as integer
� Dim y,z as integer( wrong declaration)
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 7/16
Type declaration Symbols or
Characters
Dim <variablename> <type
declaration character>
Ex:dim a%
we need not use as clause wth
this method
Type Declaration
Symbol
Datatype
%
Integer
$String
@
currency
&
long
#
double
!
Single
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 8/16
Implicit and Explicit Variable
Declaration� Implicit declaration: The programmer just
need to type variable name into source code &
the variable is automatically created by the VB.
Eg. B=helloB contains String value hello & VB
automatically created B & selected a default
datatype .Disadvantage of implicit declaration is that
variant data type takes larger memory as
compare to other data types.
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 9/16
Explicit Declaration
� In this declaration it becomes mandatory to
declare the variable before there use .error
message is flashed incase variables are not
declared. In this case the programmer must
first name the variable & describe what type of
information will be contained within the
variable.
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 10/16
There are two methods :
1)By checking require variable declaration option in option dialogavailable tools menu.
2)By writing option explicit in general declaration.
Eg: Dim B As StringExplicit Declaration has 3 parts:
�The first part is a keyword that determines the SCOPE of
variable.
�The second part is the variable name that will be used in thesource code.
�The third part is the datatype of the variable that tells the
computer how much memory is required .
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 11/16
OPTION EXPLICIT1. To force variable declarations to be explicit i.e that each
varibale must be declared we use Option Explicit statement atthe module or form level in the general declaration section.
2. Is we don¶t use O.E all undeclared variables are of VARIANT
type unless the default type is otherwise specified.
3. It is used to avoid incorrectly typing the name of an existing
variable or to avoid confusion in code where the scope of the
variable is not clear.
Eg: Option Explicit
Dim R As integer
Private Sub Form_Load()
X=10
End Sub
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 12/16
SCOPE OF VARIABLE
1. Local
2. Static
3. Private
4. Public
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 13/16
Two method for option explicit
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 14/16
Fixed length and Variable Length
String
� Fixed length string declaration:
Dim firstname as string * 15
�Variable Length String Declaration:
Dim Firstname as string
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 15/16
Val() and Str () Function
� Val():val function converts a string value to
equivalent number.
�
Str():str function converts the function intoequivalent string.
8/7/2019 Form load ,show and hide properties�,VB Datatypes and variables declaration
http://slidepdf.com/reader/full/form-load-show-and-hide-propertiesvb-datatypes-and-variables-declaration 16/16
Defining Named Constants
� Const <constname> = <value>
� Constants name should be written in upper
case characters.