Sei sulla pagina 1di 4

TYBSC (IT) Visual Basic

Chapter 1. Introduction to Visual Basic


Q1. What are objects and properties? How are they related to each other? (4 mrks )
Ans:
Objects:
Think of objects as a thing, or a noun. Examples of objects are forms and controls.
Forms are the windows and dialog boxes you place on the screen; controls are the elements
that you place inside a form, such as text boxes, command buttons, and list boxes.
Properties:
Properties tell something about an object, such as name, color, size, location, or how it will
behave. You can think of properties as adjectives that describes objects.
When you refer to a property, you must first name the object, add a period, and then name
the property. For example, refer to caption property of form called Form1 as Form1.Caption (say
Form1.Caption).
Q2. What are the three steps for planning and creating Visual Basic project? Describe
what happens in each step. ( 6 mrks )
Ans:
To write a Visual Basic project you follow the three step process for creating the project and
then repeat the project for creating the project. The three step involves setting up user interface,
defining the properties, and creating code.
The Three-Step Process as follows:
Planning:
Design the user interface: When you plan the user interface, you draw a sketch of screens the
user will see when running your project. On your sketch, show the forms and all the controls that
you plan to see. Indicate the name that you planed to give the form and each of objects on the
form.
Plan the properties: For each object, write down properties that you plan to set or change during
the design of the form.
Plan the basic code: This step is where you plan procedures that will execute when your project
runs. You will determine which events require action to be taken and then make a step-by-step
plan for those actions
Programming:
After you have completed the planning steps and have agreement form your user, you
are ready to begin the actual construction of the project. You will use the same three steps
process that you used for planning.
Define the user interface: When you define the user interface, you create the forms and controls
that you designed in planning stage.
Set the properties: When you set the properties of objects, you give each object name and
define such attributes as the contents of the label, the size of text, and the words that appear on
the top of command button and in the forms title bar.
Write the Basic Code: You will use Basic programming statements to carry out the actions
needed by your program. You will be surprised and pleased by how few statements you need to
create powerful Windows program.
Q3. What is the purpose of Visual Basic file types: .vbp, .frm, .bas, and .ocx?
Ans:
Visual Project consist of at least two, and usually more, files as follows:
.vbp file: This file is called the project file, is a small text file that holds the names of the other
files in the project, as well as some information about the VB environment.
.frm file: Each of your form in the project is saved in a file with extension. To begin your project
your project will have only one form. Later you can expect your projects to have several forms,

TYBSC (IT) Visual Basic

with one .frm file for each form. A from holds the description of all objects and their properties
for each form, as well as the basic code that you have written to respond to the events. These
are also referred as form modules.
.bas file: Optionally your project can have this file. These file holds basic statements that can
be accessed from any form. As soon as you begin .bas file are called standard code modules.
.ocx file: additional controls, called custom controls, are stored with a file .ocx extension. If you
include controls in your projects that are not part of the standard control set, the .ocx file names
will be included in the project.
.vbw file: After you save a project, Visual Basic automatically adds one more file to your project
with extension of .vbw. This file holds information about each projects form.
Q4. When is Visual Basic in design time? Run time? Break time?
Ans:
Visual Basic has three distinct modes.
While you are designing the user interface and writing code, you are in design time.
When you are testing and running project, you are in run time.
If you get an error or pause project execution, you are in break time
Q5. What is purpose of name property of control? ( 4 mrks )
Ans:
Every control has its properties one of the common properties of controls is name property.
Name property is the one by which the control is identified and it is referred as the object name
of that control.
By using name property programmer can access the other properties of the controls and
methods as well at run time.
Visual Basic gives default name to the controls which can be later changed by changing its
name property at the design time or urn time.
Q6. Which property determines what appears on the form for Label control.
Ans:
Caption property of the Label control determines what will appear on the Label control.
This Caption property is changed at run time or design time.
Use can not change the Caption property of the Label control.
Q7. What is the purpose of the Caption property of the Command button? And Caption
property of the Form?
Ans:
Command button has a Caption property which is used to display a text on the top of Command
Button.
Form object also has the Caption property. This property displays the Caption text at the title bar
of the window.
This property can be changed run time or design time. But it cant be changed directly by the
end user.
Q8. What does cmdPush_Click() mean? To what does cmbPush refer? To what does
Click refer?
Ans:
Visual Basic is event driven programming language. Over here cmdPush_Click() is a event
procedure, which belongs to cmdPush command button object.
Visual Basic automatically names your event procedures. The name consist of the object name,
an underscore(_), and the name of event. For example: the click event of command button

TYBSC (IT) Visual Basic

called cmdPush will be cmdPush_Click().


This procedure will be executed when ever Click event of the cmdPush command button is
fired.
When you will click on the cmdPush command button at the run time the statements with in the
cmdPush_Click() event procedure will be executed.
Q9. What is Visual Basic Event? Give some examples of events.
Ans:
While your project is running, the user can do many things, such as move mouse around; click
on either button; move, resize or close your forms window; or jump to another application. Each
action by the user causes an event to occur in your Visual Basic Project.
Some events you care about, and some events you dont care about. If you write Basic code for
particular event, then Visual Basic will respond to the event automatically execute your
procedure. VB ignores events for which no procedures are written.
Visual Basic automatically names your event procedures. The name consist of the object name,
an underscore(_), and the name of event. For example: the click event of command button
called cmdPush will be cmdPush_Click().
Q10. What property must be set to center text in Label control? What should be the value
of property?
Ans:
Visual Basic Label control has several properties. One of the property is Alignment property
which determine the alignment of the text display on the Label control that is Caption of Label.
You can set 1 of 3 values for alignment property of Label. If value of Alignment property is 0-Left
Justified then Caption of Label will be aligned left. If it is 1-Right Justified then Caption of Label
will be arranged to Right or you can set value to 2-Center will align the Caption to center of
Label control.
Q11. What is declaration section of the form module? What belongs there? ( 4 mrks )
Ans:
Good documentation guidelines require some more remarks in project. Always begin each
procedure with remarks that tell purpose of procedures. In addition, each project file needs
identifying remarks at the top. The General section declaration section is good location for these
remarks.
Code window may appear with or without Option Explicit statement at the top. To give remarks
you can move the insertion point up to the blank and type following remarks
Hello world project
by your name
todays date
Q12. What is compile error, when does it occur, and what might it cause it?
Ans:
Visual Basic convert your project to machine language, it finds any compile errors. You get
compile errors when you break the syntax rules of Basic and sometimes when use an illegal
object or property.
For example, try spelling End as end or using the world Quit instead of End. The compiler can
only translate the seat spelling of the world and cannot recognize either of these words both
cause the compile time error message box.
You also receive compile error if you accidentally use the wrong punctuation or place the
punctuation in the wrong place. The compiler cannot understand lblMessage,Caption or
lblMessage.Caption;

TYBSC (IT) Visual Basic

The editor might find compile errors as you move of offending line. Or the compile error may not
be found until you try to run the project. Before Visual Basic can actually run your project, it
attempts compile the code into machine language. If VB finds compile errors, it displays Code
window, highlights the offending line, and enters break time.
After you have corrected your compile errors, you can click on run button to continue the
compilation and running project.
Q13. What is run time error, when does it occur, and what might it cause it?
Ans:
If your project halts during execution, thats a run-time error. Visual Basic displays a dialog box,
goes into break time, and highlights the statement causing.
The statement that cannot be executed correctly cause run-time errors. The statements are
correctly formed Basic statement fail to execute.
Run time error can be caused by attempting to do impossible
arithmetic operation such as calculate with non-numeric data, divide by zero, or find the square
root of negative number.
Q14. What is logical error, when does it occur, and what might it cause it?
Ans:
With logical errors your projects runs but produces incorrect results. Perhaps the result of a
calculation are incorrect or the wrong text is OK but appears in wrong location.
If the project runs, it must be right-right? All too often, that statement is not correct. You may
need to use calculator to check the output. Check all aspects of the project.
For example, the you want to print hello world but you are giving some incorrect message at the
wrong place it will not give out put as you expected and it causes the logical error to solve these
kinds of errors you must check the code carefully.
Q15. Tell the class of control and the likely purpose of these object names:
Ans:
(a) lblAddress:
lblAddress is object of Label control class which is named as lblAddress. It is used to
display text on to the Label control.
(b) cmdExit:
cmdExit is object of Command Button control which is named as cmdExit. It is used
when you want user to perform some action.
(c) txtName:
txtName is object of TextBox control which is named as txtName. It is used to take
inputs from the user.
(d) optTextBlue:
optTextBlueis object of Option button control class which is named as optTextBlue and it
is used to user to select one option from several options.
Q16. When does context-sensitive help mean? How can you use it to see the Help page
for a command button? ( 6 mrks )
Ans:
A quick way to view Help on any topic is to use context-sensitive Help.
Select a VB project, such as form or control, or place the insertion point in word in the editor,
and press F1. The MSDN library viewer will open on correct page, if possible, saving your
search.
If you want need a help about command button just place the cursor on the command button
and press F1 key. This will open page with command button help page from MSDN library.

Potrebbero piacerti anche