vb review questions

advertisement
SUBJECT: ‘VB’ (PGDCA - 2)
Page 1 of 120
Note:
This question-bank contains three sections.
Section-A contains 1 mark Multiple Choice Objective type questions.
Section-B contains 5 marks subjective questions.
Section-A contains 10 marks subjective questions.
Section – A
[QUESTIONS 1 TO 152]
1 Marks Questions
[PAGE 1 TO 17]
MULTIPLE CHOICE OBJECTIVE TYPE QUESTION
Q1. Event-driven languages are:
(a) FORTRAN based
(c) OOP
Q2. IDE is:
(a)
(b)
(c)
(d)
(b) Are used to write procedural languages
(d) Designed to make programming GUI easier
Independent Development Enterprise
A development environment for machine language
A software project management tool
An Integrated Development Environment for Visual Basic
Q3. Which of the following is not part of the IDE:
(a) Code editor window
(b) Properties window
(c) Form layout window
(d) General window
Q4. The application name always appears in the:
(a) Properties window
(b) Intermediate window
(c) Code window
(d) Title bar
Q5. The color of a button is:
(a) One of its properties
(c) Defined in the project
(b) Not updateable
(d) Defined in the Intermediate window
Q6. Code is:
(a) Updateable in the form editor
(c) Seldom used
(b) Instructions
(d) An object
Q7. Controls are:
(a) Code
(c) Rules
(b) Part of the menus
(d) Objects
Q8. In the IDE, which of following is used to design the layout of an application?
(a) Form Designer window
(b) Project Explorer window
(c) Context Menu
(d) Form Layout window
Q9. The location of the form on the desktop during execution is determined by the:
(a) Form Designer window
(b) Project Explorer window
(c) Context Menu
(d) Form Layout window
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 2 of 120
Q10. The Object Browser:
(a) Displays the command buttons and textboxes etc.
(b) Shows frequently used shortcuts as objects
(c) Is a Context Menu
(d) Displays the object libraries and their combinations of data and code
Q11. The location of the form on the desktop during execution is determined by the:
(a) Form Designer window
(b) Project Explorer window
(c) Context Menu
(d) Form Layout window
Q12. The first procedure-oriented language was:
(a) FORTRAN
(b) BASIC
(c) COBOL
(d) ADA
Q13. C is:
(a)
(b)
(c)
(d)
A language widely used in UNIX
A language based on BASIC
Used primarily for business applications
A GUI
Q14. COBOL is:
(a) One of the oldest programming languages
(b) Still widely used
(c) Not suitable for business applications
(d) None of the above
Q15. Object Oriented languages:
(a) Are procedural languages
(b) Are task oriented
(c) Are based on actions happening to objects
(d) Are natural language techniques
Q16. Visual Basic projects are identified by a:
(a) “.vbp” suffix
(b) “.mak” suffix
(c) “.vbg” suffix
(d) All the above
Q17. Visual Basic forms are identified by a:
(a) “.frm” suffix
(b) “.mak” suffix
(c) “.for” suffix
(d) A special icon
Q18. To run an application in Visual Basic:
(a) Click on the start button (blue arrow)
(b) Use the File Menu
(c) Use the Project Menu to select Run
(d) None of the above
Q19. To exit Visual Basic:
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
(a)
(b)
(c)
(d)
Page 3 of 120
Click Alt-Q
Use the File Menu to select Quit
Use the Window Menu to select Exit
Click on the diskette icon
Q20. The reference library of Visual Basic books is called:
a) MSDN Library
b) Help Library
c) Contents
d) Topic pane
Q21. in which year vb 6.0 version was launched
a. 1991
b. 1994
c. 1996
d. 1998
Q22. RAD stands for
a. rapid application development
c.reused application development
b. randomly application development
d. Rapid application develop.
Q23. IDE stands for
a Integrated development environment b. Integration development enviroment
c. Integrated developing environment
d. Integration developing environment.
Q24. “dim” is a _______
a. data type
c. operator
b. keyword
d.symbol
Q25. how many control in visual basic.?
A .3
b.2
c. 4
Q26. what is the prefix of command ?
a. cmd
c. cmd1
Q27. what is the prefix of list box?
A Lst
b. list
d.7
b.command
d.command1
c. list box
Q28. how many tools available in visual basic?
a. 40
b.30
c. 21
Q29. select the event
a. key up
c. dbclick
Q30. there are _______types of scrollbar
a.3
b.4
c.2
Q31. which is not a part of IDE
a. Project Explorer Window
c.form layout window
d. box
d.31
b. got focus
d. all of above
d.6
b.code window
d.text box
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 4 of 120
Q32. RGB() stands for
a.red green blue
c.green blue red
b. red gray blue
d. red green black
Q33. define the output
text1.text=”visual basic”
text2.text=mid(text1.text,8,5)
a. visual
c. visual bas
b. ual basic
d. basic
Q34. define the right output
text1.text=”hello”
text2.text=left(text1.text,3)
a. hel
b. lo
c. llo
d. elo
Q35. Which language is not a true object-oriented programming language?
a.) VB.NET
b.) VB 6
c.) C++
d.) C#
e.) Java
Q36. A GUI:
a.) uses buttons, menus, and icons.
b.) should be easy for a user to manipulate.
c.) stands for Graphic Use Interaction.
d.) Both a and b.
e.) All of the above.
Q37. Visual Studio .NET provides which feature:
a.) debugging.
b.) application deployment.
c.) syntax checking.
d.) Both a and b.
e.) All of the above.
Q38. What does IDE stand for?
a.) Integrated Development Environment
b.) Integrated Design Environment
c.) Interior Development Environment
d.) Interior Design Environment
e.) None of the above.
Q39. Which type of project can a developer choose in the New Project dialog box?
a.) Visual Basic Projects
b.) Visual C# Projects
c.) Visual C++ Projects
d.) Both a and b.
e.) All of the above.
Q40. Which is not a main component of the Visual Studio IDE?
a.) Solution Explorer
b.) Tool Box
c.) Start Menu
d.) Designer Window
e.) Properties Window
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 5 of 120
Q41. Which does the solution explorer not display?
a.) Form Properties
b.) Reference Folder
c.) Form File
d.) Assemble File
e.) All are part of the solution explorer.
Q42. Which is true about the name and text property of a control?
a.) They are the same when the control is first created.
b.) The text property changes to match any changes in the name property.
c.) The name property changes to match any changes in the text property.
d.) They are never the same unless the programmer makes it that way.
e.) They are not allowed to be the same and an error will occur if they are.
Q43. For which task does the IDE provide multiple ways to accomplish the task?
a.) Putting a control on the form
b.) Running the program
c.) Activating the property window for a control
d.) Both a and b.
e.) All of the above.
Q44. Which are the standard prefixes for the Button and Combo box controls respectively?
a.) btn and chb
b.) btn and cbo
c.) bto and chb
d.) bto and cbo
e.) cmd and cbo
Q45. Which are the standard prefixes for the text box and label controls respectively?
a.) tex and lbl
b.) tex and lab
c.) txb and lbl
d.) txb and lab
e.) txt and lab
Q46. Which task is accomplished in the Code editor?
a.) Adding forms to the project
b.) Adding controls to the form
c.) Adding event procedures to the form
d.) Both a and b.
e.) All of the above.
Q47. Which is not a feature of a GUI that makes learning a program easy for users?
a.) Online help
b.) WYSIWYG formatting
c.) Dialog boxes
d.) Detailed key strokes and commands
e.) Icons
Q48. An object is composed of:
a.) properties.
c.) events.
e.) All of the above.
Is not an inb.) methods.
d.) Both a and b.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 6 of 120
Q49. Which statement about objects is true?
a.) One object is used to create one class.
b.) One class is used to create one object.
c.) One object can create many classes.
d.) One class can create many objects.
e.) There is no relationship between objects and classes.
Q50. Which is not true about forms and controls in Visual Basic?
a.) They are pre-built.
b.) They are graphical objects.
c.) New versions of the classes must be created with each project.
d.) Buttons can be created with the drag and drop method.
e.) All of the above are true.
Q51. Which is an example of Visual Basic Objects?
a.) Control objects
b.) ASP.NET
c.) ADO.NET
d.) Both a and b.
e.) All of the above.
Q52. The .Net class library:
a.) contains over 25,000 classes.
b.) uses namespaces to manage all of the classes.
c.) has the System.Form namespace for classes used in Windows-based application.
d.) Both a and b.
e.) All of the above.
Q53. Which is not a property of the Common control class?
a.) Show
b.) BackColor
c.) Font
d.) ForeColor
e.) Name
Q54. Which property determines whether a control is displayed to the user?
a.) Hide
b.) Show
c.) Visible
d.) Enabled
e.) Cursor
Q55. The Button control can be activated:
a.) programmatically through the click event.
b.) by clicking the button with the mouse.
c.) with the form’s DefaultButton property.
d.) Both a and b.
e.) All of the above.
Q56. The CancelButton property belongs to which object?
a.) Button
b.) Form
c.) Label
d.) TextBox
e.) Timer
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 7 of 120
Q57. A click event procedure stud for the label control can be created by:
a.) selecting the object and event from the code editor window’s drop-down boxes.
b.) typing the code in the code editor window.
c.) by double clicking the control.
d.) Both a and b.
e.) All of the above.
Q58. In event-driven programming an event is generated by:
a.) the system.
b.) a user’s action.
c.) the program itself.
d.) Both a and b.
e.) All of the above.
Q59. Which is not a common control event?
a.) Click
b.) SingleClick
c.) DoubleClick
d.) MouseMove
e.) MouseDown
Q60. The Tick event is found only in which object?
a.) Form
b.) Button
c.) TextBox
d.) Label
e.) option
Q61. The Activated event is found only in which object?
a.) Form
b.) Button
c.) TextBox
d.) Label
e.) Timer
Q62. The Rnd statement will generate a(n):
a.) decimal value between 0.01 and 1.00.
b.) integer value between 0.01 and 1.00.
c.) decimal value between 0.0 and 1.0.
d.) integer value between 0.0 and 1.0.
e.) decimal value between 0.0 and up to 1.0, but not including 1.0.
Q63. The analysis phase of software development involves:
a.) collecting the requirements about what the program will accomplish.
b.) creating a detailed plan on how the program will accomplish the requirements.
c.) writing the software with a program such as VB.NET.
d.) Both a and b.
e.) All of the above.
Q64. Which phase of project development typically costs the most?
a.) Analysis
b.) Design
c.) Implementation
d.) Maintenance
e.) Documentation
Q65. Which is not an integer data type?
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
a.) Single
c.) Short
e.) Long
Q66. Which is a numeric data type?
a.) Floating point
c.) Boolean
e.) All of the above.
Page 8 of 120
b.) Byte
d.) Integer
b.) Integer
d.) Both a and b.
Q67. The Date data type does not hold which type of information.
a.) Seconds
b.) Hours
c.) Days
d.) Months
e.) Quarters
Q68. The Boolean data type:
a.) is unsigned.
b.) has two states.
c.) is displayed by the program as yes or no.
d.) Both a and b.
e.) All of the above.
Q69. Which is a valid statement for declaring a variable?
a.) Const Form As Integer
b.) Const myForm As Integer
c.) Private Dim Form As Integer
d.) Dim myForm As Integer
e.) All of the above.
Q70. VB.Net identifiers:
a.) are case sensitive.
c.) can begin with a number.
e.) All of the above.
b.) can begin with an underscore.
d.) Both a and b.
Q71. The name of a constant:
a.) must both begin with a letter and be all upper case.
b.) does not have to begin with a letter but must be all upper case.
c.) must begin with a letter but can be upper or lower case.
d.) does not have to begin with a letter and be either upper or lower case.
e.) None of the above.
Q72. The proper operator precedence, from first to last, is:
a.) logical, comparison, and arithmetic.
b.) arithmetic, comparison, and logical.
c.) arithmetic, logical, and comparison.
d.) comparison, arithmetic, and logical.
e.) logical, arithmetic, comparison.
Q73. With A = False and B = True, which statement evaluates as True?
a.) A AND A
b.) A AND B
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
c.) B AND A
e.) None are true.
Page 9 of 120
d.) B AND B
Q74. With A = False and B = True, which statement evaluates as False?
a.) A OR A
b.) A OR B
c.) B OR A
d.) B OR B
e.) None are true.
Q75. Which operator is evaluated first?
a.) NOT
b.) AND
c.) XOR
d.) OR
e.) They are always evaluated left-to-right.
Q76. The left side of an assignment statement will hold:
a.) a variable.
b.) an object property.
c.) an expression.
d.) Both a and b.
e.) All of the above.
Q77. The right side of an assignment statement will hold:
a.) a variable.
b.) an object property.
c.) an expression.
d.) Both a and b.
e.) All of the above.
Q78. Which function will return the monthly payments of a loan?
a.) Pay (Rate, PV, Nper)
b.) Pmt (Rate, Nper, PV)
c.) FV (Rate, Nper, Pmt)
d.) FV (Rate, Nper, PV)
e.) None of the above.
Q79. Which function returns the numbers represented in the string “$56.7”?
a.) Abs
b.) CDbl
c.) Int
d.) Rnd
e.) Val
Q80. What is the extension of form
a.) .OCX
b.) .FRM
c.) .DOC
d.) .VBP
Q81. Which function displays a pop-up window?
a.) MsgBox
b.) InputBox
c.) TextBox
d.) Both a and b.
e.) pop up
Q82. Which is true about the prompt argument?
a.) It can be made of multiple values concatenated into one string.
b.) It can include the vbCrLf constant.
c.) It can include the ampersand symbol to concatenate strings.
d.) Both a and b.
e.) All of the above.
Q83. In order to process a number typed in a TextBox the programmer must:
a.) use the Val function to convert the Text value.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
b.)
c.)
d.)
e.)
Page 10 of 120
use the CDbl function to convert the Text value.
use the IsNumeric function to convert the Text value.
Both a and b.
All of the above.
Q84. Which TextBox method does not use the clipboard?
a.) Clear
b.) Copy
c.) Cut
d.) Paste
e.) All of these methods use the clipboard.
Q85. Which TextBox property should always be changed first?
a.) AcceptsReturn
b.) BorderStyle
c.) Font
d.) Name
e.) Text
Q86. Which is not a valid value for the ListBox SectionMode Property?
a.) None
b.) One
c.) MultiSimple
d.) MultiExtended
e.) All of the above.
Q87. Setting the SelectedIndex property of a ListBox to -1 will:
a.) cause an error.
b.) cannot be done.
c.) de-select any selected item.
d.) Both a and b.
e.) All of the above.
Q88. Which method of a ListBox will remove just one item at a time?
a.) Items.RemoveAt
b.) Item.RemoveAt
c.) Items.ClearAt
d.) Item.ClearAt
e.) Items.Clear
Q89. The Items property of a ComboBox:
a.) is a collection of items.
b.) is the same as the Items property of a ListBox.
c.) contains methods and properties.
d.) Both a and b.
e.) All of the above.
Q90. Which value for the ComboBox DropDownStyle property allows a user to type in
data?
a.) DropDown
b.) DropDownSimple
c.) DropDownList
d.) Both a and b.
e.) All of the above.
Q91. Which two controls combined to form the ComboBox control?
a.) ListBox and TextBox
b.) ListBox and InputBox
c.) ListBox and MsgBox
d.) Label and TextBox
e.) Label and InputBox
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 11 of 120
Q92. When a condition in an If…Then statements tests true:
a.) the next Else statement is activated.
b.) the next If statement is activated.
c.) the next Then statement is activated.
d.) the End If statement is activated.
e.) a condition can never test true.
Q93. The End If statement is required:
a.) in all If…Then statements.
b.) in all Multi-line statements with Else.
c.) in Single Line statements.
d.) Both a and b.
e.) All of the above.
Q94. Which statements are optional in an If…Then statement?
a.) If
b.) Then
c.) end if
d.) Both a and b.
e.) All of the above.
Q95. Which selection process is an example of multiple branches from a single
expression?
a.) If…Then
b.) Select Case
c.) Do…Loop
d.) For…Next
e.) All of the above.
Q96. How many times is the test expression of a Select Case evaluated?
a.) 0
b.) 1
c.) 2
d.) Once for each Case.
e.) It depends on the value of the test expression.
Q97. Which is not a type of Select Case test construct?
a.) simple value
b.) complex value
c.) relational value with Is
d.) range of values with To
e.) All of the above are types of test constructs.
Q98. What happens in a Select Case construct when a test value matches the test
expression?
a.) The corresponding block of statements is run.
b.) The next Case test value is checked.
c.) The Case Else statement is run.
d.) The Select Case construct is exited.
e.) An error is generated.
Q99. Do...Loop is an iterative statement because it:
a.) selects a block of statements to run.
b.) runs the same block of statements repeatedly.
c.) selects a block of statements and runs it repeatedly.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 12 of 120
d.) selects a block of statements and runs it a specified number of times.
e.) All of the above.
Q100. Which is true of a Do…Loop?
a.) The While condition goes after the Do keyword.
b.) The Until condition goes after the Do keyword.
c.) The While condition goes after the Loop keyword.
d.) The Until condition goes after the Loop keyword.
e.) All of the above.
Q101. Which Do…Loop statement should be used to process test scores where a test
score over 100 is a signal to stop the processing?
a.) Do While Score > 100
b.) Do Until Score > 100
c.) Loop While Score > 100
d.) Loop Until Score > 100
e.) All of the above are valid for this situation.
Q102. Visual Basic forms are identified by a:
a) “.mak” suffix
b) “.frm” suffix
c) “.for” suffix
d) A special icon
Q103. To run an application in Visual Basic:
a) Click on the start button (blue arrow)
b) Use the File Menu
c) Use the Project Menu to select Run
d) None of the above
Q104. To exit Visual Basic:
a) Click Alt-Q
b) Use the File Menu to select Quit
c) Use the Window Menu to select Exit
d) Click on the diskette icon
Q105. Event-driven languages are:
a) FORTRAN based
b) Are used to write procedural languages
c) OOP
d) Designed to make programming GUI easier
Q106. IDE is:
a) Independent Development Enterprise
b) A development environment for machine language
c) A software project management tool
d) An Integrated Development Environment for Visual Basic
Q107. Which of the following is not part of the IDE:
a) Code editor window
b) Properties window
c) Form layout window
d) General window
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 13 of 120
Q108. The application name always appears in the:
a) Properties window
b) Intermediate window
c) Code window
d) Title bar
Q109. The color of a button is:
a) One of its properties
c) Defined in the project
b) Not updateable
d) Defined in the Intermediate window
Q110. Code is:
a) Updateable in the form editor
c) Seldom used
b) Instructions
d) An object
Q111. Controls are:
a) Code
c) Rules
b) Part of the menus
d) Objects
Q112. In the IDE, which of following is used to design the layout of an application?
a) Form Designer window
b) Project Explorer window
c) Context Menu
d) Form Layout window
Q113. The location of the form on the desktop during execution is determined by the:
a) Form Designer window
b) Project Explorer window
c) Context Menu
d) Form Layout window
Q114. The Object Browser:
a) Displays the command buttons and textboxes, etc.
b) Shows frequently used shortcuts as objects
c) Is a Context Menu
d) Displays the object libraries and their combinations of data and code
Q115. The location of the form on the desktop during execution is determined by the:
a) Form Designer window
b) Project Explorer window
b) Context Menu
d) Form Layout window
Q116. The first procedure-oriented language was:
a) FORTRAN
b) BASIC
c) COBOL
d) ADA
Q117. RAD stands for
a. rapid application development
c. reused application development
b. randomly application development
d. rapid application develop.
Q118. “dim” is a _______
a. data type
c. operator
b. keyword
d.symbol
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 14 of 120
Q119. how many tools available in visual basic.?
a .3
b.21
c. 4
d.7
Q120. what is the prefix of command ?
a. cmd
c. cmd1
b.command
d.command1
Q121. What is the prefix of list box?
A Lst
c. list box
b. list
d. box
Q122. select the event
a. key up
c.dbclick
b. got focus
d. all of above
Q123. RGB() stands for
a.red green blue
c.green blue red
b. red gray blue
d. red green black
Q124. define the output
text1.text=”visual basic”
text2.text=mid(text1.text,8,5)
a. visual
c. visual bas
b. ual basic
d. basic
Q125. define the right output
text1.text=”hello”
text2.text=left(text1.text,3)
a. hel
b. lo
c. llo
d. elo
Q126. Visual Basic forms are identified by a:
a) “.frm” suffix
b) “.mak” suffix
c) “.for” suffix
d) A special icon
Q127. To run an application in Visual Basic:
a) Click on the start button (blue arrow) b)
b) Use the File Menu
c) Use the Project Menu to select Run
d) None of the above
Q128. With polymorphism:
a) one method can have multiple names.
b) one object can have multiple names.
c) many methods can share the same name.
d) many objects can share the same name.
e) None of the above statements are true.
Q129. Which feature is needed to make a programming language object oriented?
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
a.) Encapsulation
c.) Polymorphism
All of the above.
Page 15 of 120
b.) Inheritance
d.) Both a and b.
Q130. Methods are used to represent:
a.) actions.
c.) data.
e.) instances.
b.) classes.
d.) events.
Q131. Properties are used to represent:
a.) actions.
c.) data.
e.) instances.
b.) classes.
d.) events.
Q132. Which is not a property of the Common control class?
a.) Show
b.) BackColor
c.) Font
d.) ForeColor
e.) Name
Q133. Which property determines whether a control is displayed to the user?
a.) Hide
b.) Show
c.) Visible
d.) Enabled
e.) Cursor
Q134. The Button control can be activated:
a.) programmatically through the click event.
b.) by clicking the button with the mouse.
c.) with the form’s DefaultButton property.
d.) Both a and b.
e.) All of the above.
Q135. The CancelButton property belongs to which object?
a.) Button
b.) Form
c.) Label
d.) TextBox
e.) Timer
Q136. In event-driven programming an event is generated by:
a.) the system.
b.) a user’s action.
c.) the program itself.
d.) Both a and b.
e.) All of the above.
Q137. Which is not a common control event?
a.) Click
b.) SingleClick
c.) DoubleClick
d.) MouseMove
e.) MouseDown
Q138. The Activated event is found only in which object?
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
a.) Form
c.) TextBox
e.) Timer
Page 16 of 120
b.) Button
d.) Label
Q139. Which phase of project development typically costs the most?
a.) Analysis
b.) Design
c.) Implementation
d.) Maintenance
e.) Documentation
Q140. Which is not an integer data type?
a.) Single
c.) Short
e.) Long
b.) Byte
d.) Integer
Q141. Which is a numeric data type?
a.) Floating point
c.) Boolean
e.) All of the above.
b.) Integer
d.) Both a and b.
Q142. The KeyPress event will capture pressing the key:
a.) A.
b.) shift.
c.) control.
d.) Both a and b.
e.) All of the above.
Q143. Which argument in the KeyPress parameter list contains the Handled property?
a.) Sender
b.) e
c.) Object
d.) KeyPressEventArgs
e.) None of the above.
Q144. What is the name of the control for putting menus on a form?
a.) FormMenu
b.) MenuForm
c.) MenuControl
d.) MainMenu
e.) Menu
Q145. The standard prefix for a menu item is:
a.) men.
b.) meu.
c.) mit.
d.) mni.
e.) mnu.
Q146. Which symbol creates an access key in the text of a menu item?
a.) @
b.) #
c.) $
d.) %
e.) &
Q147. Which is not a standard dialog box?
a.) ColorDialog
c.) OpenDialog
e.) ZoomDialog
b.) FontDialog
d.) PrintDialog
Q148. The standard prefix for a dialog control is:
a.) dal.
b.) dia.
c.) dil.
d.) dlg.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 17 of 120
Q149. What is the method used to activate the color dialog box?
a.) ActivateDialog
b.) DisplayDialog
c.) ExhibitDialog
d.) ShowDialog
Q150. The name of the class used to programmatically create a color dialog box is:
a.) Color
b.) ColorBox
c.) ColorDialog
d.) ColorDisplay
Q151. The name of the class used to programmatically create a font dialog box is:
a.) Font.
b.) FontBox.
c.) FontDialog.
d.) FontDisplay.
e.) FontDialogBox.
Q152. Which dialog control allows the user to zoom in on a document?
a.) PrintDialog
b.) PrintPreview
c.) PageSetupDialog
d.) Both a and b.
e.) All of the above.
Answers
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
D
D
D
D
A
B
D
A
D
D
D
A
A
D
C
D
A
A
A
A
A
A
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
A
B
A
A
A
C
D
C
A
A
D
A
B
D
E
A
E
C
A
A
E
E
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
A
C
D
E
D
C
E
d
A
C
D
B
E
E
B
E
A
E
A
D
A
D
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
E
D
D
B
D
B
D
A
A
D
C
B
B
B
E
E
D
A
D
E
C
A
89. E
90. A
91. A
92. C
93. B
94. C
95. B
96. B
97. B
98. A
99. B
100. E
101. B
102. B
103. A
104. A
105. D
106. D
107. D
108. D
109. A
110. B
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
D
A
D
D
D
A
D
B
B
C
A
D
A
D
A
A
A
D
E
A
C
A
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
145.
146.
147.
148.
149.
150.
151.
152.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
C
D
B
E
B
A
D
A
D
A
D
D
E
E
E
D
D
C
C
b
SUBJECT: ‘VB’ (PGDCA - 2)
Section – B
[Questions 1 TO 174]
Page 18 of 120
5 Marks Questions
[PAGE 18 TO 100]
Q1. 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.
Q2. Write about salient features of VB. (v.imp)
Ans. Some features of VB are
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
Full set of objects. So that we can design the application.
Lots of icons and pictures to use.
Response to mouse and keyboard actions.
Clipboard and printer access.
Full array of mathematical, string handling, and graphics function.
Can handle fixed and dynamic variable and control arrays.
Sequential and random access file support.
Useful debuggers and error handling facilities.
Powerful database access tools.
ActiveX support.
Package & deployment Wizard makes distributing applications simple.
Q3. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 19 of 120
Q4. Write down the names of different controls and their purpose.
(v.imp)
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.
 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.
Q5. Write down the properties of textbox and their purpose.
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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 20 of 120
 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 unhide 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.
Q6. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 21 of 120
Q7. 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:
a. Menu bar: - It contains different types of menus and a group of similar type instructions are
store in a single menu.
b.Toolbar: - 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.
c. Project Explorer :- it contains the list of forms, module and class modules used in the project
window
d.Properties:- It contains the list of properties for the selected control.
e. Toolbox: - It contains all the implicit controls used in VB.
f. Form Designer: - here we can design the form for vb project.
g. Object Browser: - It allow the user to browse through the various properties,
Q8. 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.
Q9. 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.
Q10. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 22 of 120
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.
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.
Q11. 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
End If
Q12. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 23 of 120
Q13. Discuss Timer control with suitable example.
Ans. Timer control is used to fire an event at specified intervals 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
Label1. caption = “ The timer has been fired “ & str (counter)& “times! “
End Sub
Q14. 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 Add_Click ()
If MaxID =0 then MaxID =1
If MaxID >8 then Exit Sub
MaxID = MaxID +1
Load optbutton (MaxID)
Opt button (0). 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
Opt button (0). Set focus.
End Sub
Private Sub optbutton_Click (index as integer)
Picdisplay. Back color = QB color (Index +1)
End Sub
Q15. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 24 of 120
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.
Q16. 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
Q17. 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?
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 25 of 120
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
Q18. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 26 of 120
== to compare equality
!= Not equal to
Logical operators
AND, NOT, OR
String conciliation
String conciliation -------&
Q19. 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.
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 x:
Private sub command1_click ()
Static x as integer
X=x+1
Me.print x
End sub
Now the value of is changed when we click on the command button.
If x was declared with DIM instead of static, the previous accumulated values would not be
preserved .
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 do to a variable. There are two sources for constants:
Const pi=3.14
Value of pi is universal so value of pi is constant.
Symbolic or user-defined constants are declared using const keyword.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 27 of 120
Q22. Write a program to authenticate user/password pair.
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.
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 variable: - 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 variable: - 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.text = ""
n = Text1.text
While n > 0
s = n Mod 2
Text2 .text= Text2 .text& s
n = Int(n / 2)
Wend
Text2.text = StrReverse(Text2.text)
End Sub
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 28 of 120
Private sub cmdoct_click()
Text2.text=oct(text1.text)
End sub
Private sub cmdhexa_click()
Text2.text=hex(text1.text)
End sub
Q25. Write a function sub-program 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”)
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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 29 of 120
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
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: - 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 specifies 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 30 of 120
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.
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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 31 of 120
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. 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. Steps to add the Rich
Textbox control:1. Select the Project menu and choose component option.
2. Select the Control tab from the component box.
3. Select the Microsoft Rich Textbox Contol 6.0 item from the list of components.
4. Click on apply and Ok button to add the component.
Place the Rich Textbox Control on the form fromToolbox
Q32. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 32 of 120
 The control is automatically resized to fit the boundaries of the docked edge.
Q33. 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.
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
Q34. 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.
Q35. What is the Purpose of Toolbar? How does a menu vary from a toolbar?
(v.imp)
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.
Q36. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 33 of 120
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 characterbased 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.
Q37. 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.
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.
Q38. 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.
Text 1. Text = Date
It will display the system date in the textbox.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 34 of 120
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]
Q39. 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
Q40. (a) Explain various data types available in VB.
(v.imp)
Ans. Data types available in VB
Data type Memory (Bytes)
Range
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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Currency
Boolean
Date
String
Variant
Page 35 of 120
8
2
8
1
16
-922,337,203,685,477.5808 to 922,337,203,685,477.5807
True or False
January 1, 100 to December 31, 9999
0 to approx. 2 billion character.
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. Operators are symbols which effect upon the data.
Operator which work on operands.
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 or more expression . 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.
Q41. 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()
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 36 of 120
Dim r As Integer
Dim d As Integer
Dim cf, a As Double
r = InputBox("Enter radius")
d=2*r
cf = 2 * 3.142 * r
a = 3.142 * r * r
Print "Radius
:", r
Print "Diameter
:", d
Print "Circumference :", cf
Print "Area
:", a
End Sub
Q42. 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
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 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 37 of 120
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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 38 of 120
Private Sub Command2_Click()
List1.AddItem (Combo1.List(0))
List1.AddItem (Combo1.List(1))
End Sub
Q46. How Scrollbars are added in the forms in VB?
Ans. Scrollbars are commonly used in windows programming. Using these, the user can select a
Value by postioning the thumb of the scrollbar to desired position.There are two types of
Scrollbar- Horizontal and Vertical Scrollbar.
Private sub form_laod()
Hscroll1.min=1
Hscroll1.max=255
End Sub
Private Sub hscroll1_Change()
Text1.Text=Hscroll1.Value
End Sub
Q47. 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 placed in standard, class and form modules. Sub procedure is a
procedure that performs a task but doesn’t return any value. 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.
Functions
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 39 of 120
A Function is a procedure that performs a task and returns a value. Each time the function is
called the statements between Function and End Function are executed. The syntax for a
function is as follows.
Function functionname (arglist)
[Statements]
End Function
Q48. 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 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 an object.
Q49. Explain types of dialog boxes.
Ans. There are three kinds of dialog boxes.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 40 of 120
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 password is an 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,”title”
Q50. 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 or shortcut 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.
For example:Private Sub form_MouseDown (Button As Integer, Shift As integer, X As Single, Y As Single)
If Button =2 then
PopUpMenu mnuColors
End if
End Sub
Q51. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 41 of 120
 DragDrop event is recognized when control is dropped onto object
 Drag method starts or stops manual dragging.
Q52. Write a short note on common dialog boxes. (v.imp)
Or
Explain in detail the use of command 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 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.
Q53. 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 displayed1.889889889
Q54. 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 (Byref Num as Integer)
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 42 of 120
Num = 3 * Num
Print “ I am in the procedure (pass by reference)”
End sub.
Sub triple (Byval 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’.
Q55. 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.
Q56. How an array can be passed to a function?
Ans. An array can be passed to a function in two ways.
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
a(i)=inputbox(“Enter values”)
Next
For x = 0 to 4
Print (a(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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 43 of 120
Z (I) = Y (I) + Y (I)
Next I
Fun = Z
End function
Q57. 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
1. DirList Box
2. DriveList Box
3. 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 its
directories should be displayed in the DriveList box 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.
Q58. Describe Menu Editor in VB.(v.imp)
Or
Write the steps to create Menus in VB application.
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.
Q59. 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 are1. 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 ASCII format.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 44 of 120
2. Random access: - Random access also works to retrieve data from ASCII 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.
3. Binary Mode: - Binary mode allows you the greatest amount of flexibility when working with
files. When working with binary access mode, you retrieve data 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.
Q60. Explain the menu creation through menu editor in visual Basic.
Ans. 1. To design menu, click on the tools menu and then select Menu editor. Menu editor dialog
box will appear.
2. Enter caption property and Name property in the first two boxes of menu editor.
3. You can also choose a short cut key for the current menu control.
4. 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.
5. You can type a number in the index field to make the menu control array. These are useful
when you want to list like ones you see at bottom of file menu in various applications.
The help control ID field is 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.
Q61. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 45 of 120
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
Q62. 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 uesd 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.
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
Q63. 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
Dim I as integer
Dim c as integer
c=0
n = Input Box("enter number")
For i = 1 To 10
c=n*i
Debug. Print n, "*", i, "=", c
Next
Q64. What modality is and how does it affect the behavior 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. There are two types of dialog boxes.
1. Modal: - if the dialog box is of modal type then the control will not be transferred to their parent
form until the necessary information has been given to the dialog box or it has been closed. E.g.
of these dialog boxes are msgbox, inputbox in VB.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 46 of 120
2. Modeless: - if the dialog box are modeless type then the control can be transferred to the
parent form without closing the dialog box. E.g. of this type of dialog box is find & replace dialog
box.
Q65. What do you understand by bug (error)? What are the different types of bugs that you
may encounter while programming with visual basic?
OR
Q66. What are the common errors in the visual basic?
(v.imp)
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 bugs(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 an incorrectly spelled variable.
Runtime bugs(errors): 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 bugs(errors): 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.
Q67. 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.
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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 47 of 120
Q68. 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.
Q69. 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: - 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.
Q70. Explain the difference between SDI and MDI applications. Give suitable example.
Describe the purpose of different windows in IDE.
Or
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 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 48 of 120
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.
Q71. 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.
Syntax: On Error { GoTo [ line | 0 | -1 ] | Resume Next }
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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 49 of 120
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.
Q72. Explain break mode.
Or
Why we need to set break point in VB? Give code for the same.
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.
Q73. 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 project
standard forms
Standard form can become the child of MDI No MDI FORM could be the child of standard
FORM
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.
Q74. What are three phases of component based system design?
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 50 of 120
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.
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
Q75. 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: - picturebox 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.
Q76. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 51 of 120
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
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
Q77. 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 the
option of the debug menu
debug menu
It halts the execution of an application and It is monitored automatically by the visual basic
gives a snapshot to its condition at any
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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 52 of 120
Q78. 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 then write NOTEPAD in
the text box click on ok.. Now select open option from the file menu and open the same file.
Q79. What kinds of tools are available for aid in the debugging of vb application? Explain each in
brief.(v.imp)
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 responds 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.
Q80. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 53 of 120
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)
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.
Q81. 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.
Q82. Write down the various types of ActiveX controls.
(v.imp)
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
1. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 54 of 120
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.
2. 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.
3. 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 is called constituent control.
Q83. Differentiate between ActiveX EXE and Active X DLL.
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.
Q84. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 55 of 120
 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
is 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 DAO (Data Access Object) and RDO (Remote Data Object) and all other data access
methods. It is designed to provide a common bridge between different database, file system and
e-mail servers.
Q85. Write a code in Visual Basic to Search 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
Q86. Write a code in Visual Basic to update a record in Database.
Ans.
Object
Command button 1
Properties
Name
Caption
Command button 2
Name
Caption
Command button 3
Caption
Data
Name
DatabaseName
Record source
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”
Setting
Command 1
Modify
Command 2
Update
Exit
Data1
c:\vb\Supplier.mbd
Supplier
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 56 of 120
Data1.refresh
End Sub
Q87. Compare the conventional and Object Oriented Programming.
Ans. Conventional Programming using high language such as COBOL , FORTRAN commonly
known as procedure oriented programming.
1.Large programs are divided into smaller programs known as functions.
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.
Object Oriented Programming
1.Data Structure are designed such that they characterized the objects.
2.Functions that operate on the data of an object are tied together in the data structure.
3.Data is hidden and cannot be accessed by external functions.
4.Objects may communicate with each other through functions.
5 Follows bottom up approach in program design.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 57 of 120
Q88. 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.
Q89. 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.
Q90. 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.
Q91. Explain ADO object model in detail.
(v.imp)
Ans.
ADO is active data object. ADO object model is similar to the DAO (Data Access Object)
model but it can handle more databases and has more features. ADO model consists of three
objects namely.
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 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 58 of 120
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.
Q92. 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 background & 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-ofprocess 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.
Q93. Explain ADO data control.
Ans. Earlier there were DAO (Data Access Object) & RDO (Remote Data Object) 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 (`) 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 59 of 120
When ADO data control is placed & data source is specified we can bind various other controls like
textboxes, list boxes, combo boxes 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.
Q94. 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 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.
Q95. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 60 of 120
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
Q96. What are the different types of data reports? How are they created?
(v.v.imp)
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:
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 61 of 120
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 report1. 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.
Q97. Explain the find methods to locate any record in the recordset.
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.
Q98. 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)
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 62 of 120
e.g
msgbox rs(0)
or
msgbox rs.fields(“Name”)
Q99. 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 existit 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.
Q100. 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.
Q101. 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 codeprivate sub cmdfind_click()
dim rno as integer
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 63 of 120
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
Q102. 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.
Q103. 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. 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.
Q104. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 64 of 120
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.
Q105. Explain the different Advanced Data Access issues?
Ans. Following are five data access scenarios that are more complex than simple Select
queries.
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
.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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 65 of 120
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
Q106. 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.
(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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 66 of 120
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.
Q107. 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.
 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 67 of 120
 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.
Q108. 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 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.
Q109. Explain briefly about COM and DCOM.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 68 of 120
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.
Q110. 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
Q111. Briefly explain the three types of recordsets.
(v.imp)
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.
Q112. What is a DLL? Write a suitable code to call windows API in VB application?
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 69 of 120
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 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
Q113. How can you create an ActiveX control in VB?
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.
Q114. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 70 of 120
 Add new records or update a database based on any changes you make to data displayed in
the bound controls.
Q115. 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
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
Q116. Write the DAO object hierarchy.
Ans. DAO stands for Data Access Object. 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 defines a session for the user. When your application starts, the Jet engine
creates a 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.
Q117. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 71 of 120
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
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.
Q118. What is the advantage of creating a project in Visual Basic?
Or
What is Visual Basic environment?
Ans. A project is a collection 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.
Q119. 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:
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 72 of 120
 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 characters that are required to store the argument.
UCase(argument):- Returns all characters of the argument in upper case.
Q120. 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
Q121. What do we call a Scroll Bar?
Ans. The scroll bars are used 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.
Q122. 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”
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 73 of 120
End sub
Public sub disp()
Msgbox”You are using class module”
End sub
Q123. 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.
Q124. 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
Q125. When will you create DLL?(v.imp)
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.
Q126. 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.
Q127. 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.
Q128. What are the Types of Cursors?
(v.imp)
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 74 of 120
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.
Q129. 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()
rs.CursorLocation = adUseClient
cn.Open "provider=microsoft.jet.oledb.4.0; data source=f:\database.mdb"
rs.Open "emp", cn, adOpenDynamic, adLockOptimistic
End Sub
Q130. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 75 of 120
Q131. 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 some operations 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)
Statements
End Function
Q132. 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 list 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.
Q133. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 76 of 120
Q134. 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.
Q135. What is Locking?
Ans. Locking is a technique that is 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.
Q136. When do we use ActiveX Components?
(v.imp)
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.
Q137. 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.
Q138. 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.
Q139. 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:
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 77 of 120
Dim MatrixA(9, 9) As Double
Q140. Explain different sections of a Data Report?
Ans.
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 any 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.
Q141. 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.
Q142. 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 78 of 120
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"
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
Q143. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 79 of 120
Q144. What are the basic Object Oriented Principles and features ?.
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:
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.
Q145. 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 outprocess 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 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 inprocess server architecture. The file extension for these files is .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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 80 of 120
ActiveX Document DLL:- These Components are used to create component for Web-Based
applications like ActiveX Document EXE. In Contrast to the ActiveX Document EXE these files
require container files that can call the dll files to execute the required functionality.
Q146. 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.
1. Include reference of ADODB library(Microsoft AcvtiveX 2.0 Library)
2. 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 “select * from 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
Q147. How will you play a Sound and a Movie File in visual Basic?.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 81 of 120
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.
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
Q148. What can be error handler used for?
(v.imp)
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 used 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.
Q149. 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 82 of 120
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). OLEDB enables 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. These 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 and 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.
Q150. What is data environment designer used for?.
Ans. A Data Environment Designer use 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 and 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 Recordset Objects.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 83 of 120
Q151. 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.
 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.
Q152. What is a Data Report Designer?
(v.imp)
Ans. Data Report designer is a form and 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 number of sections like the header, footer and
details. Each of these section objects can 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 any 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.
Q153. What are the Features of Data Report Designer?
(v.imp)
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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 84 of 120
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.
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.
Q154. 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.
Reuseability 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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 85 of 120
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.
Q155. Write a program to swap two values using call by reference parameter passing
mechanism.
Ans Function swap(ByRef a As Integer, ByRef b As Integer)
Dim c As Integer
c=a
a=b
b=c
Text3.Text = a
Text4.Text = b
End Function
Private Sub Command1_Click()
swap Text1.Text, Text2.Text
End Sub
Q156. Write a program that request a month of the year and then gives the number days in
the month?
Ans
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 86 of 120
Private Sub Command1_Click()
Dim a As Integer
a = Text1.Text
If a = 1 Then
MsgBox "31 days in january"
ElseIf a = 2 Then
MsgBox "28 days in february"
ElseIf a = 3 Then
MsgBox "31 days in March"
ElseIf a = 4 Then
MsgBox "30 days in April"
ElseIf a = 5 Then
MsgBox "31 days in May"
ElseIf a = 6 Then
MsgBox "30 days in June"
ElseIf a = 7 Then
MsgBox "31 days in July "
ElseIf a = 8 Then
MsgBox "31 days in August"
ElseIf a = 9 Then
MsgBox "30 days in September'"
ElseIf a = 10 Then
MsgBox "31 days in October"
ElseIf a = 11 Then
MsgBox "30 days in november"
ElseIf a = 12 Then
MsgBox "31days in December"
Else
MsgBox "wrong month entered'"
End If
End Sub
Q157. What do you mean by registering of a COM object/ how it is registered?
Ans When creating new applications or components, it is best to create .NET Framework
assemblies. However, Visual Basic also makes it easy to expose a .NET Framework component
to COM. This enables you to provide new components for earlier application suites that require
COM components. This walkthrough demonstrates how to use Visual Basic to expose .NET
Framework objects as COM objects, both with and without the COM class template.
The easiest way to expose COM objects is by using the COM class template. The COM class
template creates a new class, and then configures your project to generate the class and
interoperability layer as a COM object and register it with the operating system.
To set up your project to generate a COM object
1. Open a new Windows Application project from the File menu by clicking New Project.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 87 of 120
2. In the New Project dialog box under the Project Types field, check that Windows is
selected. Select Class Library from the Templates list, and then click OK. The new project is
displayed.
3. In Solution Explorer, right-click your project, and then click Properties. The Project
Designer is displayed.
4. Click the Compile tab.
5. Select the Register for COM Interop check box.
Q158. Explain the process of adding controls to the form?
Ans we can add controls to the form in two ways first we can drag and drop the controls from
the the tool box and we also add control dynamically to the form at run time. We add control
mostly at design time.
To create a application which display hello world.
1. click file-- New project -- select the standard Exe form.
2. form layout window is displayed
3. resize the form by dragging the its borders.
4. double click the command button control in the toolbox to create a command button.
5. double click on the label control in the toolbox to create the label on the form.
6. now set the following properties of the form, command button and label like name and
caption.
7. now double click on the command button and open the code window and the write the code
for command button click. Click is the default event for command button control.
8. now save the project and run your project by pressing the F5 key from the key board.
Q159. How do you specify an access key for a menu item?
Ans menu command usually contain access key donated by underline letters in the menu text
users can quickly select menu commandby pressing the ALT key along with the access key .
Some commonly used access command may also have a shortcut key (usually a function key,or
a letter combined with CTRL,ALT or SHIFT key)Shortcut key activate the menu command without
having the select it.
To create a menu command
1. Enter the caption for the menu command in the caption field .( Includean ampersand(&)in the
caption to create an access key)
2. enter the name for the menu command in the name field.
Q160. How do you check whether a condition should be checked at the top of loop or at
the bottom ?
Ans we know that the condition checking in the for and while first or at the top if condition is true
then the loop is executed else not but the condition testing in the last in the do-while loop
because the condition testing statement written in the last in this case statement executed first
and the checked according to the syntax of the do while loop.
for Loop
Syntax
Dim a as integer
For a=1 to 10 step 1
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 88 of 120
Statement1
Next a
In the above given program the condition testing in for loop in beginning of the loop and then
executing the statement if condition is not true then loop is not executed.
Q161. What is control array? How it is created ? discuss its uses.
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. These Controls have a common index property that is
used to identify a particular control in a control array.
How created control Array
First add two command
Buttons first to add labels and
Second to remove the labels
Add a label and make a control
Array for label.
Private Sub Command1_Click()
Dim a As Integer
For a = 0 To 3
Label1(a).Caption = "label" & a
Next
End Sub
Private Sub Command2_Click()
Dim a As Integer
For a = 3 To 0 Step -1
Label1(a).Caption = ""
Next
End Sub
Control array is used to create a collection of controls. It is easy to maintain them and use
them. It is used to create more than one control of same type then we use control array.
Q162. What is collection? How do we add, delete elements from it?
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 89 of 120
Ans A collection is an object that contains a set of related objects. There is another type of
looping mechanism in visual basic that allow to you iterate ,or step ,through each control in a
collection.you can do this using for each …next loops. This technique is extremely useful when
you don’t know the exact number of items in the collection.
You can use for each loop through all items in the collection using code similar to the
following.
Dim cmd as command1
For each cmd in form1
With cmd
If .index<> index then
Msgbox “button “& trim$(str$(.index))&”was not pressed.”
End if
End with
Next
The first line dimension an object of the command button class. The next line tells visual basic to
iterate through every command button object for form1. the with cmd statement on the next line
tells the visual basic to use the current object in the collection set to cmd.
Looping through collection is useful for many tasks including iterating through items in treeview
and listview controls,childs formsin an MDI application and object in a dynamic HTML
documents.
Q163. Discuss the string handling in-build function : instr, mid, left, right with suitable
example.
Ans 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]
Example:
str=instr(1,”Visual Basic”,”a”)
mid() function :-It returns a substring containing a specified number of characters from a
string. The syntax is
mid(string,strat,length)
Example:
str=mid(“Visual Basic”,3,7)
left() function:- It returns a substring containing a specified number of characters from the
beginning of a string. The Syntax is
left(string ,length)
Example:
str=left(“Visual Basic”,5)
right() function:- It returns a substring containing a specified number of characters from
the end of a string. The Syntax is
right(string ,length)
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 90 of 120
Example:
str=right(“Visual Basic”,4)
Q164. Suppose you have a database table EMP( ID,NAME,AGE,EMAIL) IN MS ACCESS .
Discuss the following using ADO.
(a) Connecting to the database
(b) Insert a record into the table
(c) Display records on a form.
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.
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
End Sub
Private Sub Command2_Click()
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MoveLast
End If
End Sub
Q165. Give Visual basic code for setting a connection to a data source.
Ans Create a DSN-less Database Connection: - The easiest way to connect to a database is to
use a DSN-less connection. A DSN-less connection can be used against any Microsoft Access
database on your web site.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 91 of 120
If you have a database called "northwind.mdb" located in a web directory like
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/webdata/northwind.mdb"
%>
Note, from the example above, that you have to specify the Microsoft Access database driver
(Provider) and the physical path to the database on your computer
Q166. Give visual basic code for frames. And also explain what are the various properties
associated with it.
Ans frame is often used as a container for check box, option button too, each check box is
completely independent. Thus the setting for one check box has no effect on the setting for the
other in the same group.
CheckBoxes: - Option bars are used quite often in the windows environment as they can only
have two outputs 0 and 1 these get used to process the form. In this example it will be used to
change the some text from normal to bold or to italic.
Private Sub chkBold_Click()
If chkBold.Value = 1 Then ' If checked.
txtDisplay.FontBold = True
Else ' If not checked.
txtDisplay.FontBold = False
End If
End Sub
Private Sub chkItalic_Click()
If chkItalic.Value = 1 Then ' If checked.
txtDisplay.FontItalic = True
Else ' If not checked.
txtDisplay.FontItalic = False
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 92 of 120
End If
End Sub
The checkboxes can be turned on at runtime by simply typing
name.value = 1 ' 1 On , 0 off
Q167. There is a label named lblResult that has a property named caption. There is a
variable named X.
(a) write a statement that display the value of x in the label’s caption.
(b) Write a statement that display the variable X in the label’s caption.
Ans
Private Sub Command1_Click()
Dim x As Integer
x = InputBox("enter the value of X")
lblResult.Caption = x
End Sub
Private Sub Command2_Click()
lblResult.Caption = "X"
End Sub
Q168. Write VB code for creating a pop-up menu.
Ans Option Explicit: Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
' Make sure it's the right button.
If Button And vbRightButton
Then PopupMenu mnuPopup
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 93 of 120
End Sub
Private Sub mnuChoice1_Click()
MsgBox "Choice 1"
End Sub
Private Sub mnuChoice2_Click()
MsgBox "Choice 2"
End Sub
Private Sub mnuChoice3_Click()
MsgBox "Choice 3"
End Sub
Q169. How to create Control Array at Run Time
Ans Add a command button to the form and name it as cmd Arr.
In the properties window set the value of the command button’s index property to 0.
Add the following code to the
Form_Load ( )
Private Sub Form_Load ( )
Load cmdArr (1)
cmdArr(1).Left=cmdArr(0).Left
cmdArr(1).Top=cmdArr(0).Top+cmdArray(0). height
CmdArr(1).Visible = True
End Sub
Q170. PRINTING TWO DIMENSIONAL ARRAYS
Ans
Private Sub cmdArray1_Click( )
Dim counter, counter2
Array (1 to 3, 1 to 4) as integer
For Counter1 = 1 to 3
For Counter 2=1 to 4
Array1(Counter1,Counter2)=3
Print Array1(Counter1,Counter2);
Next Counter2
Print
Next Counter 1
End Sub
The output will be as follows :3333
3333
3333
Q171. what is progress bar how to use it.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 94 of 120
Ans A ProgressBar control allows you to graphically represent the progress of a transaction. The
control consists of a frame that is filled as the transaction occurs. The Value property determines
how much of the control has been filled. The Min and Max properties set the limits of the control.
Use the ProgressBar whenever an operation will take more than a few seconds to complete. You
must also know how long the process will take by using a known end point and setting it as the
Max property of the control
Q172. What is data DATA ENVIRONMENT designer
Ans The Data Environment designer provides an interactive, environment for creating
programmatic data access. At design time, you set property values for Connection and
Command objects, write code to respond to ActiveX® Data Object (ADO) events, execute
commands, and create aggregates and hierarchies. You can also drag Data Environment objects
onto forms or reports to create data-bound controls.
Q173. Explains life cycle of forms with suitable example.
Ans A form’s life cycle starts when it gets 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 it’s 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Section – C
[QUESTIONS 1 TO 23]
Page 95 of 120
10 Marks Questions
[PAGE 95 TO 120]
MULTIPLE CHOICE OBJECTIVE TYPE QUESTION
Q1.
What is visual basic also explain its silent feature?
Ans: VISUAL BASIC is a high level programming language. Which has been evolved from the
earlier DOS version called BASIC. BASIC means Beginners' All purpose Symbolic Instruction
Code. It is a relatively easy programming language to learn. The code looks a lot like English
Language. Different software companies have produced different versions of BASIC, such as
Microsoft QBASIC, QUICKBASIC, GWBASIC, IBM BASIC and so on. However, people prefer to
use Microsoft Visual Basic today, as it is a well developed programming language and supporting
resources are available everywhere. Now, there are many versions of VB exist in the market, the
most popular one and still widely used by many VB programmers is none other than Visual Basic
6.0. We also have VB.net, VB2005, VB2008 and the latest VB2010. Both VB2008 and VB2010
are fully object oriented programming (OOP) languages.
Some features of VB are: 1. Visual Basic provides GUI Environment.
2. Visual Basic is not case sensitive language.
3. We can create crystal Repots.
4. Visual Basic provides additional internet capabilities.
5. We can create user define menu bar.
6. Provide database connectivity tools.
7. Full set of objects. So we can design the application.
8. Lots of icons and pictures to use.
9. Response to mouse and keyboard actions.
10. Clipboard and printer access.
11. Full array of mathematical, string handling, and graphics function.
12. Can handle fixed and dynamic array and control arrays.
13. Sequential and random access file support.
14. Useful debuggers and error handling facilities.
15. Powerful database access tools.
16. We can create user define controls and insert other extrinsic controls called ActiveX controls.
17. Package and deployment Wizard makes distributing applications simple.
18. Faster compiler.
19. Visual Basic provides useful debugger and error-handling facilities.
20. Useful debugger and error-handling facilities.
Q2.
What is event and event driven programming?
ANS- Event driven programming is a flexible way to allow your program to respond many
different inputs or events programs operated in a sequential fashion that did some processional
and displayed it waited for a user response and did some more processing and so on. In event
driven programming the flow of program execution is controlled by the events that occur as the
program run. Each time an event occurs, it causes a message to be sent to the operating system.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 96 of 120
The system processes the message and broadcasts it to the other windows. Each window can
take the appropriate action based on its own instructions for dealing with that particular message.
Event : - 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. Some events
are like:  Click
 Dblclick
 Keyup
 Keydown
 Load
Q3.
Difference between c and visual basic
ANS- There are many difference between c and visual basic
1. C language was developed by
Dennis Ritchie.
1. Visual Basic was developed by Alan Copper.
2. C is console base language.
2. VB is GUI base language.
3. C is case sensitive language.
3. VB is not case sensitive language.
4. In C we use header files.
4. In VB we do not use header files.
5. C can’t use classes.
5. VB use Classes.
6. C use main() function.
6. VB can’t use main() function
7. C provides only Functions.
7. VB provides Functions, procedures, Modules.
8. In C we use getch() function to
stop the display screen.
8. In VB we doesn’t used any function to stop
the screen.
9. In C we can’t use forms.
9. In VB we use forms.
10.C can’t provide Database
connectivity tools.
10. VB provides Database connectivity facility
through ADODC control.
11. We can’t create user menu bar.
11. We can create user menu bar.
12. C can’t provide ActiveX control.
12. Provide ActiveX control.
13. We can’t create crystal Repots.
13. We can create crystal Repots.
14. We do not use any keyword to
declare variable.
14. We use DIM keyword to declare variable.
Q4.
What is IDE and also explain its component?
Ans VB works in an Integrated Development Environment (IDE). IDE is a collection of menus,
toolbars and windows that make up your programming easy. Each part of IDE affects different
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 97 of 120
aspects of your programming activity. One of the most significant changes in Visual Basic 6.0 is
the Integrated Development Environment (IDE). IDE is a term 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 to all of the development
tools that we need from one screen called an interface. The IDE is also commonly referred to as
the design environment, or the program.
Components of IDE:  Title bar
 Menu Bar
 Standard Bar
 Toolbox
 Project Explorer
 Properties window
 Form Layout Window
 Form Designer window
 Object Browser window
 Code and text editor window
The Visual Basic startup dialog box
1) Title Bar : - Title bar is the top most bar on the IDE window that display the title of the project.
Title bar has three buttons minimize, maximize (restore down) and close.
2) Menu Bar : - This Menu Bar displays the commands that are required to build an application.
The main menu items have sub menu items that can be chosen when needed. The toolbars in
the menu bar provide quick access to the commonly used commands and a button in the toolbar
is clicked once to carry out the action represented by it.
3) Standard Toolbar : - It contains small icon buttons which are used to access most commonly
commands through shortcut small icon.
4) Toolbox : - The Toolbox contains a set of controls that are used to place on a Form at design
time thereby creating the user interface area. Additional controls can be included in the toolbox
by using the Components menu item on the Project menu. A Toolbox is represented in figure
shown below.
5) Project Explorer : - Docked on the right side of the screen, just under the toll bar. It is the
Project Explorer window. The Project Explorer as showed in figure services as a quick reference
to the various elements of a project namely form, classes and modules. The entire objects that
make up the application are packed in a project. A simple project will typically contain one form,
which is a window that is designed as part of a program's interface. It is possible to develop any
number of forms for use in a program, although a program may consist of a single form. In
addition to forms, the Project Explorer window also lists code modules and classes.
It also contains a hierarchical tree structure of the forms in the projects. A Project
Explorer consists of a number of forms, modules and controls that make up an application. It
helps to manage & navigate multiple projects. This window provides three buttons:
View Code.
View Object.
Toggle Folders.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 98 of 120
6) Properties Window : - The Properties Window is docked under the Project Explorer window.
The Properties Window exposes the various characteristics of selected objects. Each and every
form in an application is considered an object. Now each object in Visual Basic has
characteristics such as color and size. Other characteristics affect not just the appearance of the
object but the way it behaves too. All these characteristics of an object are called its properties.
Thus a form has properties and any controls placed on it will have properties too. All of these
properties are displayed in the Properties Window
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.
7) Form Layout Window : - Form Layout Window is used to set the position of the form on the
computer screen where it will be displayed when the project is run.
8) Forms designer window : - A form designer window contains the form. Form is the heart of
Visual Basic application. Form is a canvas or container window on which you will place the
various objects that make up application. We work in form designer window to add controls to the
form. It has a title bar in which it contains Project1- form1 (Form) name, minimum button,
maximum (restore down) button and close button.
9) Object Browser : - The Object Browser allows us to browse through the various properties,
events and methods that are made available to us. Selecting Object Browser from the View menu
or pressing the key F2 accesses it. The left column of the Object Browser lists the objects and
classes that are available in the projects that are opened and the controls that have been
referenced in them. It is possible for us to scroll through the list and select the object or class that
we wish to inspect. After an object is picked up from the Classes list, we can see its members
(properties, methods and events) in the right column.
A property is represented by small icon that has a hand holding piece of paper. Methods
are denoted by little green block while events are denoted by yellow lightning bolt icon.
10) Code and text editor window : - VB objects can recognize many different events. The
objects will not function unless you have written code to tell them what to do when the event
happens. This means that for any event, you must write an event procedure telling VB what to
do, so event procedures are lines of programming code that tell VB how to respond to a given
event.
Double-clicking any, blank part of the form will open the code window. VB program code
is entered in this window. It contains two drop-down list boxes. If you pull down the left hand box
in the code window you will see a list of controls on your form. If you pull down the right hand
box, you will see the list of events supported by the selected controls.
Q5.
What is INTRINSIC CONTROLS
Ans- The controls are the building blocks (pre-define). Which are used to assemble (design) the
VB program. The toolbox is a foundation of controls from which we can select controls and place
them in the form. There are two types of controls in Visual basic.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 99 of 120
1) INTRINSIC CONTROLS: - These controls reside within VB itself. They can’t be removed from
the toolbox. The Toolbox contains 21 intrinsic controls.
Icons
Control name
Pointer
Label
Deception
It is by default Selected control.
It is used to interact with controls on the form.
It is used to display graphics images, icons on a form and we can use
as a container object.
Displays static text.
TextBox
It is used to accept user input, which can display only editable text.
Frame
It's just like a container - It can hold other controls. There are two very
good reasons to use it. First is If you want multiple groups of option
buttons then place each group in a frame and each group will operate
independently. Second is If you want to manipulate controls as a
group then put them in a frame and you can handle them all at one
time.
This one works just like you expect. Press the button and it executes
a block of code.
Enables users to select or deselect an option. We can select multiple
check boxes depending upon the user.
Lets user select one option from a group options.
PictureBox
Command
Button
CheckBox
Option
Button
ComboBox
ListBox
HScrollBar
VScrollBar
Timer
DriveListBox
DirListBox
FileListBox
It is used to contain list of items but user can select only one item
from a list of items or add and remove items in the combobox.
It is used to contain list of items but user can select multiple items
from a list of items using Multiple property or add and remove items in
the listbox.
Basically you use the slider value of a scroll bar as the input for other
code that you write. These are normally used in conjunction with
other controls.
Basically you use the slider value of a scroll bar as the input for other
codes that you write. These are normally used in conjunction with
other controls.
This is the most unusual of the intrinsic controls. It is Used to set a
timer on Form using its Interval property. At each interval, its Timer
event fires. Lets the program to perform actions in real time without
user interaction.
It is used to enable all the drives and we can select drive from the
drive listbox.
It is used to enable all the directories and we can select directory
from the directory listbox.
It is used to access the file in the directory.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Shape
Line
Image
Data
OLE
Page 100 of 120
Graphic control that can draw and fill a rectangle, circle, square, or
oval. It does not respond to events.
It is used to draw a line on the form.
It is used to display images, icons on a form and we cannot use as a
container object.
It is used to connect the program to the database.
It is used to insert objects on Visual Basic application, which come
from other applications already on your computer (such as Word,
Excel etc….) then this control is very useful.
Q6.
Explain explicit controls
Ans ) EXTRINSIC CONTROLS: - These are outside VB controls & reside in toolbox with .OCX
files. These can be added to & removed from the toolbox. If we want use it, firstly, insert the
extrinsic control.
Step to insert extrinsic control –
1)Click on project menu and then select component option or right click on the Toolbox then
select Component option.
2)Then it displays Components dialog box, which contains Controls, Designers, and Insert able
Objects tab.
ACTIVEX CONTROLS.
3) Then select any one of then which component programmer requires.
4) Then click OK button.
5) Now the control that you selected from the components dialog box, is displayed in the toolbox.
Q7.
What is SDI and MDI form?
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 101 of 120
Ans. In a visual basic we used two type of form first is SDI and second is MDI form
1. SDI (Single Document Interface)
2. MDI (Multiple Document Interface)
1. SDI (Single Document Interface) : - In an SDI interface there is only one document open and
only one form for the user to view and modify. If the user opens another document, the current
one is closed.
Most applications in Windows 95 or later one, use a Single Document Interface. Each
window of the application holds a single document. So, if the user wants to open more
documents with that application, he must open a new window. An example of an SDI application
is Windows Notepad.
2. MDI (Multiple Document Interface) : - The Multiple Document Interface (MDI) was designed
to simplify the exchange of information among documents all under the same roof with the main
application. You can maintain multiple open windows, but not multiple copies of the application.
Data exchange is easier when you can view and compare many documents simultaneously.
You almost certainly use Windows applications that can open multiple documents at the
same time and allow the user to switch among them with a mouse-click. Multiple Word is a typical
example, although most people use it in single document mode. Each document is displayed in
its own window and all document windows have the same behavior. The main Form or MDI Form
isn't duplicated. But it acts as a container for all the windows and it is called the parent window.
The windows in which the individual documents are displayed are called Child windows.
An MDI application must have at least two Forms, the parent Form and one or more child
Forms. Each of these Forms has certain properties. There can be many child forms contained
within the parent Form. But there can be only one parent Form.
The parent Form may not contain any controls. While the parent Form is open in design
mode, the icons on the ToolBox are not displayed and you can't place any controls on the Form.
To create an MDI application, follow these steps:
Q8.
Explain scope of variable in visual basic with diagram
Ans The scope of variables is the portion of code from which that variable can be accessed.
Scope variable depend upon where programmer declared the variable. The scope of variable is
procedure-level (local), Module-level and project level. For example a variable declared within
the private sub section will have scope within the End Sub block.
If we want to access the variable all the program with in the single form, then variable
declared in general section its called form level variable.
The scope of variable is defined into three parts
Local variable
Modual variable
Project variable
Local level variable: - A local variable with procedure scope is recognized only within the
procedure in which it is declared. A local variable can be declared with Dim keyword. When a
local variable is declared with the Dim keyword, it means the scope of the variable is private. We
can’t access this variable out side of the procedure. The values of the local procedures variables
are not preserved and the memory allocated to those variables is released.
Dim X As Integer
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 102 of 120
The local variables exist as long as the procedure in which they are declared. Once a
procedure is executed, the values of local variables are lost and the memory used by these
variables is free and can be reclaimed. Variables that are declared with Dim keyword exist only
the procedure is being executed.
For example : - In the following program "command1" and "command2" the variable X is
declared in each of the modules. Each variable X is independent of the other--the variable is only
recognized within its respective procedure.
Module Level Variables: - A module level variable is available to all the procedures in the
module. Using Public or Private keyword declares them. If you declare a variable using a Private
or Dim keyword in the declaration section of a standard BAS module, a form module, a class
module and so on then you are creating a private module-level variable. Such variables are
visible only from within the module and can't be accessed from the outside. In general these
variables are useful for sharing data among procedures in the same module:
In the declarative section of any module
Private Login As Date
' Private module-level variable
Dim Password As String
' another private module-level variable
You can also use the Public keyword for module-level variables. All module types except
BAS modules. (Public variables in BAS modules are global variables.) In this case, you are
creating module-level variable that can be accessed by all procedures in the module to share
data and that also can be accessed from outside the module. In this case, however, it's more
appropriate to describe such a variable.
' In the declaration section of Form1 module
Public CustomerName As String
' A Public property
You can access a module property as a regular variable from inside the module and as a custom
property from the outside:
' From outside Form1 module...
Form1.CustomerName = "Dharam & Neshan"
Project level variables: - Project level variable is also called global or public scope. It means the
variable is accessible to all procedures in all modules of the project. The variables available to all
the modules and procedures in an application are said to have project level variable. Public
keyword is used to declare variable as project level scope. It is also known as global variable.
Basically project level variables are declared when we want use same variable in whole project. It
is declared in the general section but we can’t declared in any private sub block.
Public vs private Variables : - The scope of the public variable is global, it means variable can
be accessible in all procedures and modules. The scope of the private variable is local, it means
variable can be accessible within procedure only where it is declared. A variable can have the
same name and different scope.
For example, we can have a public variable named R and within a procedure we can
declare a local variable R. References to the name R within the procedure would access the local
variable and references to R outside the procedure would access the public variable.
Static Variables : - Static variables are not reinitialized each time Visual Invokes a procedure
and, therefore, retain or preserve value even when a procedure ends. In case we need to keep
track of the number of times a command button in an application is clicked, a static counter
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 103 of 120
variable has to be declared. These static variables are also ideal for making controls alternately
visible or invisible. A static variable is declared as given below.
Static sta As Integer
Variables have a lifetime in addition to scope. The values in a module-level and public variables
are preserved for the lifetime of an application whereas local variables declared with Dim
keyword. It can exist only with the procedure in which they can declare is still being executed.
The value of a local variable can be preserved using the Static keyword. The following procedure
calculates the running total by adding new values to the previous values stored in the static
variable value.
The following is an example of an event procedure for a CommandButton that counts and
displays the number of clicks made.
Private Sub Command1_Click ( )
Static Counter As Integer
Counter = Counter + 1
Print Counter
End Sub
The first time we click the CommandButton, the Counter starts with its default value of zero.
Visual Basic then adds 1 to it and prints the result.
Q9.
What is data type explain with details?
Ans Data type means what type of data will be stored in the variable. This data can be an
alphabet, numerical having decimal point or without decimal point. Data type determines size
(range) of the data and how much storage space is allocated by variables. Visual Basic supports
many kind of data type. By default Visual Basic variables are of variant data types. The variant
data type can store numeric date/time or string data. When a variable is declared a data type is
supplied for it that determines the kind of data they can store. The fundamental data types in
Visual Basic including variant, integer, long, single, double, string, currency, byte and Boolean.
Each data type has limits to the kind of information and the minimum and maximum values it can
hold. In addition, some types can interchange with some other types. Lists of Visual Basic data
types are given below.
In Visual Basic 6.0, there are 11 different data types available in visual basic. Like…
Type
Store
Memory
Identifier
1. Integer
Whole numbers
2 bytes
%
2. Long
Whole numbers
4 bytes
&
3. Single
Decimal numbers
4 bytes
!
4. Double
Decimal numbers
16 bytes
#
5. String
Text information
1 byte
$
6. Boolean
True/ False
2 bytes
-7. Byte
Whole number
1 byte
-8. Currency
@
9. Date
Date & Time
8 bytes
-10. Object
None
None
11. Variant
Any of the data types
16 bytes
--
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 104 of 120
Integer : - The Integer data type occupies 2 bytes. The valid range of an Integer variable is 32768 to 32767. Integers should be used when you are working with values that can’t contain
fractional numbers.
Long : - The Long data type occupies 4 bytes Memory. The valid range of a long variable is 2,147,483,648 to 2,147,483,647. Long variables can only contain non-fractional values. Long
data type is over Integers for increased performance. Most Win32 functions use this data type for
this reason.
Single : - The Single data type occupies 4 bytes memory space. The valid range of a long
variable is -3.402823e38 to -1.401298e - 45 for negative values and from 1.401298e -45 to
3.402823e38 for positive values. When you need fractional numbers within this range then we
can use single data type.
Double: - The Double data type occupies 16 bytes Floating-point memory used. These variables
range from -1.79769313486232e308 to -4.94065645841247e-324 for negative values and from
4.94065645841247e-324 to 1.79769313486232e308 for positive values. When high accuracy is
needed then we can use double data type.
String : - The String data type usually used as a variable-length and fixed-length type of
variables. A variable-length string can contain up to approximately 2 billion characters. If we use
fixed-length then it occupies fixed length the length that we define in the declaration time. Each
character has a value ranging from 0 to 255 based on the ASCII character set. Strings are used
when Text is involved.
Boolean : - The Boolean data type has only two states True and False. These types of variables
are stored 16-bit (2 Byte) memory. For example, lets suppose that you have a textbox (Text1)
and a command button (Command1). You want only Command1 to be enabled when there is text
in Text1. You would do something like this...
Whenever you Run the program then Command1 will only be enabled when there is text typed
into Text1, other wise command1 is disabled.
Byte : - The Byte data type is occupies 1-byte, which can store value from 0 to 255. This data
type is very useful for storing binary data.
Currency : - This data type is used for holding values related to item rates, payrolls details and
other financial functions. However this data type should not be used if you need extreme
accuracy beyond the fourth decimal point. For example, if you are working on foreign exchange
details or interest rates for very large values. So user used currency data type. Declaration for
currency is
Dim salary as currency
Date : - This variable holds date and time data. It can hold time from January 1 to December
31,9999 and time from 00.00.00(midnight) to 23.59.59. It occupies 8 bytes of memory. The date
is displayed as per the setting in your computer. You can store it in British format, American
format or any other format that is available in the regional setting on your control panel.
Dim tomorrow as date
Object : - In visual basic forms, controls, procedures and recordsets are all considered as
objects. All programming activity revolves around these objects. Visual basic is very much an
object-based programming language. It is natural to use Object data types.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 105 of 120
Variant : - Variant is a special data type that can contain any kind of data except fixed-length
string data. Variant data can also be the special values Empty, Error, and NULL.
Dim a
It is a variant data type, because we can mention any data type. It will automatically pick any type
of data in the program.
Q10. Explain the difference between implicit and explicit declarations. Explain with
suitable example.
Ans There are many ways of declaring variables in Visual Basic, depending on where the
variables are declared and how they are declared. We can determine how they can be used by
our application. The different ways of declaring variables in Visual Basic are listed below:  Implicit Declaration
 Using Option Explicit statement
Implicit Declaration
Declaring a variable tells Visual Basic to reserve space in memory. There are two ways to
declare implicit variable.
1. Automatically variable declaration.
2. Using Dim keyword.
1. Automatically variable declaration: - It is not must that a variable should be declared before
using it. Visual basic language provides automatically variable declaration facility, it means we
can use variable without declaration. In this case Visual Basic compiler declares variable
automatically with variant data type and NULL value. This is called implicit declaration.
2. Using Dim keyword: - The variables are declared with Dim (Dimension) keyword and without
using Option Explicit are called implicit variables.
Syntax: Dim < variable name > as < date type >
1. Dim is a keyword that tells visual basic that you want to declare a variable.
2. Variable name is the name of the variable.
3. As is a keyword that tells visual basic that you are defining the data type for the variable.
4. Data type is the type of data.
For example
Dim strName As String
Dim intCounter As Integer
In the above example, we declared two variables strName as string type variable and intCounter
is an integer type variable.
Using Option Explicit statement : - It may be convenient to declare variables implicitly. But it
can lead to errors that may not be recognized at run time. For example a variable by name
intcount is used implicitly and is assigned to a value. In the next step this field is incremented by
1 by the following statement
Intcount = Intcunt + 1
This calculation will result in intcunt a value of 1 as intcount would have been initialized to zero.
This is because the intcount variable has been incunt in the right hand side of the second
variable. But Visual Basic does not see this as a mistake and considers it to be new variable and
therefore gives a wrong result.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 106 of 120
In Visual Basic, to prevent errors of this nature we can declare a variable by adding the following
statement to the general declaration section of the Form.
Option Explicit : - This forces the user to declare all the variables. The Option Explicit
statement checks in the module for usage of any undeclared variables and generates error
reports to the user. The user can 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.
 Click Tools menu then select Options…
 Then it will display Options dialog box that contains many tabs.
 Click the Editor tab.
 Check Require Variable Declaration option and then click the OK button
Q11. Explain operator and its types in visual basic.
Ans Operators are some special symbols, which are used to perform some specific task in visual
basic. Operators are performed operation on operands value. Operators are used to perform
different type of operations into our program. An expression is a series of value elements
combined with operators, which will gave a new value. The operators act on the value elements
by performing calculations, comparisons or other operations. There are many types of operators
used in visual basic.
Types of Operators
Visual Basic provides the following types of operators:
 Arithmetic Operator.
 Relational Operator.
 Logical Operator.
 Bitwise Operator.
 Special operator.
Arithmetical Operators: - Arithmetical operators are used to perform mathematic operation. It
will take minimum two operands and return the result of the mathematical calculation. There are
various types of arithmetic operator used in visual basic 6.0.
Operators Description
Example
Result
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 107 of 120
+
Add
5+5
10
-
Subtract
10-5
5
/
Divide
25/5
5
\
Integer Division
20\3
6
*
Multiply
5*4
20
Mod
Remainder of division 20 Mod 6
2
Relational/Comparison Operators in Visual Basic
Operators Description
Example
Result
>
Greater than
10>8
True
<
Less than
10<8
False
>=
Greater than or equal to
20>=10
True
<=
Less than or equal to
10<=20
True
<>
Not Equal to
5<>4
True
=
Equal to
5=7
False
Logical Operators : - These operators are used to combine two or more relational expressions.
They also return their result in a Boolean form. Various types of logical operators used in visual
basic but basically we use three operators in visual basic. All LOGICAL operators have priorities
lower than arithmetic and relational operators. Therefore if an expression involving arithmetic
relational and logical operators, the arithmetic operators are evaluated first, followed by the
relational operators, followed by the logical operators.
Operators
Description
OR
Operation will be true if either of the operands values are true
AND
Operation will be true only if both the operands values are true
NOT
If operand value is true then it returns false.
Q12. Explain control statement in visual basic
Ans Control statements in Visual basic: 1. If ….Then
selection statement
2. If ….Then……Else
selection statement
3. If ….Then……Elseif
selection statement
4. Nested If statement
5. IIF ( ) statement
6. Select case statement
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 108 of 120
1. if...Then selection statement : - If...Then selection statement performs an indicated action,
only when the condition is true, otherwise the action skipped. It is the basic condition control
statement. When we have single condition then mostly used this statement. The if ….Then
selection statement allows a programmer to test the value of a conditional expression and to
select or reject the execution of the statement or block of statements depending on this value. It
is also known as single block statement.
Syntax If...Then selection statement
2. If...Then...Else selection statements : - The If...Then...Else selection statement allows the
programmer to specify that a different action is to be performed, when the condition is True or
when the condition is False. If Expression is true then it executes first statement block, otherwise
it executes second statement block.
Syntax of the If...Then...Else selection statement
If <condition > Then
statements
‘First Statement Block
Else
statements
‘Second Statement Block
End If
3. If ….Then……Elseif selection statement : - If we have more than two conditions then we uses
if else if statement. In this we can create multiple blocks of statements and it will execute
according to the condition.
Syntax of the If...Then...Elseif …Else selection statement
If <condition > Then
statements
‘First Statement Block
Elseif <condition > Then
statements
‘Second Statement Block
Else
Statements
‘Third Statement Block
End If
4. Nested If statement : - Nested If statement means, if statement within if statement. First if
statement is called outer if statement and second is inner if statement. If outer if statement is true
then check inner if statement, but If outer if statement is false then doesn’t check inner if
statement.
Syntax of the Nested If statement
If < condition 1 > Then
If < condition 2 > Then
statements
Else
statements
End if
Else
If < condition 3 > Then
statements
Else
statements
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 109 of 120
End if
End If
5. IIF( ) statement : - IIF( ) statement means Immediate IF statement. Visual basic offers IIF( )
is a function that can be used as an alternative to simple If…Then….Else statement. Basically
this function is used to combines a single If…Then..Else statement in one line.
Syntax of the IIF ( ) statement
IIF (Condition, Expression1, Expression2)
6. Select...Case statement
Select case statement is used, when a single variable has multiple choices. In select case
statement we can gave multiple cases, if case will match then it will execute related block
otherwise default case will be executed. Select case statement is an alternative of the
If...Then...ElseIf statement. Select case statement is more convenient to use than the
If...Then...ElseIf statement. The variable used in select case statement is known as select case
variable. The variable in the select case statement can be integer or string type only.
In select case statement we use select, case and else keywords.
Syntax: Syntax of the Select...Case statement
Select
Case
<expression>
Case
value
Statements
Case
value
Statements
Case else
Statements
End Select
Q13. What is loop? Explain its types?
Ans There are many types of loops used in visual basic
1) For...Next Loop : - For…..Next loop is used to repeat the set of statements till a particular
condition is true but if condition is false then loop will stop work. For….Next loop is a fix loop,
because we knows in advance how many times the loop will be repeat. For….Next loop is a
single line loop, because initialization, condition and updation written in a single line. It’s also
known as entry control loop or top check loop. It means loop checks the condition first then it
executes the statement.
Syntax: For <counter_var>=<start_value> To <end value> step <increment /decrement value>
2. For Each…..Next Loop Statement : - For Each…… Loop is used to repeats a group of
statements. It is collection of object or is an array instead of repeating the statements is a
specified number of items. This is especially helpful if you don’t know how many elements are in
a collection or a dynamic array. For Each…… Loop used only variant variable.
Syntax: For Each element In group
[ statements ]
[ statements ]
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 110 of 120
Next [ element ]
3. Do While... Loop Statement : - Do While…..Loop is used to repeat the set of statements till
particular condition is true but if condition false then loop stop it’s works. It is a true loop. In Do
While….Loop initialization, condition and updation statements gave separate(different )lines in
the loop. It’s also known as entry control loop or top check loop. It means loop checks the
condition first then it execute the statements.
Syntax: Initialization
Do While condition
Statements
updation
Loop
4. Do Until...Loop Statement : - The Do Until.…. Loop statement is used to repeat the set of
statements till a particular condition is false if given condition is true then the loop will terminate.
It’s also known as false loop. It’s also known as entry control loop or top check loop.
Syntax: Initialization
Do until condition
Statements
updation
Loop
5. While... Wend Statement : - While…..Wend loop is used to repeat the set of statements till a
particular condition is true, if condition is false then loop will stop works. Same as Do
While….Loop. In While……Wend loop have three statements initialization, condition and
updation that written in separate (different) lines. It’s also known as entry control loop and top
check loop. The While…..Wend loop is an older statement pair from previous versions of BASIC
and was included in Visual Basic for compatibility. While…Wend loop can’t terminate using Exit
keyword and another hand Do While…..Loop can terminate using Exit keyword.
Syntax: Initialization
While condition
Statements
updation
Wend
Q14. What is menu how we can create menu and sub menu in visual basic?
Ans: menu is mostly used in all the application software. A list of commands or options from
which you can choose. Most applications now have a menu-driven component. You can choose
an item from the menu by highlighting it and then pressing the Enter or Return key, or by simply
pointing to the item with a mouse and clicking one of the mouse buttons.
The antithesis of a menu-driven program is a command-driven system, in which you must
explicitly enter the command you want rather than choose from a list of possible commands.
Menu-driven systems are simpler and easier to learn but are generally not as flexible as
command-driven systems, which lend themselves more naturally to interaction with programs.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 111 of 120
Steps to Create a Menu Through Menu Editor
1. Invoke the menu editor.
2. In the caption text box type & color.
3. In the name text box type mnucol.
4. Press next button.
5. Now press right arrow button to give one level indent.
6. Now type &red in the caption text box and mnured in the name text box.
7. Similarly type other color entries.
8. Press OK to save.
9. Now switch to code window and type the following code in the mnured_click ( ).
10.
Private Sub mnuRed_click ( )
11.
Form1.BackColor = VbRed
12.
End Sub
Similarly type the code for mnugreen and mnublue click ( ) events. Now run the application.
Q15. What is error define its types in visual basic?
Ans So far, the errors you have encountered in your programs have probably been simple typing
mistakes or syntax errors. But what if you discover a nastier problem in your program — one you
can’t find and correct by a simple review of the objects, properties, and statements in your
application? The Visual Basic development environment contains several tools you can use to
track down and fix errors (bugs) in your programs. These tools won’t stop you from making
mistakes, but they often can ease the pain when you encounter a mistake
Three Types of Errors : - As you develop Visual Basic programs, three types of errors can
produce unwanted results in your applications. These are described in the following topics:
1) Logic errors
2) Syntax errors
3) Run-time errors
Logic Errors : - A logic error is a human error — a programming mistake that makes the
program code produce the wrong results. Most debugging efforts focus on tracking down
programmer logic errors.
Consider the following If...Then decision structure, which evaluates two conditional expressions
and then displays one of two messages based on the result:
If Age > 13 And Age < 20 Then
Text2.Text = "You're a teenager."
Else
Text2.Text = "You're not a teenager."
End If
Can you spot the problem with this decision structure? A teenager is a person who is between
13 and 19 years old, inclusive, yet the structure fails to identify the person who is exactly 13. (For
this age, the structure incorrectly displays the message, “You’re not a teenager.”)
This type of mistake is not a syntax error (the statements follow the rules of Visual Basic); it is a
mental mistake, or logic error. The correct decision structure contains a greater than or equal to
operator (>=) in the first comparison after the If...Then statement:
If Age >= 13 And Age < 20 Then
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 112 of 120
Believe it or not, this type of mistake is the most common problem in Visual Basic programs. It's
a matter of code that works most of the time — but not all of the time — and it's the hardest
problem to track down and fix.
Syntax Errors : - A syntax error (compiler error) is a programming mistake that violates the rules
of Visual Basic, such as a misspelled property or keyword. As you type program statements,
Visual Basic points out several types of syntax errors — and you won’t be able to run your
program until you fix each one.
Runtime Errors : - A run-time error is any error — usually an outside event or an undiscovered
syntax error — that forces a program to stop running. Two examples of conditions that can
produce run-time errors are a misspelled file name in a
LoadPicture function and an open floppy drive.
Q16. What is pop up menu
Ans A pop-up menu is a floating menu that is displayed over a form, independent of the menu
bar. The items displayed on the pop-up menu depend on where the pointer was located when the
right mouse button was pressed; therefore, pop-up menus are also called context menus. In
Windows 9x, you activate menus by clicking the right mouse button.
To create a pop-up menu, you first need to define a menu throught the menu editor. To ensure
that this menu will not be displayed on the menu bar, you make it invisible, i.e.make sure that the
visible check box in the menu editor is not checked for this very menu.
Any menu that has at least one menu item can be displayed at run-time as a pop-up menu. To
display a pop-up menu, use the PopupMenu method.
This method uses the following syntax:
PopupMenu <menuname>
For Example, the following code displays a menu name mnuFile when the user clicks a form with
the right mouse button.You can use the MouseUp or MouseDown events to detect when the user
clicks the right mouse button:
Private Sub Form_MouseUp (Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then ‘Button=2 indicate the right mouse button is clicked.
PopupMenu mnuFile
End If
End Sub
This example shows you how to create a pop-up menu (sometimes called a context menu or a
right-click menu).
Q17. What is COM and also its advantages
Ans Component Object model is a technology that allows programmers to create user-defined
components as distinct objects, to be used in various applications and development tools. Com
determined the binary standard for an executable file that can be used for integration with other
objects and remote object invocation. Microsoft COM (Component Object Model) technology in
the Microsoft Windows-family of Operating Systems enables software components to
communicate. COM is used by developers to create re-usable software components, link
components together to build applications, and take advantage of Windows services. COM
objects can be created with a variety of programming languages. Object-oriented languages,
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 113 of 120
such as C++, provide programming mechanisms that simplify the implementation of COM
objects. The family of COM technologies includes COM+, Distributed COM (DCOM) and ActiveX
Controls.
BENFITS OF COM : - COM is a technology to create binary executables tha allow the
programmers to reuse.
The components defined for one application into another. Following benefits are provided
by the comp component
Programming Languages : - The COM components can be built using various programming
languages such as C, C++ and Small talk. So the component produced in one languge can easily
deployed and integrated with other languages.
Reusability Concept : - Once the component is written it can be used in numbers of application.
COM component provide Code reusability concept so they can used in numbers of applications.
After created once. Backward Compatibility
All types of COM components generally support Query Interface requests. Query
interface also allows the programmers to create new interfaces with additional functionality. The
new interfaces developed by the Queryinterface are made backward copatible with existing comp
components.
Maintain Version Consistancy : - COM components also provide the version consitancy. When
any version of the com component is created. Prorgrammers keep track the older versions of the
same components and make the backward compatibility. This approach solves the problem of
multiple versions for the COM components.
Q18. Explain ActiveX control in visual basic
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-defined controls to perform
manipulation on various data types in their application. ActiveX components are saved as .exe,
.dll or .ocx files.
An ActiveX control can be created in any programming language that recognizes Microsoft's
Component Object Model. The distributed support for COM is called the Distributed Component
Object Model (DCOM). In implementation, an ActiveX control is a dynamic link library (DLL)
module. An ActiveX control runs in what is known as a container, an application program that
uses the Component Object Model program interfaces
Type of ActiveX Components
ActiveX EXE : These components are used to create applications that can be deployed on outprocess server architecture. The file extension for these files is .EXE. The ActiveX Exe files run
in their own addres space making communication between the separate processes a bit slow.
ActiveX DLL
The components are used to create applications that can be deployed on in-process server
architecture. The file extension for these files is .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
inercommunication between the process.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 114 of 120
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 requires cabinet
(CAB) files for proper deployment of the control on the client machine.
ActiveX Document EXE : These components are used to create controls fo 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 also used to create components for web
based application like ActiveX document EXE. In contrast to the ActiveX Document Exe, these
files require container files that can call the dll files to execute the required functionality.
Q19. JET DATABASE ENGIN AND DATA CONTOL
Ans The Microsoft Jet Database Engine provides the means by which VB interacts with
databases. But the Jet databases engine is relatively transparent because VB provides various
Data Controls to work with database.
Data Controls These are the controls which provide data connectivity of VB Jet Engine with
various databases. The actual connectivity however remains transparent as we use only the data
controls.The data controls are a link between the information in the database and the data bound
control that lets you display the information. Their properties let you decide which database and
what part of it to access.
Data Bound Controls These are the controls which respond to the data controls. They display
the records fetched by the data control from the database.
Text Box Control
Combo Box Control
List Box Control
MS Flex Grid Control
Data Grid Control
DataListControls
(Intrinsic)
(Intrinsic)
(Intrinsic)
(Extrinsic)
(Extrinsic)
(Extrinsic)
Q20. Database Connectivity.
Ans A database is a centralised collection of related information.
The key parts of a database are as under :Database - A group of data tables that contain related information. For e.g.-FoxPro.
Table - A group of data records each containing same type of information. For e g.-Student.dbf.
Record- A physical line in a data table each consisting of a number of data fields.
Field - A column name each containing same type of data.
Query - A command designed to retrieve a certain group of records from a table or a group of
tables.
Recordset - A group of records created by a quarry.
To Link up front end application with database VB provide numbers of techniques.
These are categorized into the following category.
1. DAO
2. RDO
3. ADO
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 115 of 120
1. DAO stands for Data Access Object. This is the older technique to link front end application
with backend database in vb. The Default control for data connectivity is available with DAO. With
the help DAO we can connect access 97 , excel , dbase3 etc.
2. RDO stands for Remote Data object used to connect front end application that is available on
different computer can connect with server to access data remotedly.
RDO helps to make remote application can only connect client / server application.
3. ADO stands for ActiveX Data Object this is the newest technique to connect front end
application with back end database. ADO provide two method to connect database 1. Active Data
Control and ActiveX Data Object Library.
Q21. Explain string function
Ans STRING FUNCTIONS
Asc ( ) - It returns the character code corresponding to the first letter in the string.
For e.g
Text1.text=”a”
Text2.text=Asc(Text1.text)
The output will be - 97
Instr ( ) - It returns the position of first occurrence of a string within another.
For e.g. :
Text1.text=”QuickBasic was Visual Basic’s ancestor”
Text2.text=Instr(1,text1.text,Basic”)
The output will be - 6
StrRevers ( ) - It returns the reverse of a string.
For e.g.
Text1. Text = “hello”
Text2.text = StrReverse (text1.text)
Output - olleh
Len ( ) - It returns the number of characters in a string.
For e.g.
Text1, text = “hello”
Text2.text= Len (text1.text)
Output -5
LCase ( ) - Converts a string to lower case
For e.g.
Text1.text = “HELLO”
Text2.text= Lcase (text1.text)
Output - hello
Ucase ( ) - Converts a string to upper case
For e.g.
Text1.text = “hello”
Text2.text = Ucase (text1.text)
Output - HELLO
Left ( ) - Removes specified number of characters from beginning of a string
For e.g.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 116 of 120
Text1.text = “hello”
Text2.text = Left (text1.text,3)
Output - hel
Right ( ) - Removes specified number of character from the end of a string
For e.g.
Text1.text = “Hello”
Text2.text = Right (text1.Text,2)
Output - LO
Mid ( ) - Removes specified characters from middle of a string.
For e.g.
Text1.text = “Visual Basic”
Text2.text=Mid (text1.text,8,5)
Output - Basic
Q22. how to create a setup of any project
Ans To create the distributable package, you can use the Package and Development Wizard that
came with Visual Basic 6. The main purpose of this wizard is to create a setup program that can
be used to install the application. Off course, it also does many other jobs like compiling your
application and compresses the files for easy distribution
Following steps are used to package that can deploy on any computer
1. Select Microsoft Visual Studio 6.0 from start-> program option
2. Now Select Microsoft visual studio 6.0 tool option
3. Now select package and deployment wizard
4 Now select the project using browse button in project and deployment wizard
5 Now click on package option to create package
6 Select standard exe package
7 Click on next and choose the package folder where you want to assemble the package
8 click on Next
9 Choose Add button to add database or additional files for your project
10 Click on next and choose whether package in single cab or multiple cab file and click on next
11 Then specify the title to the project click on next
12 Specify the shared for the project
13 Now specify the setup script name
14 And click on finish button to finish the wizard now you setup is ready for deployed
When you click the Finish button, the package will be created and ready for distribution. Here
are the packaged files for the start program for download at Setup.exe
SETUP.LST You must download all files into a folder and then run the setup program.
Q23. What are various control structures in VB? Give their syntax.
Ans. Select Control structure
(v.imp)
Control structure is 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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 117 of 120
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 Command Button 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"
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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 118 of 120
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
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 119 of 120
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
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
statement block.
by an Exit For statement . Consider the following
For I= to 100
Text1.Text =Str (I)
If 1=50 Then
Exit for
End if
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
SUBJECT: ‘VB’ (PGDCA - 2)
Page 120 of 120
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.
Prepared By: - Vaishnoo Maa Computers, SCO 145, Chotti Baradari, Patiala.
Ph. 0175-2205100, 2215100
Download