Visual Basic 6.0

 (Q) What is Visual Basic? Explain in briefly.
Introduction:- Visual Basic is an event driven programming language,where we have to program according to the certain actions performed by the users.


In 1960's , John Kemny developed a programming language named as BASIC(Beginners All Purpose Symbolic Instruction code), which was mainly used to generate interest among the people towards programming.In late 1980's, the concept of GUI (Graphical User Interface) was introduced. Microsoft realizes the need of windows based programming language,so it introduces its own new programming language named Visual Basic in 1991.Here the visual word refers to the windows. It means Visual Basic is a tool that allows us to develop windows applications.

Visual Basic 6.0 is not a fully object oriented programming language,while VB.net is a fully object oriented programming language.

 VB. 6.0 is an object based language rather than a fully object oriented language. An object based language doesn't support inheritance, polymorphism, Subtyping,etc.It has in-built object.

                            In VB we can use class and object,but can't inherit one class from another class because VB is a object-based language doesn't support Inheritance.

(Q) Why Visual Basic is called an event driven programming language?

Visual basic is an event driven programming language, because we need to write code in order to  perform some tasks in response to certain events.



 In event based paradism, each feature included within the program is activated only when the user responds to a corresponding object (i.e. an icon, a checkbox, an optionbutton, a menu selection,etc) within a user interface. The programs response to an action taken by the user is returned to as an event,but it is the program response that actually defines the event.
      Visual Basic(VB) is called as event driven language,because it supports event. Event driven means the code remains idle until called upon to respond to some event(Button pressing,menu selection,.....etc). visual Basic is governed by an event processor. Nothing happens until an event is detected. Once an event is detected, the code corresponding to that event(event Procedure ) is executed. program control is then returned to the event processor.


Note:- Visual Basic also support IDE(Integrated Development Environment).
           Visual Basic is also known as RAD(Rapid Action Developed) language because we can                       developed a program or software very easily as well as in very less time

(Q) What are the features of Visual Basic?
 Ans:- There are different type features of Visual Basic, which explain below.
  *GUI Interface- VB is a graphical user interface(GUI) language. This means that a VB program will always show something on the screen that the user can interact with (usually via mouse and keyboard) to get a job done.

*IDE:- VB uses integrated development environment(IDE) which is easier for the user to minimize code writing .The IDE includes a code editor, tools windows,properties windows,etc .
*Modularization- It is considered good programming practice to modularize your programs. small modules clearly indicates that what comes into the module and what goes out. It makes a program easy to understand and update. VB forces user to program in a modular fashion because each GUI item contains part of the code.
* powerful database access tools
*Useful debugger and error handling facilities.
* Full array of mathematical, string  handling and graphics functions.
* can handle fixed and dynamic variable and control arrays
* sequencial and random access file support
* clipboard and printer access.
* support advanced features such as tools to develop ActiveX and internet controls.
*package and deployment Wizard makes distributing your applications simple.


#Software specification for Visual Basic:-

from 1991, there are several version of  visual basic is available in the market . The one most popular version of Visual Basic is 6.0. To use VB 6.0 , we have to install Visual Studio 6.0 which is a collection of several visual softwares like Visual C++, Visual Foxpro, Visual Basic , etc.
  After installation, we can open Visual Basic as follows:-
     
                  Start Programs Microsoft Visual Studio 6.0  Microsoft Visual Basic 6.0

Fig:- The New Project Window
                                  
                  After Selecting new, existing or recent tab, we have to click on Open button and after that                     following window will appear:-

                  
Fig:-The initial Visual Basic Screen





(Q) What is Project? How to create new project?
       Ans:- In visual Basic , program files are known as Project. We can open only one project at a              time . A project can contain several forms but by default one form is provided with every new            project. We can add forms in project as our need. The extension of VB project is .vbp.  
      
        Steps to create new project:-
         
           When program starts , Project box appearSelect Standard.EXE   Click on Open                             button   Project window appears. OR  File   New Project    Select standard EXE                     Click on Ok buttons Project window appears.

         🔺 A project is made up of:-
         
           ➤ Forms
           ➤Controls
           ➤Properties
           ➤Methods
           ➤Event Procedures
           ➤General Procedures
           ➤Modules

*Forms:- The form is the most important visible object, without it no control can be displayed.
      A form is define as a container which can hold several controls to design an interface.A form is also defined as a layout on which we can place the control at desired location  to create an interactive interface.
                A project can have more than one form simultaneously , but by default one form is provided with every new project. The user can add any number of forms to the project of his application by pressing:- add form from project menu.

Every form of a project can also be saved by a name with extension .frm.

A form consist of several dots(.) which is known as grids. It represents a particular Co-ordinate internally. Any control is placed on the grid position only.
Fig:- The Form



Toolbox:-
                It is also a container which contains several controls of Visual Basic and that control are used to design a form. To use any control in our project,we have to place that control on the form by using drag-drop feature.
                                      The Visual Basic controls are divided into two types:-

(i) Intrinsic controls
(ii)ActiveX controls

Intrinsic Controls:-
                                   Those Controls which are added in the toolbox by default are known as intrinsic controls.Some important intrinsic controls are as follows:-


*Pointer                                                                   

*Label                                                                      *VScrollBar
*Textbox                                                                  *Timer*
*PictureBox                                                             *DriveListBox
*Frame                                                                     *DirListBox
*CommandButton                                                    *FileListBox
*Checkbox                                                               *Shape
*OptionButton                                                         *Line
*ComboBox                                                            *Image
*ListBox                                                                  *Data
*HScrollBar                                                            *OLE




Fig:The Visual Basic Toolbox with all the intrinsic controls

Note:-  The Toolbox reside within View menu of  the menu bar.

  
*Contorls:-
      Controls are define as a predefined unit which has some properties and events.The controls are defined as a class when they are available in the toolbox.When it is placed on the form thenit is known as the object of that control.All the objects of the same class have the some properties.The value of properties may be same or different.
  Since,VB is an event driven programming language,So every control also hava some events.


*Properties Window:-
                                   The properties window shows the properties of currently selected control on the form.These properties are characteristics (Such as size visible,color,font,etc.) of the selected object and it provides an easy way to set properties.Form is also considered as a control and it also have some properties.
               We can list the properties of the selected             object in two views-Alphabetic and categorized.
  


  
 Fig :-properties Windows 



    * The left part of properties window shows the property name and the right part shows the            property value regarding each property.
                                               
    * We can change the only right part i.e. property value. 

    *The properties of any control can be changed either from properties window at design time or              from code window during coding .

    *If we chaange the properties of any control at sesign time then it will effect immediately i.e.                before execution but if we change the properties at the code window then it will be effected run          time.

    * We have to follow the following syntax to change the properties of any control at code window.

                                                       Controlname.property=Value
     Ex:-
                                             Label1.Caption="Welcome"
                                             Text1.visible=False
                                             Label1.backcolor=vbred

      Note:-
               The properties window is available in the view menu or we can press F4 to show the                              properties  window.



*Project Explorer:-
       This windows shows the project and its form in the hierarchical format. It means, We can say that this window shows the details of our project , it shows that how many forms are used in our project and their sequences.

The project explorer is also used to move from design window of selected form.It has three buttons.


 (i) View Code Button

 (ii)View Object Button


 (iii)Toggle Folders Button


     
Fig:-Project Explorer Window


(i)View Code Button:-

                      This button is used to open the code window of selected Form.The code window is used to write the program code regarding the controls. For each from there is a separate code deitor window.It is appear as follows:-

   
              
Fig:-Code Editor Window

The left part of code window shows the listing of the controls which are placed on the form and the right part shows all the events associated with the selected control from the left part.

             
    We can select any one controls from the left part and any one event of selected controls from the right side at a time.Visual Basic automattically create a procedure by associating the control name and its selected event.

(ii)View Object button:- It is used to move into the designed window of selected form.Designed window is used to create an interface or to modify an existing interface.
  

(iii) Toggle Folders Button:- It is just like ON/OFF Switch.It is used to show the listing of projects either in expand or collapsed form.


*Form Layout Window:-
                                     The Form layout window allows you to position the location of the form at run time relative to the entire screen using a small graphical representation of the screen.
 Fig:-Form Layout Window










Running Visual Basic Program:-

                                             
                                                                  Visual Basic is an interpreter based programming language so, the code written by programmer is check line by line automatically during the coding. To run the visual basic program we can either press F5 or we can choose start button (➧) from the standard tool bar. We can press (Shift +F8) for step over running.


 (Q) What is Operator? what are the different types of Operator  in VB? Explain with example.

 Ans:-Visual Basic also support some operators to perform various operations on data. Operators are            predefined symbols that perform specific operation on their operands.

An operator may have one or two operands.Those operators that work with only one operand are called unary operators. Those who work with two operands are called binary operators.
    visual Basic support following operators.:-
      (i)Arithmetic operator.

      (ii)Relation/Comparison operator

      (iii)Logical operator.

*Arithmatic Operator :-
                These operators performs general arithmetic operations on their operands. There are following arithmetic operators in VB:-

                         Operator                      Operation      

                              +                              Addition
                                                                  Ex:- 5+3=8
                                                           Subtraction
                                                                  Ex:- 5-3=2
                              *                               Multiplication
                                                                  Ex:-5*3=15
                               /                                Division
                                                                  Ex:- 15/4=3.75
                               \                                 Integer Division (Discard the decimal places)
                                                                   Ex:- 15\4=3
                             Mod                            Modules(Returns remainder after division)
                                                                    Ex:- 15 Mod 4 = 3 
                               ^                                exponentiation
                                                                    Ex:- 2^4 =16

Note:-  The  +(plus) and -(Minus) signs can be addition and subtraction operators as well as unary sign operators. The + sign is used to indicate that the no is positive while the - sign is used to change the sign of a value.
 Note:-              In visual Basic , we have two operators for string concatenation :- The +(Plus) operator and the &(ampersand) Operator.

Ex:- "Visual " + "Basic"   →   VisualBasic
         
        "Visual"& "Basic"       VisualBasic.

*Relational /Comparison Operator:-
  
     The relational operators are used to check relation between two operands. These operators always returns the result in a boolean value(True or False) . These operators compare two operands and after comparison returns True if the relation exists otherwise returns False.

  There are following relational operators in VB.



Visual Basic                              C                                            Meaning
Notation                                Notation

     >                                            >                                           Greater than
     <                                            <                                            Less than
     >=                                         >=                                           Greater Than or Equal to
     <=                                          <=                                            Less Than or Equal to
     =                                             ==                                           Equal to
    < >                                           !=                                          Not equal to




Ex:- a=25,b=20,c=25

a>b →True                    b<=c → True
a<b →False                    a=b  → False
a>=b → True                 a=c  → True
b>=c  → False                a< > → True
a<= b → False                a< > → False

Note:- We can also compare two strings using relational operator. to compare two strings,We compare each character from left to right according to their ASCII Value. If the first characters are equal ,we compare the next ones.

[Upper Case Letters    < Digits                  < Lower Case Letters]

("A"< "B" <"c"<.......<"Z") <("0" <"1"<.........<"9") < ("a"< "b" < "c" <.......< "z")

Ex:- "A" < "a"  →True
        "B" < "b"  → False
         "ab" > "aa" → True
         "teach" < "teacher" →True
         "pen"  <= "pen"  → True

     

*Logical operator:- 


  Like relational operator ,logical operator also returns the result in the form of boolian value(true or false). There are following logical operator in visual Basic:-

Operator             operation
And                        Logical AND
Or                           Logical OR
Not                        Logical NOT

And:-It is used to combine two or More conditions and produce result according to Logical AND operation. The AND operator returns True if its both operands are True Otherwise it returns False. In And operator, if any one operand is false then the final result will be False.

Ex:- x=10,y=30,z=20

X<Y And Y>Z     →True
(Here both conditions are True)

X < Y And Y< Z    → False

X>Y And  Y>Z      →False

OR:- It is used to combine two or More conditions and produce result according to Logical OR operation. The OR operator returns True if either of its operand is True Otherwise it returns False.

*Any one operand is True then the final result will be true.

*All operands false then the final result will be false.

Ex:- Ex:- x=10,y=30,z=20

        X<Y OR Y<Z     → False
        X>Y or    Y< Z     → True
        X>Y Or    Y>Z      → True

NOT:- It is used before a condition or group of condition an d converts the final result .The not operator simply negates the result.

     True  → False
     False → True

Ex:- X=10,Y=30,Z=20

r= Not (n<=y And Y>=Z)
      
      r=False
C= (Not(x<y)) or (Not(y<z))

    c=True




Data Type:



          Datatypes are predefined keywords which are used to define he type of data Store by a                        variable.It also defines that how much memory is required for a variable.
   
              visual basic supports various types of datatypes. Some important daatypes are as follows:-


Data Types                Storage Size                    Range
* Byte                            1 byte                          0 to 255
* Integer                         2 bytes                        -32768 to 32767
*Long                            4 bytes                         -2147483648 to 2147483647
* Single                          4 bytes
*Double                        8 bytes
*Currency                     8 bytes                        -9227203685477.5808 to 922337203685477.5807
*Decimal                       14 bytes
*Boolean                       2 bytes                            True or False
*Date                             8 bytes                            January 1,100 to December 31,9999
*Object                          4 bytes                            Any object referance
*String                          length of string               0 through 65535 Characters
  (Variable length)
*String                          10 bytes +                       0 to approximately
                                      String length                  2 billion (2^31) 
                                      (2 bytes per                       Unicode characters
                                          characte)

*Variant                          16 bytes                        Any value as large as Double
(Numeric)

*Variant                         22 bytes+                           0 to approximatly
                                      string length                        2 billion Unicode
                                      (2 bytes per char)                 character



*Description about some visual basic datatypes:-



Byte:- The datatype accupies one byte (8 bits) of memory. It holds on eight bit unsignes integer,its value can range from 0 to 255. An uninitialized byte variable is assigned by a value 0(zero)



Integer:- 

 It occupies 2 bytes (16 bits) of memory. It holds 16-bits signed integer that range from -32767 to 32767. The initial valuew of integer datatype is 0(Zero).




Long:- It occupies 4 bytes(32 bits) of memory. The long datatype holds 32- bits signed integer values in the range from -2147483648 through 2147483647. An uninitialized long variable is automatically set equal to 0(Zero).



Single:-
        It occupies 4 bytes of memory. The single datatype holds 32 bit signed single precision floating      point numbers ranging in value from -3.402823E+38 to -1.401298E-45 for negative value and from -1.401298E-45 to  3.402823E+38 for positive values. A single precision floating point value has seven decimal digits of precision. Uninitialized single variables are automatically set equal to 0(Zero).

Double - It occupies 8 bytes of memory. Double variables can hold a double precision floating point value in the range -1.79769313486232E+308 to -4.94065645841247E-324 for negative values and  -3.402823E+38 to 1.79769313486232E+308 for positive values. A double value has 15 decimal digits of precision. Uninitialized Double variables are automatically set equal to 0(Zero).

Currency:- It occupies 8 bytes of memory. Currency datatype can hold decimal values in a fixed point format in the range from -922337203685477.5808 to 922337203685477.5807. It is differ form floating point data type such as single and double ,it supports 4 digits to the right of decimal point. The initial value of currency variable is 0(zero).

Decimal:- It occupies 14 bytes of memory. Decimal is a floating point datatype with a higher precision than double, but it has smaller range. The decimal variable can store values in the range +/-79228162514264337593543950335 with no decimal point or +/-7.9228162514264337593543950335 with 28 places to the right of decimal point.The smaller nonzero values is +/-0.0000000000000000000000000001. The initial value for the Decimal variable is 0(Zero).

Boolean:- It occupies 2 bytes (16 bits) of memory. Boolean datatype holds either a true or false value. These are not stored as numeric values and cannot be used as such. Values are internally stored as -1(True) and 0(False) and any non-zero value is considered as true. The default value of booean is false.

Date:- It occupies 8 bytes of memory. It is used to store date and time values. A variable declared as date type can store both date and upto 12/31/9999 and time from 00:00:00(mid night) to 11:59:59 pm. The default value of date is 00:00:00

Object:- It occupies 4 bytes of memory. Visual basic uses object variables to store rererence of objects we can use the object variable to access the original objects properties and methods. The value of an uninitialized object variable is nothing (a null referance).

String:- The String datatype is used to hold the sequences of unicode characters. Unicode uses two bytes for each character and a unicode character may have 65536 different values. This makes unicode strings ideal for writing code that display its messages in any language such as chinese , japanese,etc.   
                       Visual basic manages two different types of strings .
  
(i) Variable Length String                                                (ii) Fixed Length String

A variable length string takes the memory that it needs for its characters and also takes 10 additional bytes for holding other information about the string, whereas a fixed-length  string always takes a fixed amount of memory.

 A variable length string can contain upto approximately 2 billion(2^21) characters .A fixed length string can contain 1 to approximately 65536 characters.


Variant:- The Visual basic variant datatype is a special datatype can contain any type of data. It is default visual basic datatype. If a variable is declared without specifying a datatype , Visual Basic considers the datatype, visual Basic considers the datatype as variant.

   In VB, variant variables are initialized to Empty. An empty variant is converted to 0(Zero) , when used in a numeric expression , or converted to an empty string when used in a string expression.


Visual basic datatypes and its Suffix:-

Datatype                           Suffix

Integer                                   %
Long                                      &
single                                      !
Double                                    #
Currency                                 @
Date                                         _
Object                                     _
String                                       $
Variant                                     _




** Variable and its declaration:-

  A variable is a container which is assigned some memory to hold the value. The value of variable may be changed during program execution. Each variable has a specific type which determines the size and layout of variables memory and the range of values that can be stored within that memory.

                 There are certain rules regarding naming v variable.These rules are as follows:-
(i) A variable name must be meaningful and unique.
  Ex:- num,sal,sname,da,hra etc.
(ii) A variable name can be upto 255 characters long.
(iii) A variable name must consistes of only alphabets(capital as well as small letters),digits and underscore(-).
  Example:- basicsalary,my1stbook,basic_salary.
(iv) The name must begin with a letter of alphbet.It means, digits and underscore can not be used as first character of variable name.

Ex:- 
             salary                →        Valid
             Basic_salary     →        Valid
              
             1stbook             →         Invalid
             _salary              →         Invalid  

(v) No special symbol (like %,&,#,*,$) can be used except underscore(_).
         Ex:-     Basic_salary     →   Valid
                     Basic*salary     →    Invalid
                     My$India         →     Invalid
(vi) No spacing is allowed.It means variable name cannot take  any type of space.
(vii) Keywords can not be used as variables.

       Ex:- print, if              → Invalid , because they are keywords.

Declaration of Variable:-

Visual Basic basically support two types of declaration:-

(i)  Implicit Declaration
(ii) Explicit Declaration


* Implicit Declaration:-
                                      Unlike other programming language, visual basic actually doesn't require specially to declare a variable before it is used . If a variable is not declared, visual basic automatically declare the variable as a varient. A variant is a datatype can hold any type of data. This is called implicit  declaration.


  Ex:- private sub command1_click()
                 str="welcome in Vb"
                 print str
             End sub

  Ex:-   private sub command1_click()
                  a=10
                  b=20
                   s=a+b
                 print s
             End sub 


(*) Explicit declaration:-
                                  In visual basic, it is good practice to declare a variable with a specific datatype before using them. Declaring a variable tells visual basic to reserve space in memory . In vb, variables are normally declared using statement.

Syntax for variable declaration:-


 Dim variable name as datatype


       (here Dim, as are keywords.)

              OR
  Dim variablename1 as datatype, variablename2 as datatype, variablename3 as datatype,...........


Ex:- Dim num as Integer
       Dim sname as String
       dim s as integer,b as integer, c as integer
       Dim naum as ingeger, sname as string

    * Dim a,b,c as integer  →Here a and b are variant, only c is integer.
      
Ex:- Private sub command1_click()
          Dim str as string
          Str= "welcome in Vb"
          private str
        End sub

Notes:- For string declaration , there are two possible formats; one for  variable length string and another for fixed length string. For the variable length string, we use the same format as described above but for fixed length string, we use the following format/ syntax:-

                  Dim variablename as string*n , where n defines the number of characters the string can hold.

Example:-
      Dim sname as string * 20
     Sname can holds no more than 20 characters


Using option explicit statement:-

This statement forces the user to declare all variables. when the option explicit statement is inserted/placed in the general declaration section, it instructs visual basic to require explicit declaration of all variables . If a variable is not declared, an error message will appear "variable not defined".

Ex:- Option explicit
     Private sub Command_click()
       str="welcome to visual basic"
       print str
End sub
  
Output:- error : variable not defined.   

Scope of variable:-

The scope of variable defines which part of the program code are aware of the variable's existence .A variable is swaped to a procedure- level(local) or module-level variable depending on how it is declared.


Procedure -Level(local) Variable:-
                                           A procedure -level/local variable is declared inside a procedure . This type of variable is accessible only to procedure in which it is declared .Within a procedure , variables are declared using Dim  statement. The value of a local variable can't be accessed outside it's  procedure. When the procedure finishes, the variable destroyed and memory allocated to the variable is released.

Ex:- Dim num as Integer
        Dim n as Double

          To make a procedure -Level variable retain/preserve, its value upon exiting/ terminating the procedure. We use static keyword in place of Dim.

Example:-  Static num as Integer.

Module_level Variable:- Module _level variable created with a private/Dim statement in the general declaration section f a form or code module. The  value of module_level  variable is availabel to all procedure in that module(form). Memory allocated to the module-level variable is destroyed ntil the module(form) is unloaded.

Ex:- Dim num as Integer
        private num as Integer
        Private n as double

Global Variable:- Global variables are created with a public statement in general declaration section of form or code module. The value of a global variable is available to any procedure in any form or code module. The value of a globel variable is available to any procedure in any form or code module. Memory allocated to a global variable is not released until program shuts down.


Ex:- Public num as Integer.
        Public n as single.



Some important Intrinsic Controls:-

Label:-
         It is an intrinsic control which is used to display any message or value of variable to the user. It means,We can say that the label control is mainly used for output purpose.
      
                       As we know that any control have three features:-

(i) Properties (Accessed from properties window as well as code window)
(ii)Events (Accessed from code Window)
(iii) Methods(Accessed from code window)

Note:- When we double click on any control including the form then the code window will open with the default event procedure.











































































VBB

Comments

Post a Comment

Popular posts from this blog

DATA STRUCTURE

Microsoft Visual Foxpro