Section � A by 5gO7r8

VIEWS: 0 PAGES: 76

									SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  1/76

   Section – A                                              2 Marks Questions
[Questions 1 TO 66]                                            [PAGE 1 TO 8]
Q1.    What is an event driven programming?
Ans.    In event driven programming the flow of program execution is controlled by the
        events that occurs as the program run. Each time an event occurs, it causes a
        message to be sent to the operating system. The system processes the message
        and broadcasts it to the other windows. Each window can then take the appropriate
        action based on its own instructions for dealing with that particular message.
       Events can be triggered by user’s actions, by messages from the system or other
       application, or even from the application itself. The sequence of these events
       determines the sequence in which the code executes. Thus the path through
       applications code differs each time the program runs.
Q2.    Differentiate between a variable and a constant.
Ans.   Constants are similar to variable because they take space in memory but constants
       remain same before and after the execution of a block or a program. Variable is a
       placeholder in memory. Value of the variable can be modified.
Q3.    Give the syntax of for loop in VB.
Ans.   For variable = start to end step value
                Statements
                Statements
       Next
       For example
                For I = 1 To 10 Step 1
                Print I
                Next
Q4.    What is a form in VB?
Ans.   A form is a window that contains an application code and has other objects placed on
       it to create the user interface. A form may fill the entire screen or have other forms
       contained within it or it may be a custom dialog box.
Q5.    What is the difference between label and caption?
Ans.   Label is a control, which is used to display the text on the form.
       Caption is the property of an object. It will also show the text, which is assigned to
       caption property.
Q6.    When will you use combo Box?
Ans.   Combo box is required when we want to show a list of items on form. It will show a
       list from which we can select one item.
Q7.    Give any two advantages of VB?
Ans.   VB provides graphical user interface and is one of the event driven programming
       language. It provides number of advantages:
            1. ActiveX Control: they are created once and used number of times.
            2. Database Connectivity: it helps to link front end applications with the back end
                database.
Q8.    Why should you change the control name from its default value?
Ans.   Default names assigned by the program to the controls have a number following the
       name of the control. It is original practice to change the name of control according to
       its respective usage in the application. It will also help in proper documentation.
Q9.    What is the difference between a decision statement and a looping statement?
Ans.   Decision-statement is used to check the condition and then to execute a group of
       statements if condition is true. The decision statement executes a group of
       statements once whereas looping statement is used to execute a group of
       statements more than once till the condition is true.
Q10.   Differentiate between a check box and an option button.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  2/76

Ans.   Checkboxes and option buttons both are used to made selection from the list of
       options. But there is a difference between these.
       In checkbox, we can select multiple items but in option control we can select only
       single item at a time.
Q11.   What is difference between Now and Time function?
Ans.   Now function retrieves date and time whereas Time function retrieves time only.
       For example:
       Private Sub Form_Load()
                MsgBox "Using Now" & Now()
                MsgBox "Using time" & Time()
       End Sub
Q12.   Explain the visual basic program development process.
Ans.   First step in creation of a VB program is to add project. From New tab choose the
       project template.
       After choosing the project type, add forms in your project. Set the properties of the
       form. Third Add controls on the form and set their properties. If it is simple forms
       then use the menu editor to define the menu bar.
       Define the code of controls for the action events. Add module if necessary.
       Save forms and project. Set the default form to run.
Q13.   What is the purpose of Visual Basic file types?
Ans.   Different file types are used for different purposes in VB. Programmers can know
       from the extension of the file that which file meant for what purpose.
       .VBP: It is the extension of Visual Basic Project File. It is a collection of Forms, MDI
       Forms, Class and Modules etc.
       .FRM: It is the extension of Form where we can place controls
       .BAS: It is the extension of Class file.
       .OCX: It is the extension of ActiveX Control File, used to make user controls.
Q14.   What is a Combo Box? Name the three styles of Combo Boxes?
Ans.   Combo is a control that displays single item at a time and we can select only single
       item from the list. The three styles of combo box are-
        Dropdown Combo
        Simple Combo
        Dropdown List
Q15.   What is difference between linking and embedding?
Ans.   Data associated with a linked object is stored by the application that supplies the
       object. This application stores only a link reference that displays a snapshot of the
       source data.
       When an embedded object is created all the data associated with that object is
       contained in the object.
Q16.   What is the purpose of a toolbar in an application?
Ans.   Toolbar contains several options. Those are also available in menus. Toolbars are
       basically used to make interaction process fast. Toolbar contains options those are
       frequently used in any application like start, stop, pause tools etc. it contains the
       frequently used buttons.
Q17.   Which control is used to draw circles on the form?
Ans.   Although form control is having a circle methods to draw circle, but there is control
       known as shape control, also used to design circle.
Q18.   Write down the various kind of Data type in Visual Basic and how much
       memory it will occupy in the main memory.
Ans.   Integer 2 bytes
       Long 4 bytes
       Single 4 bytes
       String 1 byte
       Byte 1 byte
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 3/76

       Date 8 bytes
       Variant 16 bytes
       Double 16 bytes
Q19.   Write down various inbuilt functions with example.
Ans.    These functions are procedures that return a value. Three categories of these types
        of functions are: -
         Date and Time function
         Format function and
         String function
       Date and Time functions: Date and time are internally stored in visual basic. The
       system’s current date and time can be retrieved using now, date and time functions
       in VB i.e
                Year (NOW), Month (Now), Day (Now),Datediff function returns the interval
       between two dates in terms of years , month or days.
       Format functions
       The format function accepts numeric values and converts it to string, in the format
       specified by the format argument.
       Format (expression [, format [, firstdaydayof week]])
       String Function
       VB string functions can manipulate strings in application.
       Strcmp()- Compare two strings
       Len () -find the length of string
       Lset(),Rset() - justify the string
Q20.   Write down various list controls.
Ans.   List box and Combo box:
       List and Combo box controls are used to present a set of choices that we want to
       display vertically in a single column. If the number of items exceeds the value that
       can be displayed, scroll bars will automatically appear on the control.
Q21.   What are exit for and exit do statements?
Ans.   Exit for and Exit do statements are used to terminate the loop before normal
       termination of loop according to condition.
Q22.   What do you mean by focus or control focus?
Ans.   The focus method is used to transfer the focus on a particular control forcefully. The
       control that gets the focus is called control focus.
Q23.   Explain the checkbox control?
Ans.   A check box control is used to offer an option to the user. It is an option on the form
       that is checked when selected and unchecked when not selected. Use a checkbox
       control when you want to offer the user two or more choices.
Q24.    Write a note on input box function.
Ans.   The input box () function displays a modal dialog box that asks the user to enter
       some data. The dialog box contains a message, an OK button and a Cancel button.
       The first parameter of the input box () function is the message of the dialog box and
       the second parameter is the title of the message box.
        e.g.
        n = input (“Enter your name”,”name please”)
Q25.    Write the syntax of if then else statement in VB.
Ans.    The if…then block is used for conditional execution of one or more statements.
        If (condition) then
                Statement1
                Statement2
        End if
Q26.    Write syntax of select case in VB.,
Ans.   Select. …Case structure is an alternative to if…then..else structure. It is used for
       selectively executing a single block of statements from multiple blocks of statements.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               4/76

       Select. …Case is more convenient in use than if… else …end if, because it reduces
       the program complexity. It makes the program easy to read and follow.
       Select case index
       Case 0
               Statements1
               Statements2
       Case 1
               Statements1
               Statements2
       End case

Q27.   Describe the various mouse events.
Ans.   The main mouse events are mouse down, mouse up and mouse move. The mouse
       down event occurs when the user presses any mouse button and the mouse up
       event occurs when the user releases any button. The mouse move event occurs
       whenever the mouse pointer is moved to the new point on the screen.


Q28.   Write a short note on Combo box control and its different types.
Ans.   A combo box combines the features of a text box and a list box. This control enables
       the user to select an item either by typing the text in the combo box or by selecting
       an item from the list.
       Different types of combo box are-
       1. Dropdown combo (style 0)
       2. Simple combo (style 1)
       3. Dropdown list (style2)
       Private sub form _load ()
       Combo1. Add Item "MCA"
       Combo1. Additem "PGDCA"
       The add item method is used to add values to the combo and list box controls.
Q29.   Write a note on IDE.
Ans.   IDE is integrated development environment, which is commonly used in the
       programming to describe the interface and environment that we use to create our
       applications. It is called integrated because we can access virtually all the
       development tools that we need from one screen called an interface.
Q30.   Write down the various elements or components of IDE.
Ans.   Main elements or components of IDE are:
            Menu bar
            Tool bar
            Project explorer
            Properties window
            Toolbox
            Form Designer
            Object Browser
Q31.   Discuss briefly about the show method.
Ans.   The show method is used to display the form object using event if anybody wants to
       open the specified form.
       e.g, form1.show
Q32.   Discuss briefly about the unload statement.
Ans.   The unload statement removes the form from the display and releases its memory.
       The following code should be entered-
       Unload form 1
Q33.   Write an applicable program by using text box and command button.
Ans.   Private sub command 1_click ()
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  5/76

             Text1. Text="This text box is locked"
       End sub

       The following code is entered in the command 2 buttons.
               Private sub command2_click ()
               End
               End sub
Q34.   Write an application by using Hscroll bar.
Ans.   Private sub cmdexit_Click ()
               End
           End Sub

            The following code is entered in Hscroll’s Change event
               Private sub HScroll_Change()
               Text1.Text=Str(HScroll1.Value)+"mph"
            End sub
            The following code is entered in Hscroll’s Scroll Event
               Private sub HScroll_Scroll ()
               Text1_Change
            End sub
Q35.   Write a code in Visual Basic to draw a box using graphic method.
Ans.   Line (600,600) – Step (1000,0)
       Line – walk (0,10000)
       Line – Step (-1000,0)
       Line – Step (0, -1000)
Q36.   Differentiate between procedural programming and event driven programming.
Ans.   Events are the various things that can happen in a program. In a procedural
       language, a written application is executed by checking the statements logically one
       after the other. But in event driven application the program statements are executed
       only when a particular event calls a specific part of the code, which is assigned to
       that event. e.g. Text box events are change, click, mouse move etc.
Q37.   What are the various startup positions of the form in the VB?
Ans.   Startup position property is used to set the position of the form when it gets displaced
       on the screen. Various options are:
       0. Manual
       1. Center owner
       2. Center Screen
       3. Windows default
Q38.   Explain the two tabs of the property window?
Ans.   The two tabs of property window are:
       0. Alphabetic
       1. Categorized
       Sometimes it is convenient to display the properties sorted alphabetically. For this,
       alphabetic tab can be used. But sometimes you can group the properties according
       to their categories. For this, categorized tab can be used. e.g. categories can be
       appearance, behavior etc.
Q39.   What are various types of list box controls used in visual basic?
Ans.   List box control is used to display a list of the items. The items can be added to the
       list box control both, at design as well as at run time. Following types of list box
       controls are provided in visual basic, which can be used or set through its style
       property.
               0- Standard.           1 - Checkbox
Q40.   What is the one major difference between a list box control & a combo box
       control?
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                   6/76

Ans.   One major difference between a list box & a combo box control is that - in combo box
       the user can enter its own items whereas in list box control a user has to select the
       item only from the list provided & the user can not enter its own items in the list.
Q41.   Write three important properties of command button.
Ans.   Three important properties of command button are -
       1. Name: The name property of the command button is used in the code window
           while programming any event on the command button.
       2. Caption: Caption property sets the caption of the command button which will be
           displayed on the button e.g. O.K.,Cancel,Yes,No etc.
       3. Enabled: This property is either true or false. If it is true then the user can click
           the button other wise if it is false then the user is unable to click the button.
Q42.   Explain the difference between implicit & explicit declarations.
Ans.   In visual basic, there are two types of declarations implicit & explicit. In visual basic,
       you cannot to declare a variable and if Visual Basic comes across an undeclared
       variable, then it declares that variable automatically of type variant. Such declaration
       of variable is called implicit declaration.
       Another type of declaration is explicit declaration where declaration of variables is
       must. Here variable is declared by Dim statement followed by variable's name and
       type e.g.
       Dim meters as integer
       For explicit declarations, statement option explicit should be written on top of the
       form.
Q43.   Explain the difference between Access keys & Shortcut keys.
Ans.
        Access Keys                                 Shortcut Keys
        1. Access keys start with the alt key       1. Shortcut keys start with the ctrl
                                                    key
        2. Access keys are designated by putting 2. Shortcut keys are to be selected
        '&' sign before the letter.                 from the Menu editor.
        3. If designer doesn't designate any access 3. There is no such rule for shortcut
        key then VB uses the first character as keys
        Access key.
        4.     Access keys can be defined for Shortcut keys are only defined for
        command buttons, menus etc.                 menus.

Q44.   Write four important properties of listbox control.
Ans.   Four important properties of listbox control are:
       1. List (): This property contains all the elements in the list
       2. List count: This counts the number of items in the list.
       3. Sorted: By setting this property to true, items in the list are always sorted.
       4. Style: This property determines the appearance of the control
Q45.   List three file controls used in visual basic?
Ans.   Three file controls used in Visual Basic are
       1) DriveList box: Displays the name of the drives within & connected to PC
       2) DirList box: Displays the folders of the current drive.
       3) FileList Box: Displays the files of current folder.
Q46.   Why Dim statement is used in visual basic?
Ans.   Dim statement is used in visual basic to declare variables within subroutine, functions
       or at module level. Variables declare with Dim statement are local to the function in
       they are declared
       Syntax: Dim variablename
       e.g. Dim a as Integer
               Above statement declares a variable 'a' of the type integer.
Q47.   Write a note on variable naming conventions used in visual basic.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                7/76

Ans. Following are the few naming conventions used while declaring variables.
     1. It must begin with a letter.
     2. Can't contain an embedded period or any of the keywords.
     3. Must not exceed 255 characters.
     Must be unique within its scope.
Q48. Define Event.
Ans. It is an action recognized by an object, such as clicking of the mouse or pressing of a
     key and you can write a code as a response to the occurrence of an event. Events
     can occur as a result of a user action or program code, or they can be triggered by
     the system.

Q49.   How is secondary form added to an active object? How is it removed?
Ans.   To add secondary form- select project menu -> select add form option.
       To remove the secondary form from the project, right click on the form icon in the
       project explorer window and select remove form the popup menu.
Q50.   How secondary form is made visible when it has been loaded? How is it made
       hidden?
Ans.   We can make the form visible at load time by specifying the visible property of the
       form as true.
       To make the form hidden at runtime we have to use the method formname.hide.
Q51.   How the values to the properties of the controls are assigned in VB?
Ans.   To set the properties at design time select the control and set properties using the
       property window.
Q52.   How a control is removed from the form design window?
Ans.   To remove a control from the form design window select the control and then press
       the delete key from the keyboard.
Q53.   What is the purpose of the list index property? Which control supports this
       property?
Ans.   List index property is used to find the index of the selected item in the list. This
       property is used with the list box control.
Q54.   For what type of applications the timer control is intended?
Ans.   Timer control is used to call the subroutine or function again and again after a
       specific period of time. We can also call a specific code again and again after a
       specific interval.
Q55.   Suggest three different uses of a scrollbar.
Ans.   Scrollbar are used for the following purposes.
       1. These are used to navigate the document.
       2. By making changes in the value property of the scrollbar control we can modify
           the value of the scroll bar.
       3. Scrollbars are also useful for changing the border size and shape of the shapes.
Q56.   Briefly describe the difference between the Design and RUN mode.
Ans.   Design mode-In this mode the controls are added to a project, their properties set &
       the relevant code is written.
       Run mode-In this mode we examine our program in action just as the user will see it.
       Here property settings can be changed by a program’s code. This is accomplished by
       writing a special kind of assignment statement that gives a new value to a specific
       property of a selected object.
Q57.   How can you declare a variable in VB? Explain with example.
Ans.   In vb the variables can be declared as-
               1. Implicit   2. Explicit
       1. Implicit: - In implicit declaration, variables are automatically declared as type
           variant whenever they are used in the application.
           e.g a=10
       2. Explicit: - In explicit declaration, variables must be declare before the their use
           otherwise vb interpreter will generate an error.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                8/76

           e.g dim a as integer
           a=10
Q58.   What is the role of a LABEL control and a TEXTBOX control in VB?
Ans.   Label is a static text control in vb. Text of the label cannot be modified at runtime.
       TextBox control is an editable text control. We can set or edit the values of this
       control at runtime
Q59.   What are the various properties that any control can have?
Ans.   Various controls can have the following properties-
       1. Name 2. Height 3. Width 4. Top 5. Left 6. Enabled 7. Visible
Q60.   What is the purpose of a toolbar in an application?
Ans.   Toolbars are used in an application to make the life of an user easy because then
       there is no need to open the instruction from the menu. User can directly execute the
       instruction by selecting the tool from the toolbar.
Q61.   Name the component of visual basic IDE.
Ans.   Components of visual basic IDE are.
       1. TITLE BAR
       2. MENU BAR
       3. TOOLBAR
       4. TOOLBOXss
       5. PROPERTY WINDOW
       6. CODE WINDOW
       7. PROJECT EXPLORER WINDOW.
Q62.   What are the two major components within the visual programming
       development system?
Ans.   The components of visual basic IDE are very helpful to develop a good application.
       The two major components of VB IDE are the form and the code window. Without
       form user cannot use any control in vb. To make any control interactive, code window
       is needed. In code window we can code the event for any controls.
Q63.   What is an event? What is an event procedure?
Ans.   Event is an action performed on the component. An event procedure can contain the
       code that will be executed when a specific action is performed on a specific
       component.
Q64.   What is a form in visual basic?
Ans.   Form is an interface between the user and the application. A user can interact with
       an application with the help of a form. A form contains a number of sub objects that
       helps in interacting with the user.
Q65.   Name some of the controls which feature OLE drag and drop.
Ans.   Most of the control in VB provide the OLE drag and drop feature. Some of these
       controls are-
       1. List 2. Combo 3. Textbox 4. Image 5. Picture etc.
Q66.   Explain in brief the difference between Image Control and Picture Control.
Ans.   Image Control: Displays Bitmaps, Icons, JPEG or Gif files and act like a command
       button when clicked.
       Properties:
        Name: Sets the name of the control.
        Picture: You can add the graphic by setting the picture property.
        Stretch: This is a Boolean property means it can take only two values either true
           or false. By setting this property to true the inserted picture’s size could be
           controlled.

       Picture Box: This control is also used to Display Bitmaps, Icons, JPEG or Gif files.
       This control does not have a stretch property like Image Box. It requires less memory
       than image box.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  9/76




    Section – A                                             5 Marks Questions
[Questions 1 TO 45]                                           [PAGE 8 TO 26]
Q1.    Write a short note on option Explicit.
Ans.   It may be convenient to declare variable implicitly, but it can lead to errors that may
       not be recognized at run. Say e.g. a variable name intcount is used implicitly and is
       assigned a value. In the next step, the field is incremented by 1 by the following
       statement.
       Intcount =intcont+1
       This calculation will result in intcount yielding a value of 1, as intcont would have
       been initialized to zero. This because the intcount variable has been mistyped as
       intcont in the right hand side of the second variable. But Visual Basic does not view
       this as a mistake and consider it to the new variable and hence gives a wrong result.
       To prevent errors of this nature, we can declare a variable by adding the following
       statement to the general declaration section of the Form. Which is -
               Option Explicit
       This forces the user to declare all the variable. The option explicit statement checks
       the module for usage of any undeclared variable and reports an error to the user.
       The user can thus rectify the error on seeing this error message.
       The Option Explicit statement can be explicitly placed in the general declaration
       section of each module using the following steps.
Q2     Write down the names of different controls and their purpose.
Ans.   Toolbar: - It contains a set of controls that are used to place in a form at design time
       thereby creating the user interface area. User can include additional controls in the
       toolbox by using the Components menu item on the project menu. A Toolbox
       contains the following controls-
        The pointer helps to move and resize the control and Forms.
        Label displays a text that user cannot modify or interact with.
        Frame control serves as a visual and functional container for controls.
        Check Box displays a True/False or Yes/No option.
        Textbox is a control used to display message and enter text.
        The List Box displays a list of items from which a user can select one.
        Combo Box contains a Textbox and a List Box. This allows the user to select an
           item from the dropdown List Box or to type a selection in the Textbox.
        HScroll Bar and VScrollbar controls allow the user to select a value within the
           specified range of values.
        Timer control executes timer events at specified intervals of time.
        DirListBox allows the user to select directories and paths, which are displayed.
        Shape control adds a shape (rectangle, square or circle) to a Form.
        Image control is used to display icon, bitmaps, metafiles, etc.
        OLE controls used to link or embed an object display and manipulate data from
           other Windows based applications.
        PictureBox displays icons/ bitmaps and metafiles. It displays text or acts as a
           visual container for other control.
        CommandButton carries out the specified action when the user chooses it.
        The OptionButton control, which is a part of an option group, allows the user to
           select one option even if it displays multiple choices.
        The DriveListBox displays the valid disk drives and allows the user to select one
           of them.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               10/76

          The FileListBox displays a set of files from which a user can select the desired
           one.
          Line control draws a straight line to the Form.
          Data control enables the user to connect to an existing database and
           display information from it.
Q3.    Differentiate between Properties, Methods and events.
Ans.   All the controls in the Toolbox except the Pointer are objects in Visual Basic. These
       objects have associated properties. For example, a flower is loaded with certain
       colour, shape and fragrance. Similarly, programming objects are loaded with
       properties.
       A property is a named attribute of a programming object. Properties define the
       characteristic of an object such as size, color, etc. or sometimes the way in which it
       behaves. For example, a Textbox accepts properties such as Enabled, Font, Multi
       Line, Text, Visible, Width, etc. These are discussed below:
        Enabled property allows the Textbox to be enabled or disabled at run time
            depending on the condition set to True or False.
        Font property sets a particular font allows the Textbox.
        Multi Line property allows the Textbox to accept and display multiple lines at run
            time.
        Text property of the Textbox control sets a particular text in the control.
        Visible property is used to hide the object at run time.
        Width property sets the Textbox to the desired width at design time.
       The properties that are discussed above are design time properties that can be set at
       the design time by selection the Properties window. But certain properties cannot be
       set at design time.
       A method is an action that can be performed on objects. For example, a cat is an
       object. Its properties might include long white hair, blue eyes, three pounds weight,
       etc. A complete definition of cat must not only encompass on its looks, but should
       also include a complete itemization of its activities. Therefore, a cat's methods might
       be move, jump, play, breathe, etc.
       Similarly, in object-oriented programming, a method is a connected or built-in
       procedure, a block of code that can be invoked to impart some action on a particular
       object. A method requires an object to provide them with a context. For example, the
       word Move has no meaning in Visual Basic, but the following statement, performs a
       very precise action.
       Text1. Move 700, 400
       The textbox control has other associated methods such as Refresh, Set Focus, etc.
        The Refresh method enforces a complete repaint of the control or a Form. For
            example, Text1. Refresh refreshes the Text Box.
        The Set Focus method moves the focus to the control .For example , Tex1. Set
            Focus sets the focus to Textbox control Text1.
Q4.    Name and explain in brief various components of Visual Basic IDE.
Ans.   IDE is integrated development environment, which is commonly used in the
       programming world to describe the interface and environment that we use to create
       our applications. It is called integrated because we can access virtually all the
       development tools that we need from one screen called an interface.
       Main elements or components of IDE are:
             Menu bar: - It contains different types of menus and a group of similar type
                instructions are store in a single menu.
             Tool bar :- It contains the shortcuts of the commands appearing in different
                menus. By using a toolbar, user can use many items contained in different
                menus without opening a menu again & again. User can directly select them
                from the toolbar.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  11/76

              Project explorer :- it contains the list of forms, module and class modules
               used in the project window
            Properties:- It contains the list of properties for the selected control.
            Toolbox :- It contains all the implicit controls used in VB.
            Form Designer :- here we can design the form for vb project.
            Object Browser :- It allow the user to browse through the various properties,
               events, and methods that are made available, or exposed to the user.
Q5.    What is visual basic? From which language is it derived?
Ans.   Visual basic is an object-based language, which provides graphical user interface
       just like Microsoft windows. Visual basic provides integrated development
       environment. Visual basic provides three editions i.e. Learning edition, professional
       edition & enterprise edition. Visual basic integrated development environment
       provides editor, designing, compiler & debugging capabilities. Visual basic provides
       Internet features, object linking and embedding & various other capabilities to
       develop robust windows applications.
               Visual basic applications provide excellent user interface & VB developer is
       capable of being connected to various databases. Visual basic is derived from the
       language Basic.
Q6.    What is control? Can we create our own control in visual Basic?
Ans.   A control is an object, which we place on the form to create a user interface.
       Examples of controls are command button, textbox control, label, picture box etc. We
       can add more controls by right clicking on the toolbox and then by selecting
       components from pop up menu. All the controls can be accessed from the toolbox.
       Nearly every control has its own properties & methods. We can set the properties of
       a control at design time and through coding. We can make controls responding to the
       happening of events. For example: change method of textbox responds to the code
       written in change method whenever the text in the textbox changes.
               We can create our own controls in visual Basic & these are called ActiveX
       controls. User can design their own controls or can extend the properties of existing
       controls. For example: you can design a textbox control that accepts only numeric
       data.
Q7.    Describe a form’s life cycle.
Ans.   A form’s life cycle starts when it got loaded in the memory and ends when that form is
       being unloaded. When a form is loaded the events fired are referred to as Birth Events
       such as Initialize Event, Load event Resize Event, Activate Event. To watch the
       interaction of the user with the form various events are fired such as mouse move
       Event, click event, double click event etc. When the form is unloaded its shutdown
       events are fired such as QueryUnload Event, unload event, terminate event. All these
       events can be tracked through the immediate window. We can display a message
       each time an event is fired.

Q8.    What is recursion? Explain with suitable example.
Ans.   Recursion can be described as a procedure in which a function or procedure calls
       itself. Code written in a function is extended sequentially but when a function calls itself
       then the same code is executed by each call to the function. In recursion function, a
       function calls itself again & again.
       E.g. - If we want to calculate the factorial of a number with the help of a recursion
       function, then we can write the following code for the function.
       Private Function rec (x as integer)
                If x = 1 then
                         Rec= 1.
                Else
                         F = rec (x – 1)
                         Rec =f
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  12/76

                End If
Q9.    What do you understand by OLE?
Ans.   OLE is object linking & embedding. With the help of OLE we can add other objects in
       our visual basic application .OLE control is a part of visual basic toolbox. Through OLE
       control you can insert an object from one application into another application. The
       inserted object is a copy of the original object. For example, you can embed a range of
       cells from an excel worksheet in a word document. OLE container control, allows you
       to insert objects from other applications into your program. You can place only one
       object in the container control at a time, but there can be multiple OLE container
       control on a single form. You can embed word documents, sounds, images and excel
       spreadsheets in your VB applications. OLE container control hides all the
       complications of OLE from the user & you can build OLE-capable applications.
Q10.   What do you understand by transactions?
Ans.   Transaction is a database terminology and it is a sequence of alterations made to a
       table in the database. Transactions can be simply stated as any changes made to the
       database tables. In visual basic we can make transactions in the database with the
       help of various controls like DAO, ADO etc. We can create record sets in VB with
       which we can manipulate the database tables. Visual basic can store all the
       transactions that it is making, so that if there is any need then we can undo them.
       There are three statements in VB namely BeginTrans, CommitTrans, RollBack.
       BeginTrans makes the log of each & every transaction so that at later stage we can
       undo them.
       CommitTrans commits the changes to database. RollBack roll backs or undo the
       changes made in the database.
Q11.   Discuss timer control with suitable example.
Ans.   Timer control is used to fire on event at specified internals of time. The code you want
       to execute is placed in the timer event of timer control. This control has no methods
       and only one event called timer event. And has seven properties. This control is
       invisible at run time. When a timer control is placed on form its Enabled property is by
       default true. Whenever this property is set to true the timer control’s timer event is fired
       at regular intervals as specified. The unit of measurement is milliseconds. For
       example, following code will print how many times the timer has been fired.
       Private Sub Timer1_Timer()
       Static counter as long
       Counter = Counter +1
       Me. caption = “ The timer has been fired “ & str (counter)& “times! “
       End Sub
Q12.   Write a program in which When you click on add button the new option button
       is added and when a delete button is clicked, the option button got deleted.
       And when you click an option button the color of the picture changes.
Ans.   DIM MaxID as integer
       Private Sub and Add_Click ()
                If MaxID =0 then MaxID =1
                If MaxID >8 then Exit Sub
                MaxID = MaxID +1
       Load optbutton (MaxID)
       Opt button (O). Set focus.
       Opt button (MaxID). Top = Opt button (MaxID – 1). Top + 400
       Opt button (MaxID). Caption = “Option”&MaxID + 1.
       End sub

       Private Sub delete_Click ()
               If MaxID< =1 then exit sub.
               Unload opt button (MaxID)
               MaxID = MaxID – 1
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 13/76

               Opt button (0). Set focus.
       End Sub
       Private Sub optbutton_Click (index as integer)
               Picdisplay. Back color = QB color (Index +1)
       End Sub
Q13.   Explain Scrollbar & Slider controls.
Ans.   The scrollbar & slider controls allow the user to specify a magnitude by scrolling a
       selector between its minimum and maximum values. Sometimes, the user doesn’t
       know in advance the exact value of the quantity to specify. The vertical scroll bar that
       lets the user move up & down along a document. The scroll bars are the prime
       mechanism to view a large image or text that doesn’t fit entirely in a window. While
       scrolling a long document horizontally or vertically, the user doesn’t have to bother
       about line numbers or pixels.
               The slider control is similar to the scrollbar control but it does not cover a
       continuous range of values. The slider control has a fixed number of tick marks,
       which the developer can label. The user can place the slider’s indicator to the desired
       value. Scrollbar is used where continuous value is important and slider control is
       used where discrete values are required, for example slow, medium, fast etc.
       Scrollbar control is a long stripe with an indicator that lets the user select any value
       between two ends of the control scrollbar can be of two types – horizontal & vertical.
       The basic properties of scrollbar control are Min, Max and value. Slider control is
       similar to the scrollbar control but there is no continuity but there is some specific
       range e.g. slow, fast and very fast. Slider control is not an intrinsic control of VB and
       we can add it from components dialog box by selecting Microsoft common controls
       6.0.
Q14.   Write a program to make a text editor with cut and paste facilities.
Ans.   Open a standard EXE project. Place a textbox and place four buttons on it. Name the
       command button as cmdcut, cmdquit, cmdpaste and cmdreset. Name the text box as
       text editor & add the following code.
       DIM store as string
       Private Sub cmdcut_click ()
               Cuttext=Texteditor.Seltext.
               store=Texteditor.Seltext.
               Texteditor.Seltext=” “
               Cmdpaste.Enabled=true
               Texteditor.Set focus.
       End Sub
       Private Sub cmdQuit_Click ()
               Unload me.
       End Sub
       Private Sub cmdreset_Click ()
               Texteditor. Text=” “
               Texteditor. Set focus
       End Sub
       Private Sub Text editor_Change()
               Cmdcut.Enabled=True
               Cmdpaste.Enabled=True
               Cmdreset.Enabled=True
       End Sub
       Private sub cmdpaste_Click()
               Texteditor.Seltext=store
               Texteditor.Set focus
       End Sub
Q15.   Write a program having one command button and on pressing the button it
       should display labels & text boxes of Name, age, Roll No, and Address?
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                           14/76

Ans.
       Private Sub command1_Click()
               Dim captions (10) as string
               Dim sizes (10) as integer
               Caption (1)=”Name”
               Caption (2)=”Age”
               Caption (3)=”Roll No.”
               Caption (4)=”Address”
               Size (1)=20
               Size (2)=30
               Size (3)=15
               Size (4)=40
               For I=1to 5
                       Load labels (I)
                       Load text boxes (I)
                       Labels (I).Top=labels (I-1). Top+400
                       Labels (I).Left=labels (0). Left
                       Text boxes (I).Top=Text boxes (I-1).Top+450
                       Text boxes (I).Left=Text boxes (0).Left.
                       Text boxes (I).Width=Sizes (I) * 60
                       Labels (I).Caption = Caption (I)
                       Labels (I).Visible = True
                       Textboxes (I).Visible = True
               Next
               End Sub
Q16.   Write about salient features of VB.
Ans.   Some features of VB are
       1.      Full set of objects. So that we can design the application
       2.      Lots of icons and pictures to use.
       3.      Response to mouse and keyboard actions
       4.      Clipboard and printer access.
       5.      Full array of mathematical, string handling, and graphics function.
       6.      Can handle fixed and dynamic variable and control arrays.
       7.      Sequential and random access file support
       8.      Useful debuggers and error handling facilities.
       9.      Powerful database access tools.
       10.     Activex support
       11.     Package & deployment Wizard makes distributing applications simple.

Q17.   Classify the operators in VB.
Ans.   Arithmetic operators:
              +      Used to add two numbers if it is used with strings then it will
                     concatenate the both strings.
              -      Used to subtract two values
              *      Used to multiply the two numbers.
              /      Used to divide two numbers
              \      It is integer division operator.
              Mod Used to find modules
       Relational operators
              <      less than
              <=     less than or equal to
              >      greater than
              >=     greater than or equal to
              =      to compare equality
              !      Not equal to
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 15/76


       Logical operators                     String conciliation

       AND, NOT, OR                           String conciliation -------&
Q18.   Write the enhance comments of VB 6.0 over VB 5.0.
Ans.   Visual Basic 5.0 released in late 1996. New environment supports creation of Active
       x controls. Deleted 16-bit application support.
       VB 6.0 includes new features:
             Faster compiler
             New Activex data control object
             Allows database integration with wide variety of applications
             New data report designer.
             New package & report designers
             Additional Internet capabilities.
Q19.   Explain the visual basic program development process.
Ans.   First step in creation of a VB program is to add project. From New tab choose the
       project template.
       After choosing the project type, add forms in your project. Set the properties of form.
       Third step - Add controls, if it is a simple form, then use menu editor to define the
       menu bar. Now add controls on the form and set their properties.
       Define the code of controls for the actions events. Add module if necessary.
       Save forms and project. Set the default form to run.
Q20.   What is use of static variables?
Ans.   You can preserve the value of a local variable by making the variable static. Static
       keyword is used to declare the variable as static.
       For example.
       The following function calculates a running total by adding a new value to the total of
       previous values stored in the static variable named Applesold:
       Function RunningTotal (num)
       Applessold= Applessold + num
       Running Total= Applessold
       End function
       If Applessold was declared with DIM instead of static, the previous accumulated
       values would not be preserved across calls to the function and the function would
       simple return the same value with which it was called.
Q21.   Define constant and its sources.
Ans.   A constant is a meaningful name that takes the place of numbers or string that does
       not change. Although constant some what resembles a variable, you can’t modify a
       constant or assign a new value to it as you can to a variable. There are two sources
       for constants:
       Intrinsic or system-defined:
       These constants are provided by applications and controls
       Visual Basic constants are listed in the visual Basic (VB) and Visual Basic for
       applications (VBA) object libraries in the object Browser. Other application that
       provide object Libraries also provide a list of constants you can use with their objects,
       methods and properties. Constants are also defined in object library for each Active
       X control.
       Symbolic or user-defined constants are declared using constant statement.
Q22.   Write a program to authenticate user/password pair.
Ans.   Make a project using standard.exe.
       Add a form. Add two text boxes and two labels. Change caption of first label as
       username as second’s as password. Name the first textbox as txtusr, and second as
       txtpass.
       Add a command button and make its caption clickme.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                16/76

       Double click on button to write code for click event.
       If txtusr = “Munish” and txtpass= “VB6” then Msgbox “Successful login”
       Else
       Msgbox “Login denied Reenter User name/Password”
       Txtusr = “ “
       Txtpass= “ “
       End If
Q23.   What do you understand by scope of a variable? Differentiate between global
       variable and local variable.
Ans.   Scope of a variable depends upon the location where it is declared or which keyword
       is used to declare the variable. Scope tells the lifetime of a variable. We can declare
       variables in two ways.
       1. Global
       2. Local
       1. Global: - When the variables are to be declared as global variables then they are
            declared in the general section of the program. So that they are accessible within
            the whole form. If they are declared with public keyword then they are accessible
            within the whole project with form reference. If they are declared with in a module
            even then they could be called globally within the project. If these variables are
            declare with private or dim keyword in the general section then these variables
            are accessible with in the specified form only.
       2. Local: - if the variables are declared with dim statement in any procedure of the
            form then they are accessible with in that procedure only. We can declare local
            variable with public or private keywords too.
Q24.   Write a VB program to implement a calculator that coverts a number given a
       textbox to its equivalent Binary Hexadecimal and octal number on the click of
       respective buttons and display the result in another textbox.
Ans.
       Private Sub Cmdbinary_Click()
               Text2 = ""
               n = Text1
               While n > 0
                      s = n Mod 2
                      Text2 = Text2 & s
                      n = Int(n / 2)
               Wend
               Text2 = StrReverse(Text2)
       End Sub
       Private sub cmdoct_click()
               Text2=oct(text1)
       End sub
       Private sub cmdhexa_click()
               Text2=hex(text1)
       End sub
Q25.   Write a function subprogram to covert the temperature provided in Fahrenheit
       to Celsius.
Ans.
       Public Function ftoc(f As Double) As Double
               ftoc = 5 / 9 * (f - 32)
       End Function
       Using the following statements we can call that function on click of a command
       button
       Private sub command1_click()
                Dim f a double
               f=inputbox(“enter Fahrenheit”)
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              17/76

              msgbox ftoc(f)
       End sub
Q26.   Write an application that will put a new Textbox control on the form every time
       you click the command button?
Ans.
       Dim i As Integer
       Private Sub Command1_Click()
               i=i+1
               Load Text1(i)
               Text1(i).Visible = True
               Text1(i).Top = Text1(i - 1).Top + Text1(i - 1).Height
       End Sub

       Private Sub Form_Activate()
               i=0
       End Sub

Q27.   Create a project that contains a picture box and two buttons labeled smile and
       frown. The smile button will display a happy face in the picture box and frown
       will display a sad face. Use graphics methods to draw the two faces.
Ans.




       Private Sub Command1_Click()
               Picture1.Cls
               Picture1.FillStyle = vbSolid
               Picture1.FillColor = vbYellow
               Picture1.Circle (Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 2), 500
               Picture1.FillColor = vbRed
               Picture1.Circle (Picture1.ScaleHeight / 3 + 130, Picture1.ScaleWidth / 3 +
               100), 100
               Picture1.Circle (Picture1.ScaleHeight / 3 + 500, Picture1.ScaleWidth / 3 +
               100), 100
               Picture1.Circle (Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 2), 200, 2, 3
       End Sub

       Private Sub Command2_Click()
               Picture1.Cls
               Picture1.FillStyle = vbSolid
               Picture1.FillColor = vbGreen

              Picture1.Circle (Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 2), 500
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               18/76

               Picture1.FillColor = vbRed
               Picture1.Circle (Picture1.ScaleHeight / 3 + 130, Picture1.ScaleWidth / 3 +
               100), 100
               Picture1.Circle (Picture1.ScaleHeight / 3 + 500, Picture1.ScaleWidth / 3 +
               100), 100
               Picture1.Circle (Picture1.ScaleHeight / 2, Picture1.ScaleWidth / 2 + 300), 200,
               0, 3
       End Sub
Q28.   Briefly describe the difference between the design and run mode.
Ans.   The VB provide two types of modes for an application. These modes are
       1. Design mode
       2. Run mode
       1. Design mode: - When a form is opened in this mode then we can place different
       controls that we want, on the form. These controls then appear on the form at run
       time. If we want that some the drawn controls must appear on the form, but we do
       not want them to work. Then we can specify the disable property of these controls at
       design time as False. Some of the properties of controls those we can not specify at
       run time these can be specified at design time. At design time using form layout
       window we can also position the form for the run time appearance. Shape and line
       control doesn’t provide any event so it is normally used at design time.
       2. Run mode: - this mode specify the codes that will execute when we run the form.
       In which we can specify the control position according to form size at runtime. The
       code for events those are attached with different controls of the form can only define
       in the run mode. We can define different types of procedures those are called by the
       events of the control at runtime.
Q29.   List out the mouse pointer properties with at least one pointer example.
Ans.   Returns or sets a value indicating the type of mouse pointer displayed when the
       mouse is over a particular part of an object at run time.

       The settings for value are:
       Constant       Value Description
       vbDefault              0      (Default) Shape determined by the object.
       vbArrow                1      Arrow.
       vbCrosshair            2      Cross (crosshair pointer).
       vbIbeam                3      I beam.
       vbIconPointer                 4       Icon (small square within a square).
       VbSizePointer                 5       Size(four-pointed          arrow         pointing
       north,south,east, west).
       vbSizeNESW             6      SizeNESW                (double,arrow,pointing,northeast,
       southwest).
       vbSizeNS               7      Size N S (double arrow pointing north and south).
       vbSizeNWSE             8      SizeNWSE               (double,arrow,pointing,northwest,
       southeast).
       vbSizeWE               9      Size W E (double arrow pointing west and east).
       vbUpArrow              10     Up Arrow.
       vbHourglass            11     Hourglass (wait).
       vbNoDrop               12     No Drop.
       vbArrowHourglass 13           Arrow and hourglass.
       vbArrowQuestion 14            Arrow and question mark.
       vbSizeAll              15     Size all.
       vbCustom               99     Custom icon specified by the MouseIcon property.
       This example changes the mouse pointer to an hourglass while circles are drawn
       across the screen and then changes the hourglass back to a pointer at the end of the
       procedure. To try this example, paste the code into the Declarations section of a
       form. Press F5 to run the program, and then click the form.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                   19/76

          Private Sub Form_Click ()
                   Dim I .
                   Screen.MousePointer = vbHourglass
                   ' Set random color and draw circles on form.
                   For I = 0 To ScaleWidth Step 50
                             ForeColor = RGB(Rnd * 255, Rnd * 255, Rnd * 255
                             Circle (I, ScaleHeight * Rnd), 400
                   Next
                   ' Return mouse pointer to normal. Screen.MousePointer = vbDefault
       End Sub
Q30.   Explain the following
               Image control
               Command button control
Ans.   1. Image control: - An Image control can display a graphic from a bitmap, icon, or
       metafile, as well as enhanced metafile, JPEG, or GIF files. The Image control uses
       fewer system resources and repaints faster than a PictureBox control, but it
       supports only a subset of the PictureBox properties, events, and methods. Use the
       Stretch property to determine whether the graphic is scaled to fit the control or vice
       versa. Although you can place an Image control within a container, an Image control
       can't act as a container.
       Properties: - there are two main properties of image control. These are
       Picture: - In the picture property the image that we want to display on the image
       control is specified.
       Stretch: - Returns or sets whether the image/ graphics resizes to fit the size of an
       image control or not.
       2. Command Button: - The easiest way to allow the user to interact with an
       application is to provide a button to click. You can use the command button control
       provided by Visual Basic. Most Visual Basic applications have command buttons that
       allow the user to simply click them to perform actions. When the user chooses the
       button, it not only carries out the appropriate action, but it also looks as if it's being
       pushed in and released. Whenever the user clicks a button, the Click event
       procedure is invoked
       Command button control has the default event click and its default property is
       caption.



Q31.   What does docking a window mean? How is docking carried out?
Ans.   You can dock controls to the edges of your form or have them fill the control's
       container (either a form or a container control). For example, Windows Explorer
       docks its Tree View control to the left side of the window and its List View control to
       the right side of the window. Use the Dock property for all visible Windows Form
       controls to define the docking mode.
       To dock a control
            Select the control that you want to dock.
            In the Properties window, click the arrow to the right of the Dock property.
            An editor is displayed that shows a series of boxes representing the edges
               and the center of the form.
            Click the button that represents the edge of the form where you want to dock
               the control. To fill the contents of the control's form or container control, click
               the center box. Click (none) to disable docking.
            The control is automatically resized to fit the boundaries of the docked edge.
Q32.   What are object Properties?
Ans.   The Object properties provide general information about objects contained in the
       Database window. Applies to Form object, Module object and Report object.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               20/76

       You can view the Object properties, and set the Description or Attributes properties,
       in the following ways:
             Click an object in the Database window, and then click the Properties button
                on the Database toolbar.
             Click an object in the Database window, and then click Properties on the View
                menu.
             Right-click an object in the Database window, and then click Properties on the
                shortcut menu.
            Graphical User Interface
            Multiple UI
            ActiveX Control Provision
Q33.   What is Combo Box, Name and describe the three styles of Combo Boxes?
Ans.   Combo Box control presents a set of choices that are displayed vertically in a single
       column. If the number of items exceeds the value what can be displayed, scroll bars
       will automatically appear on the control. A Combo Combine a feature of a Textbox
       and a List Box. There are three types of Combo Box Styles.

       Dropdown Combo: It appears as only an edit area with a down arrow button at right
       side. The user can either select a value from the list or type a value in the edit area
       Simple Combo: It displays an edit area with an attached list box always visible
       immediately below the edit area. The user can select an item from the list or type an
       item in the edit box portion for the combo box.
       Dropdown List: It turns the combo box into a drop-down list box. The user could click
       the down arrow to view the list. The user can select only one of the list items and
       cannot type an item in the edit area.
Q34.   What is the Purpose of Toolbar? How does a menu vary from a toolbar?
Ans.   Toolbars are used to provide quick access to the functions that are also available in
       menus. Toolbars are even more helpful if they expose functions that are buried under
       a menu of options or hidden deep in nested submenus. When you decide to create
       large applications, be sure to use of toolbars and menus effectively.
               Menus expose many of the underlying functions built into an application that
       are not necessarily be observed at first glance. Menu options can be enabled,
       disabled, checked, and even popped-up on an object. For example you can create a
       window list. Which is a menu, that has an option for each MDI child form within the
       form.
       Toolbar contains normally standard and frequently used options in an application like
       debug and Form start options, Form editing options, IDE control option etc.

Q35.   What are the benefits of building applications for components?
Ans.   Components are the main elements of VB applications. VB components are divided
       into the following categories.
       1. Modules 2. Methods 3. Events 4. Controls
       All are useful to develop good component application. Building of an application for
       components, provide the following methods.
       1. Once a component is designed and coded it provide more interaction than the
           character-based program.
       2. Any user can interact with components because components raise events when
           any action is preformed on component. These different actions can manage only
           in component-based programming.
       3. After developing a component, it can be reused in different software’s, so it
           provides reusability.
Q36.   Distinguish between static and dynamic page.
Ans.   A web site contains both the static and dynamic web pages. Both are needed to
       develop to good application.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                21/76

       Static pages: - Static pages are those pages, which provide static information
       means, which can not be modified or changed at runtime. They do not response the
       query of client at runtime. These pages are only view able for different users.
       Dynamic pages: - Dynamic pages of the site provide more user interaction. To
       convert any static page to interactive, scripts are used for both client side and server
       side. Server side Technology (ASP) is also used to make interactive web pages. Any
       user can pass different types of queries and web pages respond according to the
       user’s query.
Q37.   Write VB code to place colored dots randomly on the form.
Ans.   Place a timer control on the form and set interval to 5.
       Specify the following code in the form.
       Dim i As Integer
       Private Sub Form_Load()
       i=0
       End Sub

       Private Sub Timer1_Timer()
       For j = 1 To Rnd * 100
       Me.Circle (Rnd * Me.ScaleWidth, Rnd * Me.ScaleHeight), 1, QBColor(i)
       Me.Circle (Rnd * Me.Width, Rnd * Me.Height), 1, QBColor(i)
       i=i+1
       If i > 14 Then
       i=0
       End If
       Next
       End Sub
Q38.   What are various control structures in VB? Give their syntax.
Ans.   Select Control structure
       Control structure are used to control the flow of program's execution. Visual Basic
       supports control structure such as If…. Then, If…. Then …… Else , Select ….. Case
       and loop structure such as Do While ….Loop, Do… Loop while and For ……Next
       method.
       If…. Then … Else Statement
       The If….. Then block is used for conditional execution of one or more statements.
       If condition then
       Statements
       End If
       The statement is executed only if the condition is true. The condition is usually a
       comparison, but it can be any expression that evaluates a numeric value. If then –
       Else block is used to define several blocks of statements, in order to execute to one
       block. The following block of statement illustrates if…. Else.. End if statement.
       If A =1 Then
                Statements
       Else
                Statements
       End if
       The following example illustrates the If ….. Then.. Else statement.
       E.g.- Illustrate an example to check for the number of digits in a number and display
       a message indicating the number of digits in it within 1000.
        A new Standard EXE project is opened and a TEXT Box and CommandButton is
             added to the Form. The following code is entered in the Command 1_Click ()
             procedure.
       Private Sub Command 1_Click ( )
                If Val (Text1. Text)<10 then
                         MsgBox " It is a Single Digit Number"
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                   22/76

            Else if Val (Text1.Text)<100 then
                    MsgBox "It is a two Digit number"
            Else if Val (Text1. Text )<1000 then
                    MsgBox " It is a Three Digit Number"
            Else
                    MsgBox " The value is more than three digits.
            End if
   End Sub
   The program is executed by pressing F5. When a number is entered in the TextBox, it
   displays a message accordingly.
   Select …… Case statement
   Select …. Case structure is an alternative to If. Then …. Elseif for selectively
   executing a single block of statements from among multiple blocks of statements.
   Select…..Case is more convenient to use than the If… Else …. End if .The following
   program block illustrates the working of Select. Case
     Select case index
            Case 0
            Statements
     Case 1
            Statements
     End select
     Select … Case structure evaluates an expression once at the top of the structure,
     where as If….Then…Elseif evaluates different expressions for each Else If
     statement.
     Do while. Loop statement.

    The Do while. Loop is used to execute statements until a certain conditions is met.
    The following do loop counts from 1 to 100
    counter =1
    Do while counter <101
    Counter =counter +1
    Loop
    The variable counter is initialized to 1 and then the Do While loop starts
    Do….. Loop While Statement
    The Do …. Loop While statement first executes the statements and then tests the
    condition after each execution. The following program block illustrates the structure.
    Counter =200
    Do
    Text1. Text=Str (counter)
    Counter =counter +1
    Loop while counter <501
    The program executes the statement between Do and Loop While structure in any
    case. Then it determines whether the counter is less than 501. If so, the program
    again executes the statements between Do and Loop While else exits the loop.
    Do …. Loop Until Statement
    The Do….. Loop until structure executes the statements until the condition is
    satisfied. It is an infinite loop if the test fails and to get released from this infinite loop
    we can use the CTRL+BREAK combination or End from the Run menu. The
    following code entered in the Form_Load () procedure illustrates the structure.
     E.g. -
    Private Sub Form _Load ( )
    Do
    X$ =Inputbox $ ("Password Please ?")
    Loop Until X$ ="Vanilla Orange"
    End Sub
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              23/76

       The above example checks for the password set to open the Format runtime. At run
       time it asks for the password and until it is entered as "Vanilla Orange" the loop
       remains infinite. Once the correct password is typed in the input box and clicked OK,
       the Form is opened.
       The For ….Next Loop Statement
       The For …. Next Loop is another way to make loops in Visual Basic. The following
       loop counts from 1 to 50.
       for I =1 to 50 step 1
       Text1. Text =Str (I)
       Next
       In order to count from 1 to 50 in steps of 2, the following loop can be used . :
       For 1=1 to 50 step 2
       Text1. Text =Str (I)
       Next
       The loop counts as 1,3,5, etc.
       Exit For and Exit Do statement
       A For ….Next loop can be terminated by an Exit For statement . Consider the
       following statement block.
       For I= to 100
       Text1.Text =Str (I)
       If 1=50 Then
       Exit for
       End if
       Next
       The proceeding code increments the value of I by 1 until it reaches the condition
       I =50. The Exit for statement is executed and it terminates the For … Next loop. The
       following statement block –containing Do… While loop is terminated using Exit do
       statement.
       I=1
       Do while I<1001
       Text1. Text <1001
           I=I+2
        If I>500 then
                Exit Do
       End if
       Loop
       With –End With Statement
       When properties are set for objects or methods are called, a lot of coding is included
       that acts on the same object. It is easier to read the code by implementing the With-
       End with statement. Multiple properties can be set and multiple methods can be
       called by using the With End With Statement. The code is executed more quickly and
       efficiently as the object is evaluated only once. This concept can be clearly
       understood with the following example.
       With Textprice
       . Font. Size =16
       . Font. Italic =True
       . Height =235
       . Text="Welcome to Visual Basic6.0"
       End with
       In the above coding, the object Text price (The Name property of Textbox has been
       changed to text price) is evaluated only once instead of being evaluated for every
       associated property or method. This makes the coding simpler and efficient.
Q39.   (a) Explain various data types available in VB.
Ans.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                    24/76

       Data types available in VB
        Data       Memory                Range
        type       (Bytes)
        Byte       1                     0 to 255
        Integer    2                     -32,768 to +32767
        Long       4                     -2147483648 to 2147483647
        Single     4                     -3.402823*103 to –1.401298*1045 for negative values
                                         1.4401298*10-45 to 3.402823*1038 for positive values.
        Double       8                   -1.79*10308 to –4.94*10-324 for negative values
                                         4.94*10-324 to 1.79*10308 for positive values
        Currency     8                   -922,337,203,685,477.5808 to 922,337,203,685,477.5807
        Boolean      2                   True or False
        Date         8                   January 1, 100 to December 31, 9999
        String       1                   0 to approx. 2 billion character.
        Variant      16                  A general-purpose variable that can hold any type of
                                         variable values.
        Object       4                   A variable declared as an Object can have any object
                                         reference assigned to it.

(b)    Explain various relational and logical operators in VB.
Ans.   Operators are symbols used in an expression to perform operations on the operands.
       There are different types of operators in VB.
       Relational operators
       <       Less than
       <=      Less than or equal to
       >       Greater than
       >=      Greater than or equal to
       =       To compare equality
       <>      Not equal to
       less than(<) : return true if first value is less than second.
                        Less than or equal to (<=): return true if first value is less than or equal
                        to the second
       greater than (>) : return true if first value is greater than second
                        greter than or equal to (>=) : return if first value is equal to or greater
                        than second
       equal to (=) : return true if both values are equal
       not equal to(<>) : return true if one value is not equal to the second

       Logical operators: - Logical operators are used to combine the result of two
       expressions to a common result. These operators are
       1. AND 2. OR 3. NOT
       1. AND: - It combines the result of two expressions. If the result of both the
          expressions return true then the result of AND is true else false.
       2. OR :- If one of the expression produce true result than the result of or is true
       3. NOT :- to create complement of the expression’s result.

Q40.   Write a program that reads in the radius of a circle as an integer and print the
       circle diameter, circumference and area on the form using print method.
Ans.   Place a command button on the form and do the following code in the code window
       Private Sub Command1_Click()
       Dim r As Integer
       Dim d As Integer
       Dim cf, a As Double
       r = InputBox("Enter radius")
       d=2*r
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                            25/76

     cf = 2 * 3.142 * r
     a = 3.142 * r * r
     Print "Radius       :", r
     Print "Diameter       :", d
     Print "Circumference :", cf
     Print "Area        :", a
     End Sub
Q41. WAP that prints 100 asterisks to the form one at a time. After every tenth
     asterisk your program should print a line break.
Ans. Place a time control on the form and its interval property to 100.
     Timer1.interval=100
     Write the following code in the code window
     Dim i As Integer
     Dim j As Integer
     Private Sub Form_Load()
     i=1
     j=1
     End Sub

       Private Sub Timer1_Timer()
       Print "*     ";
       i=i+1
       j=j+1
       If j > 10 Then
       Print
       j=1
       End If
       If i > 100 Then
       Timer1.Enabled = False
       End If
       End Sub

Q42. What is the difference between Event driven programming and procedural
     Programming?
Ans. There different types of programming. And different languages at least support one of
     them. We can categorize the programming into the following types.
     1. Unstructured 2. Structured / procedural 3. Object Oriented 4. Event driven.
     1. Unstructured programming: - There is no specific flow of the program code,
         control can be transferred from any where to any part of the program. More and
         more use of Go To statement in the program helps to make the program
         unstructured.
     2. Procedural programming: - In procedural programming, the program is divided in
         to the small sub blocks. These blocks are called procedures and these
         procedures execute their source code by calling. Procedural programming helps
         to make debugging easy.
     3. Object Oriented programming: - This programming is based on the objects and
         classes.
     4. Event driven programming: - Event or actions are performed on the specific
         component and components respond according to these actions and execute the
         code written under the event procedure.. Normally event procedures are local to
         the form in which they are declared and have private access.
Q43. What is a variant? What are the advantages and disadvantages associated with
     the use of variants?
Ans. Variant is a default data type. When you declare variables implicitly they
     automatically got declared in VB, this data type is known as variant type in VB. The
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              26/76

       variable declared as variant can hold the value of any type. The memory space taken
       by the variant variable is 16 bytes.
       Variant Type provides a number of advantages -
       1. They can hold any type of values
       2. It will automatically adjust and convert type accordingly to the value stored into
           the variable.
       3. Very useful, when implicit declaration is used in the program.

       Disadvantages
       1. It automatically declares the variables, which are not declared explicitly in the
          application, the use of these variables in the program, makes the program more
          error prone. The errors caused by these variables are difficult to find.
       2. Another disadvantage of variant data type is that, it consumes more memory
          spaces as compare to the other data types.

Q44.   Write a VB code in a click event of a Button to draw “X” across a form by using
       line function.
Ans.




       Private Sub Command1_Click()
       Me.Line (Me.ScaleLeft, Me.ScaleTop)-(Me.ScaleWidth, Me.ScaleHeight)
       Me.Line (Me.ScaleWidth, Me.ScaleTop)-(Me.ScaleLeft, Me.ScaleHeight)
       End Sub

Q45.   Find the number of items in a combo box. How you will set the item number of
       2 top most items in the visible portion of the list box?
Ans.   Following program will count the number of items in the combo box and will set the
       item number of 2 top most items in the visible area of the list box. Using following
       steps.
       1. place one combo control,list control and two command buttons.
       2. add item in combo using the list property of the combobox
       3. Write the following code to count number of items in the combobox with help of
           button.
       Private Sub Command1_Click()
       MsgBox Combo1.ListCount
       End Sub
       4. To place 2 top most items of the combo box in the list control, write the following
           code
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              27/76

        Private Sub Command2_Click()
        List1.AddItem (Combo1.List(0))
        List1.AddItem (Combo1.List(1))
        End Sub




        Section – B                                              2 Marks Questions
      [Question 1 TO 35]                                           [PAGE 26 TO 29]
Q1.     Describe difference between testing and debugging.
Ans.    Testing is the procedure to check the application if it is working properly and
        according to the requirements specified before coding or not.
        Whereas Debugging is the technique to find errors and removing them, so that the
        application could work properly.
Q2.     Differentiate between control array and control collection.
Ans.    Control array can contains number of controls but of same type whereas the control
        collection can contain a group of controls of heterogeneous type i.e. various type of
        controls could be the part of a control collection.
Q3.     How will you define a menu hot key?
Ans.    Hot keys related to menus are used to activate any specific menu on the contribution
        of Alt Key with specific Key.
        We can set Hot Key to any menu by inserting (&) ampersand sign before the letter
        used for hot key in the caption property of the menu editor.

Q4.     What is the name of two controls required for creating a toolbar?
Ans.    Toolbar contains frequently used options in an application. To design our own
        toolbars, there are two types of control provided by Window common controls]
        These are
          1. Toolbar
          2. Image List control
Q5.     How form templates are useful while creating a toolbar?
Ans.    Templates contain pre-formatted design of specific options. Using these templates
        we can design specific type of application. Form template helps us to
Q6.     Differentiate between MDI and SDI.
Ans.    Single Document Interface is an application that can support only one document
        at a time.
        Multiple Document Interface allows you to create an application that maintains
        multiple forms within single container form. An MDI application allows the user to
        display multiple documents at the same time with each document display in its own
        windows.
Q7.     Explain immediate windows briefly.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              28/76

Ans.    The immediate window is a window inside the visual basic environment in which you
        can view program values and can print the message during the program’s execution.
        This window is used normally to get immediate results of any execution.
Q8.     What is native code and P-code?
Ans.    Visual basic used to produce executable program file in p-code i.e. (pseudo code – it
        is a technique for expressing operation of a computer program or an algorithm in a
        natural language such as English. It was develop as an alternative of a flow chart)
        rather than native code. But with the later versions of visual basic the compiler
        started translating the visual basic, which people can understand, into executable
        programs consisting of native machine code that computer can read and understand.
Q9.     What do mean by breakpoint?
Ans.    A breakpoint works as a marker in the code that tells the visual basic where to
        suspend the program execution. Breakpoint is purely temporary in nature means it is
        not stored permanently in the code. It is used to open the VB code in debug mode.
Q10.    Explain the debug. print statement.
Ans.    This print method sends the output to the immediate window. This could be done by
        including the following statement in the code
        Debug. Print [item];
Q11.     What is an array .How to declare an array?
Ans.    A sequence of variable by the same name can be referred using arrays. The
        individual elements of an array are identified using an index number.
         e.g.-Dim salary (9) as integers
Q12.    List three important properties of a command button.
Ans.    Caption: This property specifies the text that appears on the command button.
        Picture: This property specifies a graphic image that appears on the command
        button in place of caption.
        Style: This property specifies whether a command button display a text caption or
        picture.

Q13.    Name the functions used to create menus with Bitmaps.
Ans.    Functions used to create menu with bitmaps are:
        1. GetMenu( )
        2. GetSubMenu()
        3. ModifyMenu( )
        4. CreateCompatibleDC( )
        5. CreateCompatibleBitmap( )
        6. SelectObject( )
Q14.    What do you understand by term debugging?
Ans.    Debugging a program means correcting the errors in the program while it is running.
        Immediate window is used help in debugging a program, which is running in visual
        basic. Immediate window helps to display the values of the program variables,
        change the value of the variables. During debugging, you can insert statement in the
        code, change the value of variable and then continue running your program
Q15.    Define the RGB( ) function.
 Ans.   For defining colors, visual basic provides the RGB() function, which accepts three
        arguments.
        RGB (Red, Green, Blue)
               With RGB() function, you can define any color. The red, green & blue
        arguments accept values from 0 to 255. e.g. to change the background color. The
        red, green & blue arguments accept values from 0 to 255 e.g. to change the
        background color, you can write form1.backcolor = RGB (255,255,0).
Q16.    What is pop up menu?
Ans.    Pops up menus are also called context menu or shortcut menu that the user can
        invoke by right clicking a form or control. This pop up menu is regular menu & can be
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                             29/76

       displayed anywhere on the form. Pops up menus are invoked with the PopUpMenu
       method.
Q17.   Explain the difference between Modules & Class modules.
Ans.   Modules store variable declarations and code, which are available to all the other
       components of an application. But if procedures are to be used for several projects
       then class Modules are built.
Q18.   What is ReDim statement?
Ans.   Redim statement is used to define the size of an array dynamically at runtime. This
       statement is used when we want to change the size of an array at runtime.
       syntax
       ReDim FirstArray ( 4 to 12)
Q19.   What is the use of Preserve Statement in VB?
Ans.   Preserve statement is used with Redim statement to define array size dynamically.
       Using the preserve keyword we can preserve the old values given to the different
       memory elements of an array. while increasing the size with Redim.
Q20.   What is Step Into, Step Over and Step Out?
Ans.   The Step Into option is used to execute one line of code at a time. This is handy
       when you want to continuously monitor your application as you go through it line by
       line.
       The Step Over option allows you to step over a procedure or function call without
       having to single stepping through its individual lines of code.
       The Step Out option moves the program execution back to the calling procedure.
       This is the functional equivalent of Exit Sub or Exit Function. It simply exits the
       current procedure without executing any more code in that procedure
Q21.   What is the difference between a drop-down menu and a pop-up menu?
Ans.   Drop down menus show their options by clicking on the menus and we can select
       one of the option from the list by just clicking on it. Whereas popup menu appears by
       right click on the control to select the specified option from the menu.
Q22.   How is an event procedure created, viewed or edited?
Ans.   Event procedures are created by using add procedure option of Tools menu by
       opening code window. We can edit and view event procedures in code window.
Q23.   What do you understand by control array?
Ans.   Control array is the array of controls. To create the array of control just place the
       control on form at design time, then copy paste it again and again. By making the
       control array, similar type of code can be used for multiple controls.
Q24.   What is syntax error and error handler?
Ans.   Syntax error appears when you misspell any instructions or variables. Error handler
       is the mechanism used to find errors and to debug them. There are different types of
       tools provided by vb to handle logical errors. Like -step into, stepout, step over,
       immediate window, local window, watch window etc.
Q25.   What is module and procedures?
Ans.   Module is the collection of procedure and variables. Procedures are subroutine or
       function that can contain specific set of codes that will execute whenever the
       procedure is called or specific event is fired.
Q26.   What single stepping is and how you use it to debug?
Ans.   Single stepping is the process to run code line by line. This is accomplished by step
       into option use to find logical error in the debug process.
Q27.   What is the difference between subroutine and functions?
Ans.   Subroutine and function both are the types of procedures.
       Using function we can return a value to calling function whereas nothing is returned
       by subroutine to the calling function.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 30/76

Q28.   How does a menu vary from a toolbar?
Ans.   Menus are the drop down instructions. These instructions appear whenever we click
       on a specific menu whereas toolbar contains different type of tools having specific
       instructions. And these instructions are execute by clicking. Toolbar helps to visualize
       the instructions so that the user can easily understand the purpose of the instruction.
Q29.   What is the purpose of a dialog box?
Ans.   Dialog boxes are used to provide information and to receive information from the
       user at runtime. The dialog boxes are of two types.
       Model and modeless
       From model dialog box, the control cannot be transferred to the parent dialog box
       without closing the dialog box whereas control can be transferred to the parent dialog
       box without closing the dialog box in modeless dialog box type.
Q30.   What is the purpose of the inputbox function? How does the input box function
       differ from the msgbox function?
Ans.   Input Box and message box both are modal dialog boxes. But the message box
       dialog box is completely a message window that provides the user message only
       whereas input box contains a textbox that can take data as input, and then it
       produces the result on the basis of input data.
       Syntax for Inputbox
       Inputbox(“prompt”,”title”,”defaultvalue”,startx,starty)
       Syntax for MessageBox
       MessageBox(“prompt”,”title”,messageboxstsyle)
Q31.   How is the watch window opened with in the visual basic environment?
Ans.   We can open the watch window by opening the form’s code in debug mode. Then
       select option watch window from the debug menu.
Q32.   What are error codes? How can error codes be used with in an error handler?
Ans.   Error codes are the specific numbers given to the specific errors. These are helpful to
       set specific types of messages regarding the specific error.
Q33.   What is a modal form? How can a form be displayed as a modal once it has
       been loaded?
Ans.   Modal forms are the forms that never transfer the control to the parent form unless or
       until it is closed or unloaded. To display any form as modal just specify the 1 in the
       show () method to the form
       e.g
       formname.show(1)
Q34.   What is a separator bar and how is it created?
Ans.   A Separator bar is a line, which separates the menu items. It is mainly useful for
       obtaining clarity. In the Caption TextBox ‘-‘ is typed and assign name like ‘mnuSep’ in
       the Name TextBox. This adds a separator line, which is drawn between the menu
       items.
Q35.   Write steps to create an MDI application.
Ans.   The Multiple Document Interface allows you to create an application that maintains
       multiple forms within a single container form. To create an MDI form and its child
       form use following procedure.
       1.        Create MDI formby adding MDI form from project menu.
       2.        Create the applications child form by setting forms MDI child property to true.
Q36.   Differentiate between procedural programming and event driven
       programming?
Ans.   Events are various things that can happen in a program. In the procedural language
       a written application is executed by checking for the program logically through the
       program statements one after the another. But in event driven application the
       program statement are executed only when a particular event calls a specific part of
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                             31/76

       the code i.e. assign to the event e.g. text box events are change, click, mouse move
       etc.




     Section – B                                            5 Marks Questions
 [Questions 1 TO 39]                                         [PAGE 30 to 44]
Q1.    Write a short note on Procedure and their types.
Ans.   Procedure
       Visual Basic program can be broke into smaller logical components called
       procedures. Procedures are useful for condensing repeated operations such as the
       frequently used calculations, text and control manipulation etc. Following are the
       benefits of using procedures in programming.
        It is easier to debug a program with procedures, which breaks a program into
           discrete logical limits.
        Procedures used in one program can act as building blocks for other programs
           with slight modifications.
       Procedures can be Sub, Function or Property Procedure.
       Sub procedures
       Sub procedures can be paced in standard, class and form modules. Each time the
       procedure is called, the statements between Sub and End Sub are executed. The
       syntax for a sub procedure is a follows.
       [Private | Public] Sub procedurename [arglist)]
       [Statements]
       End Sub
       arglist is list of argument names separated by commas. Each argument acts like a
       variable in the procedure. There are two types Sub Procedures – general procedures
       and event procedures.
       Event Procedures
       An event procedure is a procedure blook that contains the control's actual name, an
       underscore (_) and the event name. The following syntax represents the event
       procedure for a Form_Load event.

       Private Sub Form_Load ( )
       .. Statement Block ..
       End Sub
Q2.    Explain modules and its various types in detail.
Ans.   Module is a block of code that performs a specific task and is complete in itself.
       Modules can be defined as collection of code that performs a specific task. This code
       is hidden from rest of the coding on the form. There are three types of modules in VB.
       1. Form Module
       2. Standard Module
       3. Class Module
       1. Form Module: The form that you see on the screen is a representation of the
       properties that define its appearance. For each form in an application, there is a
       related form module that contains its code and the form module is created in the file
       with extension .frm.
       Each form module contains event procedures which is section of code to response to
       specific code. Forms can contain controls & for each control on the form, there is
       corresponding set of event procedures in the form module. Form module can contain
       sub procedure, event procedures and function procedures. E.g. Form_load() is a event
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              32/76

       procedure written for each form on the project if needed and responds when the form
       is loaded.
       2. Code Module/Standard Module: When larger projects are built in VB, then
       developer wants to reuse the code as much as possible. For this reason procedures
       and functions are stored in separate modules rather than attaching them to forms.
       A standard or code module is set of code that you want, to make accessible
       everywhere in the project. Standard module has no visual components & is useful for
       reusing the code. So a module or standard module has a global scope. Code modules
       are maintained in a separate folder in project explorer window and these files are
       stored with .bas extension on hard disk.
       3. Class Module: Class module is used to create objects that can be called from
       procedures within your application classes. Standard module contains only code & a
       class module contains both code & data. Standard module can never have more than
       one copy but class module data exists separately for each instance of the class. Class
       module helps VB to be an object-oriented language. For each class module you have
       to create an object of that class.
       The data in a standard module has a program scope i.e. it exists for the life of your
       program while class module data for each instance of a class exists only for the
       lifetime of object.
Q3.    Explain types of dialog boxes.
Ans.   There are three kinds of dialog boxes.
       1) Modal dialog box
       2) Modeless dialog box
       3) System modal dialog box

       Modal dialog box: - Model dialog boxes can be called as application modal dialog
       box. This dialog box insists the user to respond to them, before continuing in the same
       application. A modal dialog box can stop the running of your code until it is being
       closed or being hidden. The show method of form uses VbModal style to load the form
       as a modal dialog box. e.g.
       Form1. Show VbModal.

       Modeless dialog box: - Modeless dialog box do not need to be closed to loose their
       focus. They are just like any other form in your application and loose their focus as
       soon as you click some other window outside the application. A form is by default
       loaded in this state if no arguments are supplied to show method.
       System modal dialog box: - A system model dialog box restricts the user from
       continuing work on the system unless it gets unloaded. Screen saver with passwords
       is example of system modal dialog box. The show method doesn’t have this style but
       in order to call a default message box in a system modal style, we can use the
       following syntax.
       MsgBox “Message string “, VbOkOnly + VbSystemModel.
Q4.    Write a note on POP-UP menu.
Ans.   A popup menu is floating menu that is display over a form independent of the menu
       bar. Popup menus are also called context menus, because the items displayed in the
       pop up menu depend on where the pointer is located when the right mouse button is
       clicked.
       Any menu can be display as a pop up menu at run time provided it has menu item.
       The following code displays the colours menu when the user clicks the right mouse
       button over the form at run time.
       Private sub_form_MouseDown (Button As Integer, Shift As integer, X As Single, Y As
       Single)
       If button =2 then
       PopUpMenu mnuColors
       End if
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  33/76

          End Sub
Q5.       Write a note on Dragging and Dropping.
Ans.      Dragging is the process of clicking the mouse button in a control and moving the
          mouse while holding down the mouse button. The action of releasing the mouse
          button after the dragging is called Dropping. The following dreg and drop
          properties,events and methods are supported by VB-
         DragMode property enables automatic or manual dragging of a control
         DragDrop event is recognized when control is dropped onto object
         Drag method starts or stops manual dragging.
Q6.       Write a short note on common dialog boxes.
Ans.      A common work in most of the applications is to prompt user for filenames, selecting
          files to open, saving the file on hard disk, font names & sizes or colors to be used in
          applications. Common dialog control is peculiar & provides services to the application
          but is not displayed on the form at design time. Common dialogs control provides
          built-in windows dialog boxes.
          1. Open - File open common dialog box lets user select a file to open.
          2. Save As - File save common dialog box lets users select or specify a file name in
               which current document will be saved.
          3. Color - The color dialog box lets user select colors or specify custom colors.
          4. Font - Font common dialog box lets user select font &style to be applied to
               current text selection.
          5. Print - Print common dialog box lets user select and set up a printer.
          6. Help- help common dialog box displays help topics.
Q7.       Explain immediate window.
Ans.      Whenever an application of VB is interrupted in run time by pressing -Ctrl+Break, a
          window is shown at the bottom of the screen called immediate window. When Visual
          basic commands are issued in this window, they execute immediately with the help of
          immediate window, you can see the control flow of the program & can work out which
          events are fired at what time. It is a debugging aid & when an application is running,
          you can stop it and use the immediate window to examine or change the values of
          the applications variables. You can step into the code of the application while it is
          executing & can change the value of the variables & can even insert statements in
          the code & then continue the execution of an application.

          Immediate window can act as a calculator. For example if you enter following
          statement in immediate window.

          Print 1888/999 & press enter. The following result will be displayed-
          1.889889889
Q8.       Explain the following.
          1. Rnd function.
          2. Date function.
          3. Time function.
          4. Strcomp function.
          5. Instr function.
Ans.      Rnd function: - Rnd function generates random numbers that doesn’t follow any
          pattern. For example- If you write the following code in the form click event.
          Private sub form – Click ()
                   Dim I as integer
                   For I = 1 to 5
                           Print Rnd
                   Next I
          End sub
          It will generate five random numbers between 0 & 1.
          Date function: - Date function displays the system date eg.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  34/76

       Text 1. Text = Date
       It will display the system date in the textbox.
       Time function: - The time function will display the system’s current time. eg
       Text1. Text=Time
       It will display system time in the text box.
       Strcomp function: - This function can be used to compare strings. The strcomp
       function will returns a value, such as for example
       E.g.-If you set X=strcomp (A $, B $), then value of x is, –1 if A$ is less then B$, 0 if
       A$ equals to B$, 1 if A$ is greater than B$ and the value of x will be NILL if any
       variable is empty.
       Instr() function :- Instr function tells you whether the first string is a part of the
       another string or not and also it will tell you the position from which the first string
       starts within the another string. The syntax is
       Instr [string1, string2, compare]
Q9.    Write a short note on Rich Textbox control.
Ans.   Rich textbox control is a full-fledged word processor; it provides all the functionality of
       a textbox         control and gives you capability to mix different fonts, sizes and
       attributes. You can place images in your text, on a rich textbox control.
       Main property of rich textbox control is Text property & it contains the Text, which is
       currently being displayed by the control. You can use Rich Textbox control to specify
       the text’s formatting including paragraph indentation, font, font size & style etc. The
       control provides simple properties that turn the selected text to bold, italics, underline &
       so on. The two important methods of Rich textbox control are save file that saves the
       contents of control on the disk and can load file that loads the contents of file from the
       disk.
Q10.   Explain the terms passing by value & passing by reference.
Ans.   When you call a function or procedure, there are two ways to pass an argument.
       1. Passing by reference.
       2. Passing by value.
       When you pass an argument variable by reference, any changes to the corresponding
       parameter inside the procedure will change the value of the
       Original argument when the function or procedure finishes, when you pass an
       argument by value, then original variable retains the original value even after the
       procedure finishes. For example
       Sub Triple (Num as Integer)
       Num = 3 * Num.
       Print “ I am in the procedure (pass by reference)”
       End sub.
       Sub triple (BY Val Num as integer)
       Num = 3*Num.
       Print “ I am in the procedure (Pass by value)”
       End sub.
       In visual Basic, passing an argument by reference is default. If we have to pass an
       argument by value then we have to specifically mention the keyword ‘By Val’.
Q11.   What do you understand by term property pages?
Ans.   Active controls can have property pages. Property pages are similar to the properties
       window and they allow the developer to set the control’s properties. Properly pages
       are better and have more flexible user interface.
       The properties you set through the properties windows apply to the entire control but
       the property pages of the control contain several pages on which related properties are
       grouped. Property pages of a control can be displayed by Right clicking the control &
       then by selecting properties from the pop-up menu .We can design the property pages
       through the property page wizard.
Q12.   How an array can be passed to a function?
Ans.   An array can be passed to a function in two ways.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 35/76

       1. By reference or by value of the elements when the function supports one single
            argument only.
       E.g.
       Dim A(5) as integer
       For x = 0 to 4
       Print Sqrt ((x))
       Next
       2. By reference when the function supports an array argument
       Example.
       Private function Fun (y () as integer) As Integer
       Dim Z(3) as integer
       For I = 0 to 2
       Z (I) = Y (I) + Y (I)
       Next I
       Fun = Z
       End function
Q13.   What do you understand by file system controls?
Ans.   File system controls in visual basic allow the users to select a new drive, to see the
       hierarchical directory structure of disk or to see the names of the files in a given
       directory. For using these controls you have to write code to take the full advantage
       of these controls. There are three main controls named DirList Box, DriveList Box &
       FileListBox. Dirlistbox displays all the directories present in the selected drive of the
       computers and of any other drive attached to the computer. File list box displays the
       files present in the current directory .We can attach these controls with each other so
       that when a drive is selected then all its directories should be displayed in the
       DirListbox and when a directory is selected then all its files should be displayed in the
       file list box. File system controls; let you to control the file system of the computer.
Q14.   Describe Menu Editor in VB.
Ans.   Menu editor is used to create new menus and members to add new commands to
       the existing menus, to replace the existing menu commands with your own
       commands and to change and delete existing menus and members
                 To display the Menu Editor
                 From the Tools menu, choose Menu editor
                 Or
                 Click the Menu editor button on the toolbar.
       The two most important properties for menu controls are:
       1.        Name: - This is the name you use to reference the menu control in the code.
       2.        Caption: - This is the text that appears on the control.
Q15.   Discuss the file handling facilities of VB.
Ans.   When we want to store data in visual Basic it can be in two forms: a database or an
       ASC || file. ASC|| files contain data of all types and can be formatted in a comma-
       separated values list; Three modes of files are-

       1.     Sequential
       2.     Random Access
       3.     Binary
       Sequential: - When you want to store or retrieve data in VB you may choose to
       create a sequential file. A sequential file is a series of lines of text in ASC|| format.
       Random access: - Random access also works to retrieve data from ASC|| files, but
       you have greater flexibility when you use it instead of sequential mode. Random
       access allows you to position yourself anywhere within the file at any time to get the
       data you need.
       Binary Mode: - Binary mode allows you the greatest amount of flexibility when
       working with files. When working with binary access mode, you retrieve data
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               36/76

       sequentially and in chunks; - the binary mode. The number of bytes read form the file
       equals the size of the string, in bytes that you want to read data into.
Q16.   Explain the menu creation through menu editor in visual Basic.
Ans.   To design menu, click on the tools menu and then select Menu editor. Menu editor
       dialog box will appear.
       Enter caption property and Name property in the first two boxes of menu editor.
       You can also choose a short cut key for the current menu control
       The left and right arrow buttons are for indenting and out denting menu controls. A
       menu title must be flush with the left margin of the menu list box at the bottom. A
       menu item is usually indented once. You would indent a second time to create a
       submenu item (cascading menu) from the previous menu item.
       The up and down arrow buttons are for changing the order in which menu titles and
       menu items appear.
       You can type a number in the index field to make the menu control array. These are
       useful when you want to list like the ones you see at bottom of file menu in various
       applications.
       The help control ID field in used to link the help menu to a help file through a unique
       identifies called help context.
       Finally the Negotiate Position field is used to determine where a top-level menu
       would be positioned when an MDI child form is maximized and both forms must
       share the menu bar of MDI parent form.
Q17.   Explain the tasks involved in debugging the visual basic application.
Ans.   Debugging is a process by which errors are identified and resolved in source code.
       Typically, debugging is conducted at various levels. These levels are termed as-
       Level1 debugging, level2 debugging, and level3 debugging.
       Level1 debugging: The first level of debugging is the implementation of a debugging
       procedure and the necessary tuning to make it operate as expected.
       Logical errors occur when the application does not perform as intended and
       produces incorrect results. When a programmer sets to write a procedure, he/she
       would have in mind only the expected output of that procedure. As the developer
       goes about writing the procedure, he/she finds a better method that solves many
       more constraints, thereby working better in the worst of circumstances also. This
       fine-tuning and developing of code functionality in such a way that the program runs
       efficiently in called level1 debugging.
       Level2 debugging: Second level debugging is the activity required to make a
       functional unit of code interact according to plan with other units of code, typically
       before shipping or deploying the completed project. Generally this condition arises
       when the user’s procedure does not run properly in a test case.
       Level3. Debugging: Level3 debugging is primarily the diagnosis and repair of
       problems occurring in applications that have already been deployed. These bugs are
       often the most difficult to locate because they occur on a remote machine. They may
       be the result of unanticipated circumstances. These may be one of the following:
       User actions
       Program configuration
       System configuration
Q18.   Explain the function and use of Err Object.
Ans.   ErrObject is a class in VB to handle errors. It has number of properties and functions.
       1.Clear: - This method is to clear all the property settings of the error object.
       2.Description: - Return or sets the string expression with a descriptive string
       associated with the error objects.
       3.HelpContext: - Return or sets a context ID for a topic in a help file.
       4.Helpfile: - Return or sets the fully qualified path for help file.
       5. Last DLL error: - Returns the system error code by call to DLL.
       6.Number: - Returns or set a numeric value representing an error.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 37/76

       7.Raise: - This function will generate an error at runtime.
       8. Source: - Returns or sets the name of the object that has originated the error
Q19.   Write a VB program that takes a number from the user with an input box and
       which will displays its multiplication table in the immediate window.
Ans.
       Dim n As Integer
       n = Input Box("enter number")
       For i = 1 To 10
               c=n*i
               Debug. Print n, "*", i, "=", c
       Next
Q20.   What modality is and how does it affect the behaviour of your dialog boxes?
Ans.   Modality means whether the dialog box will give its control to the next dialog box or
       form without being closed or unloaded or not. There are two types of dialog boxes.
       1 Modal
       2.Modeless
       1. Modal: - if the dialog box is of modal type then the control will not be transfered to
       their master form until the necessary information has been ginen to the dialog box or
       it has been closed. E.g of these dialog boxes are msgbox ,inputbox in VB.
       2. Modeless: - if the dialog box are modeless type then the control can be transferred
       to the master form without closing the dialog box. E.g of this type of dialog box is
       find & replace dialog box.
Q21.   What do you understand by bug (error)? What are the different types of bugs
       that you may encounter while programming with visual basic?
Ans.   Bugs are the errors. Bugs appear in the VB application at different situation and can
       terminate the VB application abruptly. Some bugs will not terminate the application
       but will insist the produce to produce the wrong result. All these bugs are divided to
       the following categories.
       Syntax bug: These errors occur when we enter an incorrect line of code. Such as a
       mistake in typing a keyword, a punctuation is missing or an incorrectly spelled
       variable.
       Runtime bugs: These occur when a command attempts to perform an action that is
       not valid. For example, a runtime error occurs if we try to assign a string to a numeric
       variable. Error handler executes only if a run-time errors encounters.
       Logical bug: Occurs when an application executes without syntax error or run-time
       errors, but the results are not what we intend or correct. For example, an application
       might prompt the user for a password but then may not allow access to the
       application even if the password is correct.
Q22.   What are the common errors in the visual basic?
Ans.   In VB the error can be divided into the following category.
       Syntax errors: These errors occur when we enter an incorrect line of code. Such as
       a mistake in typing a keyword, a punctuation is missing or a misspelled variable.
       Runtime error: These occur when a command attempts to perform an action that is
       not valid. For example, a runtime error occurs if we try to assign a string to a numeric
       variable. Error handler executes only if a run-time error encounters.
       Logic Errors: Occurs when an application executes without syntax error or run-time
       errors, but the results are not what we intend. For example, an application might
       prompt the user for a password but then may not allow access to the application
       even if the password is correct.
Q23.   Write a program that verifies the order in which the events occur for the user
       control. Use debug.print statement to display the name of each event as it
       occurs.
Ans.   Using the following code we can find the order of the occurrence of events in the user
       control and we can print the message on the debug window.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                38/76

       Private Sub UserControl_Initialize()
               MsgBox "inalizining event"
               Debug.Print "inalizining event"
       End Sub

       Private Sub UserControl_Paint()
               MsgBox "painting event"
               Debug.Print "painting event"
       End Sub

       Private Sub UserControl_Resize()
               MsgBox "resize event"
               Debug.Print "resize event"
       End Sub

       Private Sub UserControl_Terminate()
               MsgBox "terminate event"
               Debug.Print "terminate event"
       End Sub

Q24.   Describe the basic concept of array handling in visual basic.
Ans.   Array is the group of elements with single or similar name and with similar data type
       in continues memory locations. Concept behind defining the array in vb is that it is
       difficult to manage a number of variables. But by using array we can specify a
       number of variables in a single array variable, which are using the same data type
       and can be given different values using the different index values of an array. The
       following syntax is used to define the array in VB.
       Syntax
       Dim variable (upperbound) as datatype
       e.g
       dim rollno(5) as integer
       In vb we can create the array of controls by defining the same control a number of
       times in the form. This makes the control handling process easy. A single event,
       which is common to all the controls, can be recognized by different controls present
       in an array with their index numbers.
       We can create the array of control by inserting the control on the form and then by
       using copy and paste option at design time of the form.
Q25.   Explain DLL and immediate window.
Ans.   DLL Stands form Dynamic linking library. A DLL file is a file that contains one or more
       functions and it is compiled, linked, and stored separately from the processes using
       it. The operating system maps the DLLs into the process's address space when the
       process is starting up or while it is running. The process then executes functions in
       the DLL. In VB we can create DLL using ActiveX DLL project.
       Immediate window: - Show the immediate result of the calculation performed in
       debug window. Print method of debug object is used to send the output to the
       immediate window. So this window is a part of the debug process in VB which is
       used to make the VB code error free. We can find result of an expression by
       calculating directly in immediate window in break mode.
Q26.   Explain the difference between SDI and MDI applications. Give suitable
       example.
Ans.   Visual Basic provides a great deal of flexibility, allowing you to configure the working
       environment, which best suits, your individual style. You can choose between a
       single or multiple document interface and you can adjust the size and positioning of
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              39/76

       the various Integrated Development Environment (IDE) elements. Your layout will
       persist between sessions of Visual Basic.
       SDI or MDI Interface
       Two different styles are available for the Visual Basic IDE: single document interface
       (SDI) or multiple document interface (MDI). With the SDI option, all of the IDE
       windows are free to be moved anywhere on screen; as long as Visual Basic is the
       current application, they will remain on top of any other applications. With the MDI
       option, all of the IDE windows are contained within a single resizable parent window.
       Any single document interface can be converted into a multiple document interface
       by setting the value of the MDICHILD property of a form as true.
       e.g. in Vb project the following form is created to perform calculate the sum of two
       numbers. And another form shows the welcome message.after inserting an MDI form
       in the project. We can convert these SDI form into the MDI with the help of
       MDICHILD properties of these forms

       Single Document Interface First Form




       Single Document Interface Second Form




       set firstform.mdichild=true
       set secondform.mdichild=true
        to change this interface to multiple document interface.
Q27.   Explain in detail the On Error and the Resume Next statement.
Ans.   Enables an error-handling routine and specifies the location of the routine within a
       procedure; can also be used to disable an error-handling routine. Without an On
       Error statement, any run-time error that occurs is fatal: an error message is
       displayed, and execution stops.
       Syntex: On Error { GoTo [ line | 0 | -1 ] | Resume Next }
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 40/76

       GoTo line
       Enables the error-handling routine that starts at the line specified in the required line
       argument. The line argument is any line label or line number. If a run-time error
       occurs, control branches to the specified line, making the error handler active. The
       specified line must be in the same procedure as the On Error statement, or a
       compile-time error will occur.
       GoTo 0
       Disables enabled error handler in the current procedure and resets it to nothing.
       GoTo -1
       Disables enabled exception in the current procedure and resets it to nothing.
       Resume Next
       Specifies that when a run-time error occurs, control goes to the statement
       immediately following the statement where the error has occurred and the execution
       continues from that point. Use this statement rather than On Error or Go To
       statements while accessing objects.

Q28.   Explain break mode.
Ans.   It halts the operation of an application and gives a snapshot of its condition at any
       instant, as the program is still active; only its execution is temporarily suspended. All
       variables retain their values properties and statements. In this mode you can modify
       an applications code, or can observe the applications interface condition or you can
       also determine the active procedures that have been called or you can even change
       the program flow.
       If visual Basic encounters any of the below mentioned statements, then it enters into
       the Break Mode.
       Breaks point
       Stop statement
       Break mode can be entered manually in several ways.
       1. Press ctrl + Break
       2. Select the Break button on the toolbar
       3. Press F5 while your program is running.
Q29.   Compare standard and MDI programs.
Ans.   Standard and MDI form both are the part of vb application. Normally standard forms
       are provided in simple applications and MDI form is used to manage all standard
       forms under a single form. All the control commands like menu and toolbars are
       available on the MDI form.
       A standard form can be distinguished from a MDI form on the basis of the following
       differences.
         STANDARD FORM                                    MDI FORM
         In a single project there are number of Only single MDI form is in the single
         standard forms                                   project
         Standard form can become the child of No MDI FORM could be the child of
         MDI FORM                                         standard form
         We can place any type of control on the On MDI form only menus, toolbar and
         standard form                                    runtime-hidden control are place able. Like
                                                          timer control, common dialog control etc.
         To arrange the standard form there is no MDI form can arrange its child forms in
         property and method                              cascade and tiled style with arrange
                                                          method.
Q30.   What are three phases of component based system design?
Ans.   In Component based system design component is created and coded to execute
       result on the specific action on the component.
       Component based design system has three different phases.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               41/76

       1. Component Design phase: In this phase the controls are placed on the form. With
       proper orientation and alignment. Their properties are specified according to the
       requirement using property window.
       2.code phase: - In the code phase of the component design system. Programmer will
       analyse the requirement of code and when the code will be executed and appropriate
       event for that code will be handled in the code window.
       3. Executing/Testing phase: -After the coding process, the source will be tested in the
       testing/Execution phase by putting the dummy data on the components, if it produce
       accurate results then they will finalize the source otherwise the debug process will be
       performed to find the logical and syntax errors.

  Design Phase                 Code Phase                  Testing /Execution phase




                                      Debugging

Q31.   What is the difference between graphics methods and graphics control.
Ans.   Graphics methods are useful to design any graphics object on the form. There are
       graphics methods like
       Circle :- Circle method is used to draw the circle on the form. It has the following
       syntax
       Sub Circle(Step As Integer, X As Single, Y As Single, Radius As Single, Color As
       Long, Start As Single, End As Single, Aspect As Single)
       Line :- Line methods is used to draw a line on the form we can also convert line to
       rectangle. It has the following syntax
       Sub line(flags As Integer, X1 As Single, Y1 As Single, X2 As Single, Y2 As Single,
       Color As Long)
       Graphics Controls :- There are different types of graphic controls provided by vb. Like
       image control, picture box, shape control and line control.
       Image control :- In image control we can load the image using load picture method.
       We can specify the image size according to the image control using stretch property.
       Picture box: - picturbox control can also work as container for different graphics
       objects and can appear like a canvas similar to the paintbrush window. But there is
       no stretch property in this control.
       Shape and line: - these are two controls those don’t have any type of events.
Q32.   An Array Marks(40) contains marks of 40 students of a class. WAP to count the
       number of students who scored more than 60 and who scored below 33.
Ans.   Private Sub Command1_Click()
       Dim MARKS(39) As Integer
       Dim CM, CL As Integer
       Dim I As Integer
       CM = 0
       CL = 0
       For I = 0 To 39
       MARKS(I) = InputBox("ENTER MARKS OF " & I + 1 & "STUDENT")
       Next
       For I = 0 To 39
       If MARKS(I) > 60 Then
       CM = CM + 1
       End If
       If MARKS(I) < 33 Then
       CL = CL + 1
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               42/76

       End If
       Next
       MsgBox ("No of students having marks less than 33 :" & CL & vbCrLf & "number of
       students having marks more than 60 : " & CM)
       End Sub
Q33.   What is a break expression? What is the difference between watch expression
       and break expression?
Ans.   Break Expression :- A break expression works as a marker in the code that tells
       visual basic to suspend the program execution. By setting the breakpoints at a place
       make it easy to investigate which line has suspended the program execution. Break
       expressions are temporary and not preserved in the code.
       Watch Expression : - Visual basic automatically monitor the watch expression that
       you define. When the application enters break mode, these watch expressions
       appears in the watch window, where you can observe their values. You can also
       direct watch expression to put application into break mode whenever the
       expression’s value changes or equal to specific value.
       Difference between break expression and watch Expression
        Break expression                             Watch expression
        It cab be added using toggle break point It can be added using add watch option of
        option of the debug menu                     the debug menu
        It halts the execution of an application and It is monitored automatically by the visual
        gives a snapshot to its condition at any basic
        instant as the program is still active
        In break expression we can check code Watch expression is added into the watch
        using different debug tools                  window and it force the form to enter in a
                                                     break mode where we can watch the
                                                     current result of the expression.


Q34.   Use the common Dialog Control to create an application that asks user for a
       file to open and then open that file in NOTEPAD.
Ans.   Following steps are used to open a file in richtextbox.
       1. Place an activex control richtextbox on the form.
       2. Place a common dialog control on the form.
       3. Place a button on the form and do the following code on the button.
       Private sub command1_click()
       Commondialog1.filter=”TextFiles |*.txt”
       Commondialog1.showopen
       Richtextbox1.loadfile commondialog1.filename
       End sub
       To open the same file in notepad select run option from the start menu than write
       NOTEPAD in the text box click on ok.. Now select open option from the file menu and
       open the same file.
Q35.   Explain in detail the use of Common Dialog Control available in VISUAL BASIC.
Ans.   A Common work in most of the applications is to prompt user for filenames, selecting
       files to open, saving the file on hard disk, font names & sizes or colors to be used in
       applications. Common dialog control is peculiar & provides services to the application
       but is not displayed on the form at runtime. Common dialogs control provides built-in
       windows dialog boxes.
       1. Open - File open common dialog box lets user select a file to open.
       2. Save As - File save common dialog box lets users select or specify a file name in
            which current document will be saved.
       3. Color - The color dialog box lets user select colors or specify custom colors.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 43/76

       4. Font - Font common dialog box lets user select font &style to be applied to
           current text selection.
       5. Print - Print common dialog box lets user select and set up a printer.
       6. Help- help common dialog box displays help topics.
Q36.   What kinds of tools are available for aid in the debugging of vb application?
       Explain each in brief.
Ans.   There are different kinds of debugging tools provided by vb to the vb program error
       free. These tools are.
       The Immediate Window: Most programming languages have a way to test program
       statements procedures and functions visual Basic users the immediate window for
       the testing purpose you can use the immediate window to test statements or to
       perform quick calculations when you are in break mode. If you type Print 2+2 in the
       immediate window and press enter, visual basic quickly respond with a 4.
       The Debug Object: You can also add lines of code to your program that will print
       values directly to the immediate window. For this you can use a predefined visual
       basic object called debug. E.g.-
       Debug.Print variable
       Debug.Print expression
       Watch Window: In debugging terms, a watch is a variable or object that is
       specifically monitored or watched in real-time as the program executes. You can view
       the properties of watches in the watch window. The watch window can be called up
       by pressing the watch window button or by adding a watch to the window.
       Call Stack::- call stack tool of vb provides the detail information of parent form , and
       about the current position of the break control in form’s debug process.
       Step Into: step into tool is used to find the logical errors and check the whole code
       by executing statements line by line including all the functions and subroutine
       involved in the process.
       Step out: step out tool only provide the result of the subroutine or function in debug
       mode.
       Step Over: step over tool too execute the code line by line but excluding the
       procedures or subroutines being called by the current event. It only shows the result
       of the called subroutines or functions and then move to the next statement present in
       the current event or procedure.
Q37.   Write a short note on dynamic array.
Ans.   There will be a situation when the user may not know the exact size of the array at
       design time. Under such circumstances, a dynamic array can be initially declared and
       later the user can add elements when required instead of declaring the size of the
       array at design time.
       Dim New Array ( )
       The actual     number of elements can be allocated using a ReDim statement. This
       example allocates the number of elements in the array based on the value of the
       variable, Y.
       ReDim New Array (Y+1)
       The ReDim statement can appear only in a procedure , which is an executable
       statement. The same way of declaration as used for fixed arrays is used for declaring
       ReDim statements. ReDim is an executable statement. The lower and upper limits
       for each dimension can also be specified explicitly as in the case of a fixed size
       array. An example for this is given below.
       ReDim FirstArray ( 4 to 12)
       Each time on executing the ReDim Statement, the current data stored in the array is
       lost and the default value is set. But if we want to change the size of the array without
       losing the previous data, we have to use the Preserve keyword with the ReDim
       Statement. This is shown in the example given below.
       ReDim Preserve NewArray (Unbound (FirstArray) +1)
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  44/76

         When the Preserve keyword is used, only the upper limit of the last dimension in a
         multidimensional array can be changed. No other dimensions or the lower limit of the
         last dimension can be changed.




         Section – C                                           2 Marks Questions
       [Question 1 TO 28]                                        [PAGE 44 TO 47]
Q1.      What is MS flex Grid control? And why is it used?
Ans.     A MS flex Grid control in VB is used to create applications that present information in
         rows and columns. It displays the information in cells. The user can select a cell at
         run time but cannot change the contents.
Q2.      What do objects of same class share?
Ans.     Objects of same class share all static members and shared method and share
         properties defined in the same class.
Q3.      What data binding is and how does it work”?
Ans.     Data binding is the procedure of including code of other files, which are actually not
         the part of current applications code. These are DLLs, which are either predefined or
         made by the programmers.
Q4.      Write a note on Ms flexgrid.
Ans.     A MS FlexGrid control in Visual basic is used to create application that presents
         information in row and columns. It displays the information in cell. The user can
         select a cell at run time by clicking it or by using the arrow keys, but cannot the edit
         or alter the cell’s contents. The MSFlexGrid control displays and operates on tabular
         data. It is necessary that we add the MSFlexGrd.ocx file to our project before we use
         a MSFLexGrid control in our application.
Q5.      Define the term ADO.
Ans.     This is a programming model that eliminates the need to choose among DAO and
         RDO and all other data access methods. It is designed to provide a common bridge
         between different database, file systems and email servers.
Q6.      Define Recordset.
Ans.     A recordset is an object that contains a set of records returned by any SQL query
         from the specified table of the database. It is also helpful to manipulate back end
         database using the front end VB application. It facilitates insertion, updation and
         deletion of records.
Q7.      Define Dynaset and Snapshot type Recordset.
Ans.     Dynaset Type Recordset
         The dynaset type recordset object is a set of records that records that represents a
         table, or attached table, or the result of queries containing fields from one or more
         tables. A dynaset enables us to update data from more than one table.
         Snapshot type Recordset
         The snapshot type recordset can refer to any table, attached table or query. A
         snapshot cannot be updated and does not reflect any change made by users.
Q8.      List three important properties DateTimePicker control.
Ans.     Important properties of DateTimePicker control are
         1. Value: - This property gives the value of the date & time displayed n the control.
         2. Name: - Name property sets the name of the dtpicker, which will be used in
             coding.
         3. Format: - It specifies the format of the date or time to be displayed in the control.
Q9.      Write a note on MonthView control.
Ans.     MonthView control is used to display a calendar that shows one or more months as
         specified. This control lets the user move from one place to another. You can also
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              45/76

       specify selection of dates and specified dates can be obtained from its value
       property. By default, the current month of the current year is displayed.
Q10.   List four important properties of ListView control.
Ans.   Add – Adds a new item to listeners collection
       Count – Returns number of items in collection.
       Item – Retrieves an item specified by and index value or key
       Sorting – Whether the items of listview will be sorted or not.
Q11.   Explain the function GetDriveType( ).
Ans.   GetDriveType () function determines the drive type & is declared as we declare a
       private function Getdrivetype Lib “Kernel32” _
                  Alias “GetDriveTypeA” (By Val ndrive as string) As long
       You can pass the drive that you want to check with nDrive argument & the function
       will return a long value, which describes the type of drive.
Q12.   Describe two ways of establishing a connection to database with ADODB.
Ans.   Two ways of establishing a connection to database with ADODB are:
       1. By passing the connection string to open method of ADODB.
       2. By creating a ‘dsn’ that can be passed to open method of ADODB.
Q13.   Define data integrity.
Ans.   Data integrity states that there should be no duplication of records & database should
       always be in a consistent state. Each record in the database should be uniquely
       identifiable.
Q14.   Write two important properties of data bound list.
Ans.   Two important properties of data bound list are
       1. Row source – Specifies the source (recordset or data control) for populating the
            list.
       2. Listfield – Specifies the field that will be used to fill the list.
Q15.   Explain TableDef object.
Ans.   A TableDef object represents the definition of table in database object. All TableDef
       object forms a collection, the TableDef collection.
Q16.   Explain QueryDef object.
Ans.   Database can contain query definitions. The queries that are commonly used on a
       database can be stored in the database & can be called by name. All the queries
       stored in database can be accessed through the QueryDef object. QueryDefs object
       is a collection of QueryDef objects, one for each stored query.
Q17.   How SQL queries can be executed through active data object
       (ADO)?
Ans.   SQL queries can be executed using two ways:
                  1. Through “Execute” method of active data object.
                  2. Using the command object of active data object’s text property
Q18.   List the advantages of COM.
Ans.   COM is a language independent object model that defines many types of services &
       support for distributed objects. COM is the only model that provides detailed & open
       specifications & helps to provide stability, effective communication protocol & in
       process server support that developers & end user’s need. COM provides easy to
       use tools & largest sets of available applications. It provides Help for reusable
       components. COM supports thousands of available applications.
Q19.   List two important properties of coolbar control?
Ans.   Two important properties of coolbar control are:-
       1. Orientation: - This property specifies the orientation of the coolbar. It can be
       oriented horizontally or vertically.
       3. Align: - Align property specifies the alignment of coolbar control on its container
            object.
Q20.   What is an ActiveX control?
Ans.   Active X controls are the part of COM technology. COM stands for component object
       model. In this technology, programmer can design individual components and code
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 46/76

       for these components. These components can also be used in different application.
       All the ActiveX Controls have user specific properties.
Q21.   Explain the difference between intrinsic controls & ActiveX control.
Ans.   Intrinsic controls are those controls, which are there in the toolbox of visual basic
       whereas ActiveX controls are custom made controls, which can be build, by the
       users. Intrinsic controls are standard visual basic controls whereas you can make
       controls that have user specific properties. E.g. You can design a text box control
       which accepts only numeric values.
Q22.   Define Twip.
Ans.   A screen independent unit used to ensure that placement and proportion of screen
       elements are same on all display systems. A twip is a unit of screen measurement
       equal to 1/20 of printers point. There are app 1440 twips to a logical inch or 567 twips
       to a logical centimeter.
Q23.   Write a short note on Microsoft Jet database engine.
Ans.   It is a database management system that retrieves and stores data in user and
       system databases. The Microsoft Jet database engine can be thought of as a data
       manager component with which other data access systems such as Microsoft Access
       and visual Basic are built.
Q24.   What is dynaset?
Ans.   A type of Recordset object that returns a dynamic set of pointers to a live database
       data like a table or a snapshot type Recordset, a dynaset returns data in records
       (rows) and fields (columns). Unlike a table type Recordset, a dynaset type recordset
       can be the result of a query that joins two or more tables.
Q25.   What do you meant by Data-bound Control?
Ans.   Data-bound controls are WinForms controls those can be easily bind with data
       components. Data-bound controls have properties, which you can set as a data
       component and they’re ready to present your data in WinForms. DataSource and
       DisplayMember are two important properties.
Q26.   What do you understand by ActiveX components?
Ans.   ActiveX is a set of reusable components that can be created and utilized by several
       applications. ActiveX uses the Internet technology to assist in creating compact and
       reusable applications that can be deployed via Internet or a corporate intranet.
       ActiveX provides a familiar client server infrastructure to run your applications.
       Controls like coolbar, flatscrollbar, imageCombo are ActiveX controls. ActiveX control
       can also be used in other ActiveX compliant programs. These can be embedded and
       distributed through HTML web pages.
Q27.   What do you mean by Cursors in VB?
Ans.   In database technology, it is a piece of software that returns rows of data to the
       requesting application. A cursor keeps track of the position in the result set, and
       multiple operations can be performed row by row against a result set with or without
       returning to the original table. In other words, cursors conceptually return a result set
       based on tables within the databases. The cursor is so named because it indicates
       the current position in the result set, just as the cursor on a computer screen
       indicates current position.
       There are four types of cursors
       1. AdOpenFarwordOnly 2. AdOpenkeyset 3. AdOpendynamic 4. AdOpenStatic
Q28.   What are different types of recordsets available in visual basic?
Ans.   Recordset contain the set of records returned by any SQL query, so that they can be
       manipulated in front-end environment.
       There are different types of recordset
       1. Snapshot: Read only recordset cannot be used to update and never be reflected
          to any record in the database.
       2. Dynaset: this recordset can provide the result from different tables; Insertion and
          updation both are possible in the Dynaset.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  47/76

       3.   Tables: Recordset directly link you with the database.




    Section – C                                              5 Marks Questions
 [Question 1 TO 38]                                            [PAGE 47 TO 64]
Q1.    What is control? Can we create our own control in visual Basic?
Ans.   A control is an object, which we place on the form to create a user interface.
       Examples of controls are command button, textbox control, label, picture box etc. We
       can add more controls by right clicking on the toolbox and then by selecting
       components from pop up menu. All the controls can be accessed from the toolbox.
       Nearly every control has its own properties & methods. We can set the properties of
       a control at design time and through coding. We can make controls responding to the
       happening of events. For example: change method of textbox responds to the code
       written in change method whenever the text in the textbox changes.
       We can create our own controls in visual Basic & these are called ActiveX controls.
       User can design their own controls or can extend the properties of existing controls.
       For example: you can design a textbox control that accepts only numeric data.
Q2.    Write down the various types of ActiveX controls.
Ans.   Visual Basic offers the user three different types of control .The techniques for
       authoring all ActiveX controls are the same. The type we need to build however
       depends on the requirement and the amount of functionality that is required to be
       included in our control. The different types of ActiveX controls offered by Visual
       basic are as follows.
        User drawn control
        Enhancement to existing Visual Basic control
        New controls built with constituent controls
       User Drawn Control
       These controls are developed from scratch. The user is responsible for designing the
       control's interface and is in control of its appearance and interface. The
       implementation of these controls is very difficult, as every bit of functionality starting
       from the control's interface to its appearance has to be written by the
       developers/users. They also are the most flexible ones as the user does not have to
       put up with the limitations of other controls.
       Existing Visual Basic Control
       The simplest of custom ActiveX control is one that is based on an existing control.
       The user can keep most or all of the original control's functionality and then add
       custom members.
       For example, when the style property of the Combo Box is set to 0 (Dropdown) or 1
       (Simple Combo), the user can enter a new field value in the edit box of the control,
       but the new entry is not appended to the list of available choices. It can be enhanced
       by enrapturing the Enter key. When the user presses Enter, add the entry in the Edit
       box to the list of options. This can result in the development of a new control, say
       Enhanced Combo.
       Constituent Control
       In cases where most of the functionality we want to include in our custom control
       already exits, a new control can be designed that include existing control. The
       control that form part of the newly developed custom control are called constituent
       control.
Q3.    Differentiate between ActiveX EXE and Active X DLL.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 48/76

Ans.   Servers can be implemented as ActiveX DLL or Active X EXE components. The
       difference lies in how the server is executed. An ActiveX DLL is an in-process server.
       The DLL is loaded in the same address space as the client executable that calls the
       server and it runs on the same thread as the client. At any given moment however,
       the client application or the DLL is running. The merits of DLL are that they are faster,
       they become part of the application that uses them.
       An ActiveX EXE otherwise called as an out-of-process server, as the name indicates
       runs as a separate process. When a client application creates an object provided by
       an EXE server for the first time, the server starts running as a separate process. If
       another client application creates the same object, the running EXE server provides
       this object . In other words, a single EXE server can service multiple clients. Out-of-
       process servers seem to be more efficient in terms of resource allocation , but
       exchanging information between servers is a slow process.
       We will be working with a client server model. Here the application is client , which
       sends requests and the ActiveX Component is the server, which services the
       request. Though ActiveX DLLs run within the same application as the client , they are
       considered as to be servers.
Q4.    Define the following.
Ans.   Visual basic provides a variety of options to access remoter Client\Server database.
       They are
        Data Access Objects (DAO) It communicates with data sources through the JET
            database engine.
        Data Control : It binds data controls to Microsoft Access and other ODBC data
            sources.
        ODBC Direct It allows accessing of ODBC data sources through the RDO with
            DAO object, bypassing the JET database engine.
        Remote Data Object : (RDO): It provides a framework for using code to create
            and manipulate components of a remote ODBC database system.
        Remote Data Control (RDC) It binds the controls to an ODBC remote database .
        Open Database Connectivity (ODBC) : This is an API call interface to the open
            Data Connectivity libraries and drivers to provide data access to Oracle and other
            databases that provide data access to Oracle and other databases that provide
            an ODBC driver.
        Visual Basic Library for SQL Server (VBSQL) : It is an implementation of the
            DB library API specifically designed to provide access to an SQL server through
            a visual Basic Application.
        Active Data Object (ADO) : This is a programming model that eliminates the
            need to choose from among DAO and RDO and all other data access methods.
            It is designed to provide a common bridge between different database, file
            system and e-mail servers.
Q5.    Write a code in Visual Basic to Serach a Record in Database.
Ans.   Object        Properties                         Setting
       Data          Name DatabaseName                  c:\vb\student.mbd
                     Recordsource                       Student
       Private Sub Command1_click ()
       Data1.Record.FindFirst (“Sname=’” &DBcontrol.text & “ ’ ”)
       Text1.Text=Data1.Recordset.fields(5)
       Data1.Refresh
       End Sub
Q6.    Write a code in Visual Basic to update a record in Database.
Ans.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                             49/76




       Object                             Properties                  Setting

       Command button 1            Name                         Command 1
                                   Caption                             Modify
       Command button 2            Name                         Command 2
                                   Caption                      Update
       Command button 3            Caption                      Exit

       Data                         Name                       Data1
                                    DatabaseName                      c:\vb\Supplier.mbd
                                    Record source              Supplier
       The following code entered in the Command button1 click

       Private Sub Command1_click()
               Msgbox “You are now modify the Current Record”
               Data1.Recordset.Edit
               Text1.Enable= False
               Text2.Enable=False
       End Sub

       Enter the following code in the Command buton2 click

       Private sub Command2_click()
               Data1.Recordset (2) = Text3.Text
               Data1.Recordset (3) = Val (Text4.Text)
               Data1.Recordset.Update
               Msgbox “Record Update in file”
               Data1.refresh
       End Sub
Q7.    Compare the conventional and Object Oriented Programming.
Ans.   Conventional Programming using high language such as COBOL , FORTRAN
       commonly know as procedure oriented programming.
       1.Large programs are divided into smaller programs knows as functions.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 50/76

       2.Most of the function shares global data.
       3.Data moves openly around the system from function to function.
       4.Funtions transform data from one form to another.
       5.Employs top down approach in program design.
       Objecting Oriented Programming
       1.Programs are divided into what are known as objects.
       2.Data Structure are design such that they characterized the objects.
       3.Functions that operate on the data of an object are tied together in the data
       structure.
       4.Data is hidden and cannot be accessed by external functions.
       5.Objects may communicate with each other through functions.
       6 Follows bottom up approach in program design.
Q8.    Write a short note on masked edit controls.
Ans.   Microsoft masked edit control is used for input validations in a text box. It looks like an
       ordinary text box. You can restrict the characters entered without having to write code
       in the key events. Most important property is mask property. This property controls
       what the user can enter.
       The event dealing with input to Masked edit box is Validation Error event. This event is
       fired whenever user tries to enter invalid character.
Q9.    Write a short note on status bar control.
Ans.   Status bars are implemented in visual basic via the status bar control and it runs along
       the bottom of an application window and provides the information about the current
       status of the application. Status bar is a good place to put information that helps users
       to keep track of program options they selected.
       Status bar control is not an intrinsic control & can be added from components dialog
       box named Microsoft Windows Common Control 6.0. status bar is always added at the
       bottom of the form & you should set the form’s border style to fixed single so that user
       cannot change the size of the form.


Q10.   What is recordset? Explain.
Ans.   Recordsets are objects that represent collections of records from one or more tables
       .In database programming, Recordsets are the equivalent to variables in regular
       programming. Tables of database can’t be accessed directly. The only way to view or
       manipulate records is via recordset object. A recordset is similar to tables in database
       i.e. it consists of rows & columns and also it can contain data from multiple tables. It is
       just like a grid and records in recordset. Recordsets are the result of queries.
       Recordsets are object variables. It can store result of queries or an entire table of the
       database. The contents of the recordset, however, have a more complicated structure
       and each cell in this grid can be of a different type. To access the contents of the
       recordset, you can use its properties & methods. So a recordset is a view of some of
       the data in the database, selected from database according to user specified criteria.
Q11.   Explain ADO object model in detail.
Ans.   ADO is active data object. ADO object model is similar to the DAO model but it can
       handle more databases and has more features. ADO model consists of three objects
       namely.
       1.Connection
       2.Command
       3.Recordset
       1.Connection: - It is a top-level object & represents a connection to the data source.
       We establish a connection to a data source and issue a command against the
       connection object to retrieve the desired records from the database or to update the
       database.
       2.Command: - This object represents a SQL statement or stored procedure that can
       be processed by the data source. The command object doesn’t return any results if it
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                51/76

       updates the database or returns a recordset with the requested records. To set up a
       command object, you specify the SQL statement or stored procedure and its
       parameters. We can call the execute method to execute the SQL statement or stored
       procedure against the data source. Another approach is to create a recordset object,
       associate a command object with it and retrieve the desired records.
       3.Recordset: - This object stores the results produced on the execution of command
       object in a database. Recordsets can be created without an explicit connection. To
       access the fields of a recordset object, we can use field’s collection.
Q12.   Explain in process & out of process servers.
Ans.   A class module is server, or an application that provides its services to client
       applications. When we create an object variable to access the properties and
       methods of a class, we involve an executable file, which runs in the back round &
       waits to be contacted. Whenever we set or read a property value or call a method,
       this executable file performs some actions and return results to your application.
       Servers can be implemented as ActiveX EXE or ActiveX DLL components. The
       difference is how they are executed.
               An ActiveX DLL is called in process server. The DLL is loaded in the same
       address space as the executable that calls the server. At any point either an
       application or a DLL is running. A DLL is faster and becomes part of the application
       that uses it.
       An ActiveX EXE is an out-of-process server and runs as separate process. When an
       application creates an object provided by an EXE the server starts running as a
       separate process. If another application creates a same object, the new object is
       provided by the already running EXE. So a single EXE provides services to multiple
       applications. Example of out-of-process server is Excel. You can run two or more
       applications that requests services of excel and it will be serviced by a single
       instance of excel.
Q13.   Explain ADO data control.
Ans.   Earlier there were DAO & RDO controls which were used to access the databases but
       these were not sufficient for more advanced databases like Oracle, SQLServer etc.
       One of the new controls added to Visual Basic is Active Data Control or ADO data
       Control. With ADO data control, We can connect to more databases of different types.
       The simplest way to use ADO in your projects is to add ADO in the project & use it on
       the form just like we use DAO. We can add ADO data control from the components.
       From the project menu, select components & from the components check Microsoft
       ADO control 6.0 (OLEDB) option. ADO control will be displayed in the toolbox of VB.
       ADO data control has various properties. Place the control on the form & right click it to
       open property pages of ADO control. We now have to specify the name of the data
       source i.e. name of the database that ADO data control will connect. There are three
       types of data sources:
       1. File Data source: A database file that all user on the machine can access.
       2. User Data source: A database file that a specified user can access.
       3. System Data source: A database file that any user that can log on to the machine
       can access.
       When ADO data control is placed & data source is specified we can bind various other
       controls like textboxes, list boxes, comboboxes etc. to ADO data control by specifying
       data source and data member properties. This is why ADO data control is very
       effective tool for connecting to databases.
Q14.   What are ActiveX Controls define it and explain any two applications of ActiveX
       controls?
Ans.   ActiveX is a set of reusable components that can be created and utilized by several
       applications. ActiveX uses the internet technology to assist in creating compact and
       reusable applications that can be deployed via internet or a corporate intranet.
       ActiveX provides a familiar client server infrastructure to run your applications.
       Controls like coolbar, flatscrollbar, imageCombo are ActiveX controls. ActiveX control
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              52/76

       can also be used in other ActiveX compliant programs. These can be embedded and
       distributed through HTML web pages.
       Image List Control: While working with toolbar & coolbar each button is assigned an
       image and image list works behind the scene. It is not visible at run time and gives a
       way to store a group of images in a single place. The key to work with an Image List
       control is ListImage object and ListImages collection. The ListImages collection
       specifies the images stored. The main properties of Image List control are its custom
       properties and are shown as dialog box. You can set pictures in the ImageList control
       at design time and use their index to refer them. The Image tab on this dialog box
       gives a convenient way to add images at design time.
       To use image from imagelist control we can write
        Set Picture1.picture=ImageList1.ListImage(1).Picture
       Toolbar Control: It is one of the most important tools for providing an easy interface
       to the users. The toolbar control provides easy access to options available in your
       application. To add design time properties to the controls select its custom properties
       from the property windows.
       A toolbar control contains a collection of Buttons objects used to create toolbar. A
       toolbar contains buttons that correspond to items in an application’s menu, providing
       a graphical interface for the user to access an application’s most frequently used
       functions and operations. You can even add an Image in a button and Image list
       control is required on the same form, to add images in the toolbar at design time. You
       can add buttons at design time in the toolbar using its property pages. The custom
       property page has three tabs, General, Buttons and Picture. In the buttons tab you
       can add more buttons to the toolbar.
Q15.   Write a program in VB to find the student standing second in a class.
Ans.   Public Type Student
               Name As String
               Marks As Double
       End type
       DIM S (10) as Student
       DIM Temp as student
       Public sub enterdata ()
               DIM | as Integer
       For I= 0 to 10
               S(I). Name= Inputbox (“Enter name”)
               S(I).marks = Val (Input box (“Enter marks”) )
       Next
       End sub
       Public sub show ()
       DIM I As Integer, ) as Integer
       For I = 0 to 10
       For J = 0 to 10
               IF S(I).marks > S(J).marks then
               Temp = S(I)
               S(I) = S(J)
               End If
       Next J
       Next I
       Msgbox S (1). name & “ is second”
               End sub
Q16.   What are classes and objects? Discuss how to add properties, events and
       methods to a class module?
Ans.   A class is a self-sufficient piece of code, which means you can move the class from
       one project to another and it should, work properly without any modification. A class
       contains properties and methods that all work together to perform a set of related
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               53/76

       operations. Object is an instance of a class, which is used to access the members of
       class.
       Methods: - Adding method to a class is just like adding procedure to a class module.
       You can prefix the method name with Private or Public, depending on the scope of
       method.
       Properties: - are variables used to store and retrieve data from classes. Properties
       that are declared as public are called exposed properties. This means the data within
       the class can be accessed from another procedure outside the scope of the class.
       The exposed properties make up a portion of the class’s interface. Private properties
       can be used to keep data and procedures hidden behind the interface. This prevents
       programs from directly or unintentionally modifying the contents of data required for
       the class to function properly.
       Events: - are most interesting portion of class module. They allow the class to
       communicate information back to an application when sets of conditions are met.
       This makes the application an event driven application means it relies on events to
       make program operate.
Q17.   What are the different types of data reports? How are they created?
Ans.   Data report: - It is created by using data environment .It may have grouping on some
       data. To create data report we must have data environment. After that add command
       for the report. Double click the Data Report object in the Project Explorer window.
             Arrange the Data Environment window and the Data Report window so that
               both the windows are visible on the screen.
             From data base environment drag the fields onto the appropriate section to
               add selective fields or drag command object to include all the fields in the
               report.
             Each label control and text box control can be arranged in different section of
               the report by dragging and dropping as per the requirement set the data
               source property of Data Report object to the Data Environment and data
               member property to command.
            Crystal Reports: -
            Crystal reports let you customize many of the programs default settings to fit the
                                layout of
            your work. These settings affect such things as:
               1.      Your working environment
               2.      The way you select databases
               3.      SQL and ODBC access
               4.      The way various data types are formatted
               5.      The fonts you use for fields and text.
       To create a crystal report-
       1.      Open crystal Reports
       2.      Click the new Report button on the button bar. The Report gallery appears
               (i)     Click one of Report creation expert buttons for step-by-step help in
                       creating a report.
               (ii)    Click the another Report button to use another report as a template for
                       building your report.
               (iii)   Click the custom button to build a custom report.

       3.     When you click custom button the Report Gallery expands.
              1. Select report type
              2. Select data source
              3. Select the fields
              4. Format the fields and labels. Apply any others format required on report.
Q18.   Explain the find methods to locate any record in the recordset.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 54/76

Ans.   The find method can be used to locate a record in a dynaset or snapshot type
       recordset. VB supports four find methods.
       Find First: method finds the first record satisfying the specified criteria.
       Findlast: method finds the last record satisfying the specified criteria.
       Find Next: method finds the next record satisfying the specified criteria, searching
       forward the current record.
       Find Previous: method finds the previous record satisfying the specified criteria,
       searching backward from the current record.
Q19.   Explain how a recordset can be created in Visual Basic.
Ans.   Recordset stores the results produced by the execution of command object in a
       database. Recordset can be created without an explicit connection. To access the
       fields of a recordset object, we can use field’s collection.
       Using the following code we can create recordset in vb
       Dim cn as new adodb.connection
       Dim rs as new adodb.recordset
       Cn.open “provider=Microsoft.Jet.Oledb.4.0; Data Source=’c:\student.mdb’”
       Rs.open “select * from student”,cn,adopendynamic,adlockoptimistic
       To fetch the values from the recordset the following code is used.
       Recordset.fields(“fieldname”)
       Or
       Recordset(indexno)
       e.g
       msgbox rs(0)
       or
       msgbox rs.fields(“Name”)
Q20.   Explain in detail the difference between tables, dynasets and snapshots.
Ans.   Table:- the table is only one of the potentially many components that will actually
       make up a database. Tables are the starting point of any database, and they are
       where the data is stored. Without a minimum of one table, a database would contain
       no data and be totally meaningless.
        Dynaset :- Dynaset means dynamic set of records . the data in a dynaset does not
       actually exist-it is extracted from the underlying table or tables and only the criterias
       are saved. There are some restrictions on editing in a dynaset.You may not be able
       to edit data if it threatens referential integrity between more than one table or master
       and client table..
       Snapshot :- The snapshot type recordset can refer to any table, attached table or
       query. A snapshot cannot be update and does not reflect any change made by users.
Q21.   What is the difference between List View and Tree View? Explain with example.
Ans.   Tree View :- The Tree View control provides a hierarchical view of folders or other
       items that can be neatly categorized in a tree- style layout. It is often used in
       conjunction with a List View control, which is used to display the contents of the
       folder selected in the Tree View. This is the ActiveX control, which is available in
       common window control.
       Main properties of Tree View
       Name, ImageList, Indentation OLEDragMode, OLEDropMode, LineStyle, Scroll etc
       List View :- List View control provides a detailed view of the items appear in the
       specified folder that we select in the tree view. Normally this is used in conjunction
       with a tree view. But we can use it separately too. Any selected item can execute.
       This is also one of the ActiveX control and is available in Common window controls.


       Main Properties of List View
       Arrange , SelectedItem ,Name, LabelEdit, LabelWrap, Listitems, view , GridLines etc.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               55/76

Q22.   Explain in detail steps needed to modify the data in a database record.
                           Or
       How will you update Records sequentially through Visual Basic?.

Ans.   Suppose we have a table in Microsoft access called student.mdb and we want to
       modify the record then we have to perform the following steps.
       1. Include reference of ADODB library
       2. initialize connection and recordset using following commands in general section
        dim cn as new ADODB.connection
        dim rs as new ADODB.recordset
       3. open connection and recordset objects on the form activate them by using
            following command
       cn.open “provider=Microsoft.Jet.Oledb.4.0;Data source=” &app.path &”\student.mdb”
       rs.open “select * from student”,cn,adopendynamic, adopenlocopticmistic
       4. create a find button to find the record to update and for this write following code-
       private sub cmdfind_click()
       dim rno as integer
       rno=inputbox (“enter rollno to find”)
       rs.movefirst
       rs.find “rollno=” & rno
       if rs.eof then
       msgbox “record not found”
       else
        txtrollno=rs(“rollno”)
       txtname=rs(‘name”)
       txtclass=rs(“class”)
       end sub
       5. Modify data what ever u want to modify in the respective textboxes and click on
       update button that have the followng code
       private sub cmdupdate_click()
                 cn.execute “update student set rollno=” &txtrollno &” , name=’” & txtname
                 &”’,class=’”& txtclass & “ where rollno= “ &txtrollno
       end sub

Q23.   What care has to be taken while adding updataing and deleting records from
       linked tables?
Ans.   Following things we have to care while adding , updating and deleting records
       1. if any new record is added in the linked table it must have the reference value
           from the main table otherwise no insertion is possible
       2. if any record is going to get updated then we should change reference key in the
           secondary table
       3. before deleting the records from the parent table we all the reference records
           must be deleted from the child table.
       4. Before updating the key field in parent table must remove the reference of that
           value from the child table.

Q24.   What do you mean by ActiveX controls ? How they are useful in application
       development?
Ans.   ActiveX controls add power to your Application form. In addition to creating your own
       controls, you can use the Internet controls provided with the Professional and
       Enterprise editions of Visual Basic to extend standard applications with Internet
       technology. For example, you can use ActiveX controls on a Web page to add
       customized menus to your Web pages, to add a scrolling banner you can use to
       present advertisements or important announcements, or to add animated effects.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 56/76

       Window Common dialog control provides inbuilt dialog mechanism that is used to
       create a simple notepad application.
       ActiveX provide number of features those helps developers in development.
Q25.   Explain Application deployment with VB.
Ans.   The Package and Deployment Wizard packages your project .dll files and all
       associated files into a "cabinet" or .cab file. The wizard can then deploy this cabinet
       file and its associated support files to a location you indicate on a Web server.
       The application files that must be deployed include:

           The .dll files for the project — including the Visual Basic run-time DLL and the
            .dsr and .dsx files for the project. These are automatically packaged into the .cab
            file when you run the Package and Deployment Wizard.

           The HTML page or pages associated with the project. The Package and
            Deployment Wizard does not package these into the .cab file, but it copies them
            to the indicated location on the Web site when you deploy the .cab file.

           Any files referenced by the HTML pages, such as images. The Package and
            Deployment Wizard does not automatically recognize these dependencies, but
            you can add them to the list of additional files to deploy.

       The Deployment Process
       These are the steps in deploying your DHTML application to the Internet:
       1. Debug and compile your application.
       2. Use the Package and Deployment Wizard to build a .cab file that contains the
           necessary files for your application.
       3. Digitally sign your .cab file and rebuild.
       4. Use the Package and Deployment Wizard to deploy your application to the Web
           server you want to use.
       5. Manually copy any files associated with your application’s HTML pages, such as
           images, to the necessary location on your Web server.
Q26.   Explain the different Advanced Data Access issues ?
Ans.   Following are five data access scenarios that are more complex than simple Select
       queries.
        Executing a Parameter Query
        Performing a Parameter-Driven Stored Procedure
       1. Executing a Parameter Query : - ADO gives you a lot of flexibility here—more, in
           some cases more than RDO. Following commands are used to create parameter
           query
           Private Sub ParmQueryButton_Click()
            If Cmd.CommandText = "" Then
           Cmd.ActiveConnection = cn
           With Cmd
                       .CommandText = "select * from authors where year_born = ?"
                       .CommandType = adCmdText
                       End With
           With Parm
           .Type = adInteger
           .Size = 4
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                            57/76

        .Direction = adParamInput
        .Value = QueryParam.Text
        Cmd.Parameters.Append Parm
        End With
        End If
        Cmd.Parameters(0).Value = QueryParam.Text
          Set rs = Cmd.Execute()
          ADOGrid1.ShowData rs
          rs.Close
        End Sub
2.     Performing a Parameter-Driven Stored Procedure :- it's possible to build your own
       ADODB Parameters collection. In this case, you’re performing a simple two-
       argument SP, "AuthorByYearBorn", that returns a small resultset
        Private Sub RunSPButton_Click()
         Dim Qy As New ADODB.Command
          Dim Parm As New ADODB.Parameter
        Dim Parm2 As New ADODB.Parameter
        Set Qy.ActiveConnection = cn
        Qy(0)="1947"
         Qy(1)="1948"
        Qy.CommandType = adCmdStoredProc
        Qy.CommandText = "AuthorByYearBorn"
        Set rs = Qy.Execute(ShowRows)
        ADOGrid1.ShowData rs
       End Sub


Q27.    Explain the following
                   (a)Opening a table for exclusive use
                   (b)Data–Grid Controls
Ans.   (a) The value of this property, along with the DatabaseName, ReadOnly, and
       Connect properties, is used to open a database. In the Professional and Enterprise
       Editions, this property corresponds to the exclusive argument in the OpenDatabase
       method.
       The Exclusive property is used only while opening the Database. If you change the
       value of this property at run time, you must use the Refresh method for the change
       to take effect. If someone else already has the database open, you can't open it for
       exclusive use and a trappable error results.
       Database operations are faster if the database is opened for exclusive use.
       After you open a database for exclusive use, your application can have as many
       instances open as necessary. However, other applications running on your system
       are not permitted to open the database.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                    58/76

        (b) Data Grid Controls : - The data-aware DataGrid control appears similar to the
        Grid control; however, you can set the DataGrid control's DataSource property to a
        Data control so that the control is automatically filled and its column headers set
        automatically from a Data control's Recordset object. The DataGrid control is really
        a fixed collection of columns, each with an indeterminate number of rows.
        Each cell of a DataGrid control can hold text values, but not linked or embedded
        objects. You can specify the current cell in code, or the user can change it at run time
        using the mouse or the arrow keys. Cells can be edited interactively, by typing into
        the cell, or programmatically. Cells can be selected individually or by row.
        If a cell's text is too long to be displayed in the cell, the text wraps to the next line
        within the same cell. To display the wrapped text, you must increase the cell's
        Column object's Width property and/or the DataGrid control's RowHeight property.
        At design time, you can change the column width interactively by resizing the column
        or by changing the column's width in the Column object's property page.
        Use the DataGrid control's Columns collection's Count property and the Recordset
        object's RecordCount property to determine the number of columns and rows in the
        control. A DataGrid control can have as many rows as the system resources can
        support and up to 32767 columns.
        When you select a cell, the ColIndex property is set, thus selecting one of the
        Column objects in the DataGrid object's Columns collection. The Text and Value
        properties of the Column object reference the contents of the current cell. The data
        in the current row can be accessed using the Bookmark property, which provides
        access to the underlying Recordset object's record. Each column of the DataGrid
        control has its own font, border, word wrap, and other attributes that can be set
        without regard to other columns. At design time, you can set the column width and
        row height and establish columns that are not visible to the user. You can also
        prevent users from changing the formatting at run time.


Q28.    Explain the following
        (a) Web Based deployment
        (b) Packaging the Applications
Ans.     (a) :- These are the steps in deploying your web base application to the
         Internet:
         1. Debug and compile your application.
         2. Use the Package and Deployment Wizard to build a .cab file that contains the
             necessary files for your application.
         3. Digitally sign your .cab file and rebuild.
         4. Use the Package and Deployment Wizard to deploy your application to the Web
             server you want to use.
         5. Manually copy any files associated with your application’s HTML pages, such as
             images, to the necessary location on your Web server.
         6. Test the pages in your application to make sure that all the links to associated
             files still work. If not, you may have to adjust the location of your files on the Web
             server to match the URLs in the HTML pages.
       (b) Packaging the Application
       Using the Package and Deployment Wizard, you can easily create a professional setup
       program for your application or deploy an Internet application to the Web. The wizard
       performs these steps during the packaging process:
        Automatic inclusion of your application's main setup program (setup1.exe).
           The wizard adds the Setup Toolkit application, Setup1.exe, to the package. This file
           is the main installation program for your application.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                   59/76

           Automatic creation of your application's .cab files. The Package and
            Deployment Wizard can create a single .cab file or multiple .cab files for your
            application.
           Script-based sessions. You can select a script from another packaging session
            with the same project if you want to use the same or very similar settings as you
            move through the wizard. This can save you significant time.
           Optional creation of dependency files. Dependency files identify the run-time
            files that must be included with your application when it is distributed.
           Automatic support for data access, Remote Automation, and DCOM features.
            The wizard automatically determines whether your project includes functionality
            that changes the setup process. For example, if you include certain types of data
            access, Remote Automation, or DCOM features, you may need to include drivers
            or other files in your package. The wizard checks your projects and displays
            screens that allow you to specify the appropriate options in these cases.
           Shared file capability. The wizard allows you to install some files as shared files.
            This means that the files will not be removed from the system during an uninstall if
            other applications are using them.
           Alternate file locations for Internet packages. In Internet packages, the wizard
            allows you to specify whether dependency files should be included in the setup
            program or downloaded from an alternate Web site.
           Safety settings for Internet packages. If you do not use the IObjectSafety
            interface in your project, the Package and Deployment Wizard lets you mark
            components in your application as safe.
           Custom destination locations for each file in the project. Most files have a
            default location to which they are installed, depending on whether they are project
            files or system files. You can change these locations if you want to install the files
            to a different location.

Q29.       (a) How can you create your own object?
           (b) What are the data bound Control.
Ans.       (a) Class modules (.CLS file name extension) are the foundation of object-oriented
           programming in Visual Basic. You can write code in class modules to create new
           objects. These new objects can include your own customized properties and
           methods. Actually, forms are just class modules that can have controls placed on
           them and can display form windows. Following steps are applied to create new
           object.
           Add class module from the project menu in your project
           1. Define variable as private and procedure as public so that they are accessible out
              side
           2. save the class module and refer in the form procedure by specifying the following
              statements.
           Dim objectname as new classname
           Or
           Dim objectname as classname
           Set objectname=classname

           (b) Data bound Control :-
           Visual Basic allows you to mark properties of your control as bindable, allowing you
           to create data-aware controls. A developer can associate bindable properties with
           fields in any data source, making it easier to use your control in database
           applications.
           The controls supplied with Visual Basic can be bound to data source fields using their
           DataSource and DataField properties: - You can select one property of your control
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               60/76

       to be bound to the DataField property. Typically, this will be the most important piece
       of data your control holds.
       Although you can mark only one field as bound to the field specified in the DataField
       property, you can mark additional properties of your ActiveX control as bindable.
       Developers can use the DataBindings collection to bind these additional bindable
       properties to data fields.
Q30.   Explain briefly about COM and DCOM.
Ans.   Component Object Model
       Component Object model (COM) is the basis for all OCX controls. COM is a
       specification. It doesn’t tell the user how to implement a control ; rather it
       concentrates the way in which two process communicate with each other and defines
       some standard interfaces for them to communicate.COM allows software
       components to communicate with each other. It is a binary standard that allows any
       two components to communicate regardless of the language the components are
       written in. The only way to access and interact with a COM object is through
       interfaces.
       Distributed Component Object Model
       Distributed Component is nothing but a network. It allows information exchange over
       the internet , the local intranet or any other network. While COM is the basis for OCX
       controls , DCOM is the basis for ActiveX controls – as ActiveX itself is nothing but
       internet enable OCX.
Q31.   Explain ActiveX Documents.
Ans.   ActiveX documents (.dob) are similar to forms, but are displayable in an Internet
       browser such as Internet Explorer. The Professional and Enterprise editions of Visual
       Basic are capable of creating ActiveX documents
       Following steps are used to create ActiveX document.
       1. Determine the features your document will provide.
       2. Design the appearance of your document.
       3. Design the interface for your document; that is, the properties, methods, and
           events your document will expose.
       4. Create a project consisting of your user document and any auxiliary forms.
       5. Add controls and/or code to the UserDocument object.
       6. Implement the interface and features of your document.
       7. Compile your document to create a .vbd file and test it with all potential target
           applications
Q32.   Briefly explain the three types of recordsets.
Ans.
       Recordset: Record sets are objects that represent collections of records from one or
       more tables. Recordset are equivalent of variables in regular programming you can
       access the tables of database only by manipulating the Recordset objects. A
       Recordset is a view of some data in the database, selected from the database
       according to the user specified criteria. In other word, A Recordset represents the
       entire set of records from a table in a database or the result from an executed
       command. A Recordset is a set of rows in which each row has columns of data.
       There are three types of Recordsets namely-
       (1)Dynasets: :- This type of recordset can be specified with DAO object which is an
       updateable view of data. Means we can update and modify the records both in
       forward and backward direction.
       (2) Snapshots, which is the static (Read-only) view of data
       (3) Table, which is the direct views of table.
Q33.   What is a DLL? Write a suitable code to call windows API in VB application?
Ans.   An operating system feature, that stores executable routines in separate file having
       extension .dll, these subroutines execute only when it is called by the calling program
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               61/76

        or by the user requirement. The dynamic link library files are attached to application
        at runtime and share memory only at runtime.
        Following vb code will show how to shutdown the computer from the vb form
        by click on button using appropriate API function
   1.   open vb project
   2.   place a command button on the form
   3.   open form in code window
   4.   write the following code in general section
        Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal
        dwReserved As Long) As Long

        Private Sub Command1_Click()
        Call ExitWindowsEx(1, 0)
        End Sub



Q34.    How can you create an ActiveX control in VB? Give example.
Ans.    Steps to create an ActiveX control
   1.   Start a new project. Select ActiveX control as the project type.
   2.   Set the name property of the Project.
   3.   Set the name property of the UserControl
   4.   From the toolbox add the controls for your ActiveX control.
   5.   Set the properties of the controls according to the function you want to be performed.
   6.   Code for your UserControl.
   7.   Save the UserControl form and Project
   8.   Before a control can be used, appropriate entries must be created for it in the
        Windows registration database. Selecting the FileMake menu command can do
        compilation. After it is compiled, the Control is registered on the computer.
Q35.    Explain in detail ADO object model.
Ans.    ActiveX Data Objects (ADO): ADO enables you to write a client application to
        access and manipulate data in a data source through a provider. ADO is ideally
        suited to consume data exposed by OLE DB providers. OLE DB provides high-
        performance access to any data source, including relational and non-relational
        databases, email and file systems, text and graphics, custom business objects, and
        more. ADO connects to a database by means of OLEDB provides OLEDB provides
        is a Microsoft lower-level database interface that provides access to many different
        kinds of databases.
        Possible Uses
       Connect to a local or remote database.
       Open a specified database table or define a set of records based on a Structured
        Query Language (SQL) query or stored procedure or view of the tables in that
        database.
       Pass data field values to data-bound controls, where you can display or change the
        values.
       Add new records or update a database based on any changes you make to data
        displayed in the bound controls.
Q36. Write different VB procedures to navigate and update a database file.
Ans. There are different types of procedures provided by vb. These are as under
   1. movefirst :- The procedure used to move the cursor in recordset at the beginning.
        General syntax to use this method is
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                62/76

        Recordset.movefirst
   2. movelast :- use to shift the cursor at the last record in recordset.
        General syntax to use this method is
        Recordset.movelast
   3. moveprevious :- shift the cursor to the previous record in the recordset.
        General syntax to use this method is
        Recordset.moveprevious
   4. movenext: - shift the cursor to next record in the recordset.
        General syntax to use this method is
        Recordset.movenext

Q37.    Write the DAO object hierarchy.
Ans.    DAO objects enable you to access and manipulate data programmatically in local
        and remote databases. You use DAO to manage databases with the help of their
        structures.
        DAO objects hierarchy consist of the following structure.
   1.   workspace object
   2.   record set object.
        1. The workspace object defines a session for the user. When your application starts,
        the Jet engine creates sa default workspace object. You can open additional
        workspaces if required and each workspace has a userID and a password
        associated with it.
        The set statement is used to assign a database to be open by a database object.
        Eg.
        Dim db as database
        Set db=opendatabase(“xyz.mdb”)
        2.Recodset :- A Recordset Object cotains a set of records from the database. You
        must create the recordset by declaring a variable for the recordset object and then
        assigning it to the table as.
        dim rs as recordset
        set rs=db.openRecordset(“employee”,dbOpenTable)
        The type of recordset can be either dbOpenTable or dbOpenDynaset or
        dbOpenSnapshot. There are no bound controls for the DAO objects and so you have
        to copy data from a recordset to a textbox one by one.
Q38.    Write the steps to create an ActiveX Control for clock that exposes startclock()
        and Stopclock() methods.
Ans.    Following steps are used to create an ActiveX Control for clock
  1.    select ActiveX control project from the new project Dialogbox
  2.    On the usercontrol form place the following controls
  3.    Label control, timer control and two command buttons
  4.    set border style property of label control to fixed single.
  5.    set the caption of the command1 to startclock and caption of the command2 to stop
        clock.
   6.   change the name of the usercontrol to timercontrol
   7.   specify view bitmap property of the usercontrol to specific image . it should appear as
        on the form.



   8. Change the name of the project from project property window.
   9. Write the following code in the code window
      Private Sub Command1_Click()
      Timer1.Enabled = True
      End Sub
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)   63/76

      Private Sub Command2_Click()
      Timer1.Enabled = False
      End Sub
      Private Sub Timer1_Timer()
      Label1.Caption = Time
      End Sub
  10. Now save the project
  11. make timercontrol1.ocx.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                   64/76


       Some Additional Questions
       Short Questions

Q1.    What is the advantage of creating a project in Visual Basic?
                        Or
       What is Visual Basic environment?.
Ans.   A project is a collections of files that you use to build an application. The visual Basic
       Environment is a platform provided by Visual Basic to Develop and execute a project.
       The environment consist of different project templates, controls tools and various
       other options. A project file is a collection of files that you use to build an application.
       A project consist of
        A project file that keep track of all the components(.vbp)
        The .frm file for each form(.frm) created to develop an application. It contains
            description of the properties of the form and controls on it.
        The ActiveX Control(.ocx) file that become a part of the project file only if optional
            controls are added to your program.
        The (.cls) file is an optional file for each class module and the standard (.bas) file
            is also an optional for each standard module.
Q2.    Give any four examples of Library Functions.
Ans.   Library functions are the built-in functions which are defined in the VB library. Each
       library function performs a specific operation. You can use these functions directly,
       without implementing in a programming to perform functions such as manipulating
       strings and numbers. These are categorized into following categories:
             Numeric Functions
             String functions
             Date and Time functions
       Examples are:
       Abs(argument):- returns absolute value of the argument
       Sqr(argument):- Returns Square root of the argument.
       Len(argument):- Returns the total number of memory characters that are required to
       store the argument
       UCase(argument):- Returns all characters of the argument in upper case.
Q3.    What is With Block used for?.
Ans.   You can assign properties to various components such as forms, control buttons and
       text boxes, using two methods. These methods are using the properties window or
       by using VB programming language. The With Block feature enables you to assign
       various properties to a component without repeating the component name again and
       again
       Example
            Private sub command1_click()
                    with text1
                            .text=”hello”
                            .left=10
                            .top=100
                            .fontsize=16
                    end with
            end sub
Q4.    What is meant by Break Points?.
Ans.   The process of finding out and removing the errors is called debugging. Therefore a
       programmer has to carry out the debugging process before distributing the software
       to an end user. After deciding on the point where you want to stop/pause the
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  65/76

       execution of the program, you can allow the transition of the variables or functions.
       You can specify the point where the program should halt by setting a ‘BreakPoint’. To
       set a Break Point, put the cursor on the line where you want to set Break Point. After
       specifying the point, click on Toogle Breakpoints button. A brown Line appear and
       the execution of the program stops when control reaches at the BreakPoint.
Q5.    What do we call a Scroll Bar?.
Ans.   The scroll bars are the prime mechanism to view a large image or text that doesn’t fit
       entirely in a window. While scrolling a long document horizontally or vertically, the
       user doesn’t have to bother about line numbers or pixels. Visual Basic provides two
       types of Scrollbars, horizontal scrollbar and vertical scrollbar. The horizontal scrollbar
       controls the position in horizontal direction and vertical scrollbar control the position
       in vertical direction and you can move up and down using vertical scrollbar.
Q6.    Give any two examples of methods that can be added to a class module?.
Ans.   A class is a self-sufficient piece of code, which means you can move the class from
       one project to another and it should, work properly without any modification. A class
       contains properties and methods that all work together to perform a set of related
       operations. Object is an instance of a class, which is used to access the members of
       class.
       Methods: - Adding method to a class is just like adding procedure to a class module.
       You can prefix the method name with Private or Public, depending on the scope of
       method.
       Examples:
       Enter the following code in the Code Window
       Public sub Hello()
                Msgbox”Welcome to the Class Module”
       End sub
       Public sub disp()
        Msgbox”You are using class module”
       End sub
Q7.    What is meant by COM?.
Ans.  Component Object model (COM) is the basis for all OCX controls. COM is a
      specification. It doesn’t tell the user how to implement a control ; rather it
      concentrates the way in which two process communicate with each other and defines
      some standard interfaces for them to communicate.COM allows software
      components to communicate with each other. It is a binary standard that allows any
      two components to communicate regardless of the language the components are
      written in. The only way to access and interact with a COM object is through
      interfaces.
Q8.   What do you understand by registering ActiveX Component?.
Ans. Registering an ActiveX Component means to add the component into the project
      component option so that it could reuse in different applications of Micorosoft Visual
      Studio.
 To Register the ActiveX component use the following command at the command Prompt
      Regsvr32.exe filename.OCX


Q9.    When will you create DLL?
Ans.   You need to create ActiveX DLL component to create binary executables that can be
       integrated with other applications. ActiveX DLL components are based on the in-
       process architecture that executes on the same memory space in which the
       executable files are executed. ActiveX DLL components are not self executable you
       need to create a ActiveX exe application that calls the methods of the ActiveX DLL
       file
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                     66/76

Q10.   What is a Database?.
Ans.   A database is a collection of information that's related to a particular subject or
       purpose, such as tracking customer orders or maintaining a music collection. A
       database is similar to a data file in that it is a storage place for data. Like a data file, a
       database does not present information directly to a user; the user runs an application
       that accesses data from the database and presents it to the user in an
       understandable format.
Q11.   What are Reports?.
Ans.   Reports are the final document to be print. These are the documents which we want
       to maintain as a hard copy. Visual Basic provide a built in way to create reports in a
       Project. The Built in Report Utility is Data Report. There is also a third Party Report
       Package Available in Market as ‘Crystal Reports’ Which are more advanced than
       data reports and are compatible with Microsoft Visual Basic Environment.
Q12.   What are the Types of Cursors?.
Ans.   A cursor keeps track of the position in the result set, and multiple operations can be
       performed row by row against a result set with or without returning to the original
       table.
       The type of cursor used in a Recordset object.

       AdOpenForwardOnly
       Forward-only cursor. Default. Identical to a static cursor except that you can only
       scroll forward through records.
       AdOpenKeyset
       Keyset cursor. Like a dynamic cursor, except that you can't see records that other
       users add, although records that other users delete are inaccessible from your
       recordset. Data changes by other users are still visible.
       AdOpenDynamic
       Dynamic cursor. Additions, changes, and deletions by other users are visible, and all
       types of movement through the recordset are allowed, except for bookmarks if the
       provider doesn't support them.
       AdOpenStatic
       Static cursor. A static copy of a set of records that you can use to find data or
       generate reports. Additions, changes, or deletions by other users are not visible.
Q13.   Give an Example where searching and Sorting both are involved.
Ans.   Sorting is a technique that is used to arrange data value in a specific order.
       Searching is a technique that is used to find out a specific data value from the
       recordset entries.

       Dim cn As New ADODB.Connection
       Dim rs As New ADODB.Recordset

       Private Sub Command1_Click()
       rs.MoveFirst
       rs.Find "empno=" & Text1.Text
       Text1.Text = rs.Fields(0)
       Text2.Text = rs.Fields(1)
       End Sub
       Private Sub Command2_Click()
       rs.Sort = "ename ASC"
       Text1.Text = rs.Fields(0)
       Text2.Text = rs.Fields(1)
       End Sub
       Private Sub Form_Load()
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 67/76

       rs.CursorLocation = adUseClient
       cn.Open "provider=microsoft.jet.oledb.4.0; data source=f:\database.mdb"
       rs.Open "emp", cn, adOpenDynamic, adLockOptimistic
       End Sub
Q14.   Give an Example where sorting is must?.
Ans.   Sorting is a technique that is used to arrange data value in a specific order. Sorting is
       applicable, where we have large numbers of records and they must be processed
       fast in order to get optimized Result. And we need to search information from these
       records frequently.
Q15.   Differentiate Between User-Defined and Library Functions?.
Ans.   Library functions are the built-in functions which are defined in the VB library. Each
       library function performs a specific operation. You can use these functions directly,
       without implementing in a programming to perform functions such as manipulating
       strings and numbers.
       User-defined functions are much like subs except they return a value to the calling
       procedure. They are especially useful for taking one or more pieces of data, called
       arguments, and performing since tasks with them. Then the function returns a value
       that indicates the result of the tasks completed within the function e.g.
       Public Function Sum (A as integer) As Integer
               Statements
       End Function
Q16.   What is meant by Drop-Down Menu?.
Ans.   The menu bar consists of a number of options. Window-based applications follow a
       standard in which a File menu is always on the left then optional menus such as Edit
       and Tools followed by Help on the right. When a user clicks a menu item, a lit of
       options is displayed. Clicking any item on the list will generate a click event. You can
       write a program to respond to that event.
Q17.   What is meant by Watch window?.
Ans.   In debugging terms, a watch is a variable or object that is specifically monitored or
       watched in real-time as the program executes. You can view the properties of
       watches in the watch window. The watch window can be called up by pressing the
       watch window button or by adding a watch to the window.
Q19.   Give any two examples of Properties that can be added to a class module?.
Ans.   Properties in a class are used to store or retrieve information from the project. In
       Visual Basic there are two ways to add properties to a class module:
            Using Public variables
               While using public variables to add properties to a class module, you just
               need to declare the public variable in the declaration section of the class
               module.
            Using Properties Procedures
               Properties procedures are written like functions, but behave like properties for
               the end users. A property procedures has three parts:
               Declaration:- Declare variables to store the property value
               Get:- Retrieves the property value from a class module
               Let:- Assigns properties to a class module.
               For Example
               Public name as string
               Public salary as currency
               Public property Get empname() as string
                       Statement…..
               End Property
               Public Property Let empname(ByVal VNewValue as string)
                       Statement…..
               End Property
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                68/76



Q20.   What is the Role of Visual Component Manager?
Ans.   Visual component manager is a tool provided by Microsoft to store, manage, deploy
       and reuse the components. A Visual Component Manager employs various wizards,
       ActiveX components and database Connection objects to manage the individual
       components. The Visual Component Manager may include complete Microsoft Visual
       Basic package to store and manage the COM components. Visual component
       Manager allows a programmer to create and build newer components based on
       component based software development. The concept of reusability allows a
       programmer to use functionality previously defined for a component.
Q21.   What is a Recordset?.
Ans.   Record sets are objects that represent collectors of records from one of more tables.
       Recordset are equivalent of variables in regular programming you can access the
       tables of database only by manipulating the Recordset objects. A Recordset is a view
       of some data in the database, selected from the database according to user specified
       criteria. In other word, A Recordset represents the entire set of records from a table
       in a database or that result from an executed command. A Recordset is a set of rows
       in which each row has columns of data.
Q22.   What is Locking?.
Ans.   Locking is a technique that us used in a multi-user database environment to prevent
       users from editing one or more records on the database. For Example you are
       working in a multi-user database environment and want to edit database records.
       While editing the records, you need locking to prevent all the other users on the
       database from trying to edit the same record at the same time.
Q23.   When do we use ActiveX Components?.
Ans.   An ActiveX component is basically a user-defined executable control that can be
       used to create interfaces and applications like other controls such as Text box and
       command button. ActiveX components allow programmers to reuse these user-
       defied controls to perform manipulation on various data types in their applications.
       ActiveX components are saved as a file with .exe, .dll, or .ocx file.
Q24.   When will you create EXE Component in Visual Basic?.
Ans.   These components are used to create applications that can be deployed on out-
       process server architecture. The file extension for these files is .exe. the ActiveX Exe
       files run in their own address space making communication between the separate
       processes a but slow. These files are more robust in terms of execution as bugs in
       the file do not lead to the crash of the container.
Q25.   What are controls?
Ans.   The controls are the building blocks on which we assemble the VB program. The
       toolbox is a palette of controls from which we can select controls and place them in
       our forms. There are two types of Controls in VB.
       (I) Intrinsic Controls: These controls reside with in the toolbox by default. They can’t
       be Removed from the toolbox.
       (II) Extrinsic Controls: These controls we have to add these from the components
       windows by selecting it from the project menu. These controls are the files having,
       OCX extension.
Q26.   How we use Multidimensional Array?.
Ans.   Multidimensional Arrays: Sometimes you need to keep track of related information
       in an array. For example, to keep track of each pixel on your computer screen, you
       need to refer to its X and Y coordinates. This can be done using a multidimensional
       array to store the values.
       You can declare arrays of multiple dimensions. For example, the following statement
       declares a two-dimensional 10-by-10 array within a procedure:
       Dim MatrixA(9, 9) As Double
       Either or both dimensions can be declared with explicit lower bounds:
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  69/76

       Dim MatrixA(1 To 10, 1 To 10) As Double
       You can extend this to more than two dimensions. For example:
       Dim MultiD(3, 1 To 10, 1 To 15)
       This declaration creates an array that has three dimensions with sizes 4 by 10 by 15.
       The total number of elements is the product of these three dimensions, or 600.


       Long Questions
Q1.    Discuss the Features of Visual Basic Environment?.
Ans.   The visual Basic Environment is a platform provided by Visual Basic to Develop and
       execute a project. The environment consist of different project templates, controls
       tools and various other options. The Features Provided by the Visual Basic
       Environment are:
            Title Bar used to give the title of the project. This title is also tells us that we
              are currently working on project1 and we are in the design stage.
            Menu Bar is a standard menu bar which has different options to perform in an
              application.
            Standard toolbar contains standard controls which helps in designing and
              running our project.
            Tool Box: As the name implies, the toolbox contains the bits and pieces you
              need to build your application interface. Their tools or objects are referred to
              as controls.
            Project explorer: This is simply a list of all the forms. Which make up your VB
              project. The project explorer displays a list of all forms and modules making
              up your application.
            Property window: VB allows you to enter parameter for central, which are
              called properties of that control. Some properties can be entered at design
              time using this property window while other must be entered with code while
              the program is owning.
            Code window: This is where you type in the code that VB executes. Notice
              that the heading of the window indicates which events the code is associated.
            Form layout window: The form layout window shows where your form will be
              displayed relative to your monitor’s screen.
            Object Browsers: It lists objects available for use in your project and gives you
              a quick way to navigate through your code. You can use the object. Browser
              to explorer objects in VB and other applications.

Q2.    What are Branching statements in Visual Basic?.
Ans.   Branching statements are used to break the sequence of a program and to pass the
       contents to a specific line in the program depending on the specific condition. Various
       types of branching statements are :
       If condition Then[statements] [Else statement]; execute a group of statements
       conditionally depending on the value of an expression.
       Select case testexprerssion [case expression list-n[statements-n]]… End select :
       executes one of the several groups of statements depending on the value of an
       expression.
       Example:- IF then else Statement
       Private Sub Form_Load()
       Dim x, y As Integer
       x = 10
       y = 10
       If x <> y Then
       MsgBox " Both values are not equal"
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                             70/76

       Else
       MsgBox " Both values are equal"
       End If
       End sub
       Example:- Select case … end Select statament

       Private Sub Form_Load()

       Dim sp As Integer
       sp = 19
       Select Case sp
       Case Is <= 18
       MsgBox "you are in juniors"
       Case Is <= 50
       MsgBox "you are in Seniors"
       Case Else
       MsgBox "you are in Olders"
       End Select
       End Sub
Q3.    Write a Visual Basic code to accept a string only in lower case and display it by
       changing its alternate characters to upper case?.
Ans.   Open a new Project and Add a Label control with Caption as ‘Enter your Name’
       Add a Text Control and a Command button
       Then Write the coding as below in Code window
       Private Sub Command1_Click()
       MsgBox "You have entered String is" &
       UCase(Text1.Text)
       End Sub

       Private Sub Form_KeyDown(KeyCode As Integer,                                    Shift
       As Integer)
       Form1.BackColor = vbGreen
       End Sub
       Private Sub Text1_KeyPress(KeyAscii As Integer)
              If KeyAscii >= 65 And KeyAscii <= 91 Then
              MsgBox "Only lowercase are allowed"
              KeyAscii = 0
              End If
       End Sub
Q4.    What are the basic Object Oriented Principles?.
Ans.   The Object Oriented principles are the principles provided with the object-oriented
       programming concept. The object-oriented programming concept or approach
       involves grouping of data ad functions into modular entities known as a class.
       Classes are user-defined data types that contain data and functions and to initiate a
       class, you need to create an object of the class. You can access the data and
       methods of the classes by using this object only. You can create any number of
       objects in a class. The various object-oriented principles such as encapsulation and
       inheritance provide security to your data and allow the reuse of objects in a new
       application. Various object oriented principles are:
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                 71/76


       Encapsulation

       Refers to the data hiding. Encapsulation wraps data and methods into a single entity
       called class. This principle does not permit any outside programming to directly
       access and manipulate the wrapped data and methods. To access data you need to
       create an object of the class, which allows you to access the wrapped methods and
       data. Therefore, this principle provides security to the data inside a program. Visual
       basic use classes or class module to encapsulate the data and methods.

       Inheritance


       Inheritance is the process by which objects can acquire the properties of objects of
       other class. In OOP, inheritance provides reusability, like, adding additional features
       to an existing class without modifying it. This is achieved by deriving a new class
       from the existing one. The new class will have combined features of both the classes.

       Polymorphism


       Polymorphism means the ability to take more than one form. An operation may
       exhibit different behaviors in different instances. The behavior depends on the data
       types   used    in   the    operation.   Polymorphism     is   extensively    used    in
       implementing Inheritance.

Q5.    What are the types of ActiveX Components available in visual Basic?.
Ans.   You can create various types of ActiveX components in Visual Basic depending on
       the requirements of the client application. Various types of ActiveX controls in Visual
       Basic are:
       ActiveX Exe: These components are used to create applications that can be
       deployed on out-process server architecture. The file extension for these files is .exe.
       the ActiveX Exe files run in their own address space making communication between
       the separate processes a but slow. These files are more robust in terms of execution
       as bugs in the file do not lead to the crash of the container.
       ActiveX DLL:- These components are used to create applications that can be
       deployed on in-process server architecture. The file extension for these files s .dll.
       these files cannot be executed on their own. The ActiveX DLL files run in the same
       address space as the container files leading to faster intercommunication between
       the processes.
       ActiveX Control:- These components are used to create applications that can be
       deployed on remote server architecture. The file extension for these files is .ocx.
       these files require Cabinet(CAB) files for proper deployment of the control on the
       client machine.
       ActiveX Document EXE:- These components are used to create controls for web-
       based applications. These controls can be published to a web site. The client
       downloads the corresponding control from the web site using the web browser.
       ActiveX Document DLL:- These Components are used to create component for
       Web-Based applications like ActiveX Document EXE. In Contrast to the ActiveX
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                               72/76

       Document EXE these files require container files that can call the dll files to execute
       the required functionality.
Q6.    How will you select a Record in a database through Visual Basic?.
Ans.   Suppose we have a table in Microsoft
       access called database.mdb and we want                                               to
       modify the record then we have to perform
       the following steps.
       5. Include      reference     of     ADODB
           library(Microsoft AcvtiveX 2.0 Library)
       6. Initialize connection and recordset
           using following commands in general
           section.

       Dim cn As New ADODB.Connection
       Dim rs As New ADODB.Recordset

      Private Sub Command1_Click()
             rs.MoveNext
             If rs.EOF Then
      MsgBox "You are at Last Record"
             Exit Sub
             End If
             disp
End Sub

       Private Sub Command2_Click()
       rs.MovePrevious
       If rs.BOF Then
       MsgBox "You are at First Record"
       Exit Sub
       End If
       disp1
       End Sub

       Private Sub Form_Load()
       cn.Open "provider=microsoft.jet.oledb.4.0; data source=f:\database.mdb"
       rs.Open "emp", cn, adOpenDynamic, adLockOptimistic
       Text1.Text = rs(0)
       Text2.Text = rs(1)
       End Sub

       Public Sub disp()
              Text1.Text = rs(0)
              Text2.Text = rs(1)
       End Sub
       Public Sub disp1()
              Text1.Text = rs(0)
              Text2.Text = rs(1)
       End Sub

Q7.    How will you play a Sound and a Movie File in visual Basic?.
Ans.   To Play a Sound or Movie File in Visual Basic You have to add an ActiveX control as
       ‘Window Media Player’ and an Commondialog control 6.0 in your Project file.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                                  73/76

       Now Add the following Coding in your Code
       Window:

       Private Sub Command1_Click()
       CommonDialog1.Filter = "Movie files|*.avi|Song
       files|*.mp3"
       CommonDialog1.ShowOpen
       MediaPlayer1.FileName                        =
       CommonDialog1.FileName
       End Sub

       Private Sub Command2_Click()
       MediaPlayer1.Play
       End Sub

       Private Sub Command3_Click()
       MediaPlayer1.Stop
       End Sub

       Private Sub Form_Load()
       MediaPlayer1.ShowControls = False
       MediaPlayer1.AutoStart = False
       End Sub


Q8.    What can be error handler used for?.
Ans.   It is a routine that traps errors and directs a user or a program to perform a certain
       tasks to overcome the error. Although Visual Basic handles the various errors that
       occur during runtime. It is better for us to have control over the errors that are
       displayed.
       The ErrObject when an error occur VBA activates the err object. The err object
        is a class in VB to handle errors. It has number of properties and functions.

              Clear: - This method is to clear all the property settings of the error object.
              Description: - Return or sets the string expression with a descriptive string
               associated with the error objects.
            HelpContext: - Return or sets a context ID for a topic in a help file.
            Helpfile: - Return or sets the fully qualified path for help file.
            Last DLL error: - Returns the system error code by call to DLL.
            Number: - Returns or set a numeric value representing an error.
            Raise: - This function will generate an error at runtime.
            Source: - Returns or sets the name of the object that has originated the error
       An error ‘trapper’ should be introduced in the procedure where you anticipate the
       error. Once an error occurs, the program flow must be directed to another part of the
       procedure where an error will be resolved. In the error ‘handler’ the error will be
       resolved b popping up a message box to a user and initiating some action or the
       error will be ignored and execution of the procedure will continue from the next
       statement.
Q9.    What are advantages of ADO and OLEDB?.
Ans.   OLEDB is a set of Component Object Model(COM) interfaces that provide uniform
       access to the data stored in diverse information sources, OLEDB is defined as a new
       low-level interface that is a part of the universal Data Access platform. It is defined as
       a general purpose set of interfaces designed to let developers build data access tools
       as a components using the Component Object Model(COM). OLE DB enables
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                             74/76

       applications to have uniform access to the data stored in DBMS and non DBMS
       information containers while continuing to take advantage of the benefits of the
       database technology without having transferred data from its place of origin to a
       DBMS.
       This means OLEDB is not restricted to ISAM, Jet or even relational data sources, but
       is capable of dealing with any type of data, regardless of its format or storage
       method. OLEDB has what is called ‘providers’ which let you access the different data
       sources. For different data sources you have different data providers. OLEDB
       provides four services that you will be using in your application. The are:
        A cursor service, which is defined as a temporary read-only table that saves the
           result of a query with assigned name.
        A service to perform batch updates.
        A shape service to build that data in the form of hierarchy.
        A Remote data service provider for managing data in multi-user environments
           over connected or disconnected networks.
       ADO
       ADO enables your client application to access and manipulate data in a database
       server through any of the OLE DB providers. According to Microsoft “ADO’s primary
       benefits are ease to use, high speed, low memory overheads and a small disk
       footprint. ADO supports key features for building client/server and web based
       applications.
       The ADO features an object model like the DAO and the RDO but it is much flatter. In
       the case of the DAO you had seventeen objects and in the case of ADO you have
       only seven object besides you do not have to follow a strict hierarchy when working
       with these objects in ADO. Let us see how ADO allows you to access data from a
       database.
            Establishment of a connection to a data source
            Extraction of the required data with a suitable command.
            Having extracted the data ad worked on it, we may have to up-to-date the
               data source.
            Keep an eye on the errors that may occur and take suitable action.

Q10.   What is data environment designer used for?.
Ans.   A Data Environment Designer us an ActiveX designer tool provided by the VB. The
       Data Environment designer provides an interactive design time environment to
       access data from a database programmatically at run-time. A design time is defined
       as a time during which you create an application in the VB environment b adding
       controls setting properties and writing code to perform a specific task etc. The data
       Environment designer enables you to perform the following tasks:
        Adding Data environment Designer to a VB Project
        Creating Connection Objects top create connections to the created database
        Creating Command Objects
        Adding Data Reports
        Writing and running codes for the connection and Recorset Objects.
Q11.   What are the Benefits of ActiveX Controls?.
Ans.   The Concept of ActiveX was developed for very simple reasons that add to its
       various benefits:
            ActiveX components allow the control to import data from one application to
               another.
            It allows you to make changes in the imported data such that the data in the
               parent application can also be updated.
            ActiveX components allow the programmer to place different types of data or
               objects in one document.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              75/76

              It allows applications to exchange data between various applications. It also
               allows one application to send commands to another application.
            It also allows various objects from different applications to be visible in a
               single document. The imported object gets embedded in the host application
               document. When a user clicks on the object, the parent application of that
               object gets invoked to present the called object.
            ActiveX prevents the conversions of data while integrating one application
               into another.
Q12.   What is a Data Report Designer.
Ans.   Data Report designer is a form or the are where you arrange the various fields such
       as data report title and page header of your project Data Report that you want to
       display. Data Report designer is also known as the Visual Designer component. The
       Designer component can be controlled programmatically using the Data report
       object.
       The Data Report designer consists of a umber of sections like the header, footer and
       details. Each of these section objects ca be configured at design time or controlled
       through code at run time. Each section has a set of properties that can be
       manipulated. The default Data Report designer contains the following sections:
       Report Header:- you give the title of a data report in this section.
       Page Header:- You give the page heading here.
       Details:- This section contains the actual data. Recordset are displayed in this
       section.
       Page footer:- you give the page footer here. This can be the page number or ay
       relevant text like data of report etc.
       Report footer:- you give the summary of the report in this section. This can contain
       the address the bibliography, contact address etc. the report footer appears between
       the last page header and page footer.

Q13.   What are the Features of Data Report Designer.
Ans.   The Data Report designer has several features:
   1. Drag-and-Drop Functionality for Fields—Drag fields from the Microsoft Data
      Environment designer to the Data Report designer. When you do this, Visual Basic
      automatically creates a text box control on the data report and sets the DataMember
      and DataField properties of the dropped field. You can also drag a Command object
      from the Data Environment designer to the Data Report designer. In that case, for
      each of the fields contained by the Command object, a text box control will be
      created on the data report; the DataMember and DataField property for each text box
      will be set to the appropriate values.
   2. Toolbox Controls—The Data Report designer features its own set of controls. When
      a Data Report designer is added to a project, the controls are automatically created
      on a new Toolbox tab named DataReport. Most of the controls are functionally
      identical to Visual Basic intrinsic controls, and include a Label, Shape, Image,
      TextBox, and Line control. The Function Control automatically generates one of four
      kinds of information: Sum, Average, Minimum, or Maximum.
   3. Print Preview—Preview the report by using the Show method. The data report is
      then generated and displayed in its own window.
   4. Print Reports—Print a report programmatically by calling the PrintReport method.
      When the data report is in preview mode, users can also print by clicking the printer
      icon on the toolbar.
   5. File Export—Export the data report information using the ExportReport method.
      Formats for export include HTML and text.
   6. Export Templates—You can create a collection of file templates to be used with the
      ExportReport method. This is useful for exporting reports in a variety of formats, each
      tailored to the report type.
SUBJECT: VISUAL BASIC (PGDCA/MSC-2)                                              76/76

   7. Asynchonous Operation—The DataReport object's PrintReport and ExportReport
      methods are asynchronous operations. Using the ProcessingTimeout event, you can
      monitor the state of these operations and cancel any that are taking too long.

Q14.   What are the Benefits of COM(Component Object Model).
Ans.   COM is a technology to create binary executables that allows the programmers to
       reuse the components defined for one application into another. The concept of
       producing binary executables and to reuse the code offers multiple benefits to a user
       such as:
       Programming Language
       The COM components can be built using various programming languages such as C,
       C++. The use of various COM components arises from the fact that these languages
       can support pointers to point to the functions defined in the source code. Moreover
       the source code defined to create interfaces in these languages can be saved as
       binary executables. The binary executables produced by these languages can be
       deployed and integrated with other applications easily.
       Reusability Concept
       The COM allows programmers to create components and interfaces based on built-in
       controls and operations that can be used in various applications. A programmer can
       develop COM component to design the desired interface based on application
       requirement. This developed COM component can be integrated with one or multiple
       applications to be developed by the programmer. The concept of code reusability
       allows the programmer to create the code and use it in various applications
       Backward compatibility
       There is a constant need to upgrade the COM component and the functionality
       provided by them. COM components allow the programmer to extend and
       functionality of the existing components and interfaces using the request called
       QueryInterface. All types of COM components support QueryInterface request. It
       allows the programmer to create new interfaces with additional functionality. The new
       interface developed by queryInterface are made backward compatible with the
       existing COM components.
       Maintaining Version Consistency
       With the growing need of an application to increase the functionality and complexity
       of the COM component, the programmer either need to write the code from the
       scratch or to revise the existing COM component for desired functionality.
       Distributed Component Object Model
       The Distributed Component Object Model allows a programmer to make an interface
       call for the Component Object Model that resides on remote machine using remote
       procedure Call(RPC).Microsoft introduced the concept of DCOM to extend the
       functionality of all existing components and attain distributed capabilities for a COM
       object.

								
To top