VB Important questions,2marks

115
Page 1 What is vb? Vb is a user friendly event driven and partly objected oriented programming language using which we can develop: a. Database application. b. Web enabled application. c. And variety of other window based application. Who developed vb? Vb is developed by Microsoft in 1991 as Visual Basic 1.0. Why vb was developed? Before vb window based application was being done using c and window based compiler which was a slow and tedious process. It required lots of coding. To speed up development of window based application vc++ and Microsoft foundation class were developed. But the development process was still tedious and slow. To boost development of window based application easily and fastly vb was introduced. What are the different editions of vb? There are three editions of vb:- 1. Standard or learning edition: contains basic language feature and tools. 2. Professional edition: contains more feature and tools when compared to standard edition. 3. Enterprise edition: contains most advance feature and tools. The edition which we are using is enterprise edition. What are the hardware requirements to use vb?

description

VB Important questions

Transcript of VB Important questions,2marks

Page 1

What is vb?Vb is a user friendly event driven and partly objected oriented programming language using which we can develop:a. Database application.b. Web enabled application.c. And variety of other window based application.

Who developed vb?Vb is developed by Microsoft in 1991 as Visual Basic 1.0.

Why vb was developed?Before vb window based application was being done using c and window based compiler which was a slow and tedious process. It required lots of coding. To speed up development of window based application vc++ and Microsoft foundation class were developed. But the development process was still tedious and slow. To boost development of window based application easily and fastly vb was introduced.

What are the different editions of vb?There are three editions of vb:-1. Standard or learning edition: contains basic language feature and tools.2. Professional edition: contains more feature and tools when compared to standard edition.3. Enterprise edition: contains most advance feature and tools.

The edition which we are using is enterprise edition.

What are the hardware requirements to use vb?The hardware requirements are as follows:a. cd-rom driveb. CD-ROM (1 to 7 cds). First cd rom contains compilers for various languages like vb, vc++, visual FoxPro; visual internet developer etc. remaining cds contains help, client server tools, samples etc.c. Windows 9x Os.d. 80 to 120 mb for installation of vb.e. 40 mb free hard disk space for user generated program.f. 16 mb ram minimum ( 32 mb ram recommended)g. 80486 based micro processor ( Pentium 166 MHz recommended)

What is Event Driven programming?

Page 2

When a program consists of one or more than one event procedures and those procedures accomplish the task to be done by program it is know as event driven programming.

What is event?Event is any action performed by either user or performed by program itself. For example mouse-click, key press, window resize etc.

What are the difference between structured/procedure oriented and event driven programming?

Structured/Procedure Oriented Event Driven Programming

Program consists of one or more procedure.

Program consists of one or more event procedure.

Programming task is completed by procedure.

Programming task is completed by event procedure.

The order of execution of procedure is more or less predictable.

The order of execution of event procedure depends on user performed action.

Procedure oriented programming is not suitable for window based application.

Event driven programming is suitable for window based application.

What do you mean by IDE?Ide stands for integrated development environment. It is collection of program allowing composing and editing the program, testing the program, running the program and debugging the program.

Describe working environment of vb?Working environment of vb is composed of many elements:1. title bar: where program title, project name and program mode is displayed2. Menu bar: contains menu and related commands.3. Tool bar: consists of icons which are short cuts to frequently used commands some toolbars are: standard, formatting etc.

Page 3

4. Toolbox: on the left side toolbox appears which contains controls.5. Form designer: appears in middle where graphical user interface element (controls) is placed.6. Properties window: using this we can set properties of controls.7. project explorer window: displays files which make up the project8. Form layout window: displays form-icon used to set start up position of form.9. Immediate window: useful to test any statement or to print value of variable.

What are the different modes of vb program?There are three modes of vb program:a. design: ( when designing form and writing code)b. Run: when a program is running.c. Break: when any occurred in program.

What is project file? Why it is needed?Project file contains information about all those file which make the project. it stores location of individual file with path. When saving project it saves all files one by one inside project. When we open project it automatically opens all files which are part of project we need not to open each file one by one thus saving time. Project file has extension “vbp”.

What is executable file? How it is made?To make executable file (exe) we have to go to file menu and have to select make exe.Copying of exe file to another computer and running the exe file does not guarantee that the executable file will run there because a window based program depends on many different file. it better to run distributable package using package and deployment wizard.

What is module?Module is collection of procedures and functions corresponding to a file in disk will generate. Benefits are:a. It provides code reusability and stability.b. Avoids code repetition.c. Testing and debugging becomes easier.Type of module:a. Form module: normally contains event procedures, other procedure and function which will be used inside the same form module. extension is

Page 4

.frmb. Basic module: normally contains global variables, procedure and function which can be accessed across other modules. extension is .basc. Class module: contains definition of class, member function and properties. extension is .cls

How to use code editor window?Code editor window can be brought forward using either of these methods:1. select view-> view code2. right click on form and select view code3. Double click on any control or on double click on form.4. From project explorer window select the form name and click on button view code.navigation of code editor window:control+left arrow : move one word leftcontrol+right arrow : move one word rightcontrol +home : move to beginning of code viewcontrol +end : move to end of code viewhome : move to beginning of lineend : move to end of linecontrol+up arrow : move one procedure upcontrol+down arrow : move one procedure downshift+f2: view definition of function or procedure under cursorcontrol+shift+f2: go to last position of cursor

What is documentation? Why it is needed?Documentation of code is very necessary. Using documentation we can increase readability of our program. Using documentation we can store addition information like:a. date and time of program b. version no. of programc. company for which it was createdd. author of the codee. variables used and purposef. algorithm of programg. explanation of statementDocumentation makes the program easily under stable. In future if we are going to make modification in program it will help greatly. We use ‘(apostrophe) to write comments or rem keyword.

Page 5

How formatting of code is done?Formatting of code make program easy to read. Indentation makes easy to follow closing of control structure. different background and foreground colors, fonts, font size can be assigned to normal text, keywords etc. using tool->options->editor format tab. procedure separator line can also be turned on to help to identify where one procedure is beginning and ending.

Describe environment options in vb?Select tools->options->environment taba. under when visual basic starts

if option button selected is prompt for project: each time visual basic starts a dialog box appears which lets us select type of project.if option button selected create default project: each time visual basic starts it automatically open standard exe project.

b. under a program starts:if save changes: is selected when program is about to start it saves the changes made in project.if selected prompt to save changes: is selected when program is about to start it will ask to save the changes.if selected don’t save changes: it will not save the changes made in project and will run program.

c. Show templates for: we can have many templates available for use as starting point for form, mdi forms, modules etc.

Describe editor options.Select tools->options->editor tab.1. Auto syntax check: if checked, when writing a statement and pressing enter check the statement for error.2. Require variable declaration: puts ‘option explicit’ statement in module’s general declaration section which forces declaration of variable before use as in c-language.3. Auto list member: if checked gives popup list consisting of properties, methods supported by object. 4. Auto quick info. if checked gives information about function parameter and data type of parameter which current function will work on.5. Auto data tips: if checked gives list of constant which can be assigned to a variable or to parameter of a procedure or function?

Dim b as BooleanType b= then you will get true, false in a list

6. Auto indent: if checked starts new line just below the previous line.

Page 6

7. Tab width: specify the amount of space generated by a tab key.8. Drag and drop text editing: if checked supports drag and drop in code editor window.9. Default to full module view: if not checked only one procedure will be visible at a time.10. Procedure separator: if checked draws line among procedures.

Describe automatic code completion feature of vb.When we have to use any object property or any method of object we have to type just a few letter of that property or method as soon as the property or method is selected from popup list we can press control space key combination to complete the whole property or method thus saving key stroke.

What is Object?Object is class variable which is composition of properties, methods and data member. Object is fundamental requirement of any object oriented language. Object has three characteristics:

1. State: state of any object defines identity of object.2. Behavior: behavior of any object is decided by member functions (methods) to which object can respond.3. Method: it is also known as member function it performs computation on data member or any kind of action.

What is property?Property of any object is actually member procedure which allows to set value in data member (working as mutator) or allows to retrieve value of data member ( working as accessory).

How to create program in vb?Steps are as follows:

1. First decide the controls which will be used to create graphical user interface.2. set properties of controls3. Write event procedure coding.

How to get print of visual basic program.1. save the project2. select file->print3. from the dialog box specify:

Page 7

Under range:a. selection – to print selected code b. current module- to print current modulec. current project- to print all modules in current project

Under print what:a. Form image- to print the image of form.b. code- to print codec. form as text- to print form as text format , resulting of printing of controls along with properties and code

Under setup, specify paper size, orientation of paper and printer to use

Describe controlling objects. Or describe toolbox.Control depends on interfaces which are properties, events and methods.

Normally there are many controls found in visual basic. Some controls are activex controls which can be included in toolbox using project->component dialog. There is some control already available in toolbox which is also known as intrinsic controls or standard controls. Descriptions of standard controls are as follows:

a. Label control: it is useful to give user a prompt.b. Text box: it is useful to input/output data for program.c. List box: it is useful to give list of items and user can select items from list.d. Combo box: it is combination of text box and list box user can type new item or can select an existing item from combo box list portion.e. image box: can display picturef. Picture box: can display picture.g. directory , drive and file list box: allows to create a dialog box to save , open fileh. Ole control: allows using feature of other existing application.i. data control: useful to write data base programj. Option button or radio button: allows selecting only one of several available choices.k. Check box: allows selecting many choices of several available choices.l. Frame: acts as container to place related controls together.m. Command button or push button: useful to confirm action like close, open, apply etc.n. Timer: useful to execute certain piece of code after specified interval.

Page 8

Default property is enabled which takes true or false value.o. shape: useful to decorate formp. line : useful to draw line to decorate formq. Scrollbar: useful to take input/output or scrolling data.

What is variable?Variable is name given to computer memory location where we can store value and retrieve the stored value by name.Variable is fundamental requirement of any programming language.Rule of naming variable or identifier:

1. Variable name must start with alphabet.2. Later on digits can be used, under score can also appear.3. variable name is not case sensitive4. only a-z, 0-9 and _ can appear in variable Name5. Space and special are not allowed.6. variable name must not match with keyword7. we can have variable name 255 characters long8. name of control must not exceed 40 characters

What is data type?Data type of variable defines range, memory and valid operation for a variable

Data type Range Memory

1.Byte 0 , 255 1

2.Integer % 32767 , 0 , -32768 2

3. Single! +/- 3.4 e +34 4

4.Double # +/- 1.7 e+308 8

5.Date 1-1-100 to 31-12-9999 8

6.string(variable) $ 2 billion characters

6.string(fixed) $

7.boolean True, false 2

Page 9

8.object Reference of any object

9. variant Range for number is same as double

Range for string is same as 2 billion characters

How to declare variable?(a) Dim x as integer, y as integerOrDim x%, y%(b) Dim x, y as integerThen x will be variant and y will be integer(c) Dim b as Boolean

Describe scope of variable.Scope specifies the code range where value of variable is accessible.

a. Local variable: accessible inside a function or procedure. we use dim keyword to declare local variable.b. Module level global variable: accessible inside a module but not outside from other module. We use dim or private keyword to declare module level global variable and declare it inside general declaration of module.c. Global variable: accessible from every where. We use public or global keyword to declare global variable inside general declaration of module.

What do you mean by shadowing of variable?if global variable or module level global variable exists with name ‘a’ and a local variable also exists in a procedure or function it prevents accessing of global or module level global variable because local variable is given preference. to access value of global variable we can useModule name .global variable e.g. form1.a

What are the operators in vb?1. arithmetic operator:

+ for addition,

Page 10

- for subtraction.* for multiplication\ for integer division c=10\3 c will be 3/ for float division c= 10/3 c will be 3.333^ for power e.g. c=10^3 therefore c will be 1000mod for modulo division c=10 mod 3 c will be 1

2. relation operator >,>=,<,<=,=, <>3. logical operatorand, or, not

3. assignment=

Why do we need control structure?We all need to alter our action depending on changing circumstances. For example If weather is fine I will go Dongargarh on bike otherwise I will go by train. In the same way ‘vb’ language too must be able to perform different action under one condition and different action under another condition and this is made possible by control structure. Sometimes a given set of statements are needed to run repeatedly this is done using loop control structure.

Write notes on if control structure./ explain branching structure in vb./ write short notes on if statement/ write short note on select case.. End select.The general form of if statement is:(A) if-endif statementThe general format of if statement is If (condition is true) then Execute this statement End if

The keyword if tells the compiler that what follows, is a decision control instruction. The condition following the keyword if is optionally enclosed within a pair of parentheses. If the condition, whatever it is, is true, then the statement is executed. If the condition is not true then the statement is not executed; instead the program skips past it.(b) If –else-endif statement If statement by itself can execute only one statement if condition is true. If it required running a group of statements when condition is true we have

Page 11

to enclose those statements inside curly brace known as compound statement. The above form of if statement mentioned in (a) will not do anything when condition is false. If we want to run statement when condition is false we need if-else construct.General format of if-else construct isIf (condition is true) then Execute this statementElse Execute this statement if condition is falseEnd ifCondition is specified using relational operator x= y means x is equal to y.x<>y means x is not equal to y.x< y means x is less than y.x>y means x is greater than y.x<=y means x is less than or equal to y.x>=y means x is greater than or equal to y

What is the use of logical operator? what is meant by logical testing?Logical operator and, or, not are useful to join more than one condition whereas not operator negates meaning of condition. These are required in following situations:* When it is be tested whether a value falls within a particular range or not.* When after testing several conditions the outcome is either true or false.* Reverse the logic of condition using ‘not’ logical operator.Control structures mostly depend on logical testing to perform some piece of code either selectively or repeatedly.

What are the different forms of if –else statements?Different forms of if-else statement are as follows:

1. if (condition) then do this and this end if 2. if (condition) then do this do this else do this

Page 12

do this end if

3. if (condition) then single-true statement4. if (condition) then single-true statement else single-false-statement5. if (condition) then if (condition) then statement else statement end ifelseif (condition) then statementselse statementsend ifend if

5. if condition then statements

elseif condition then statementselseif condition then statementselse statementsend if

program to find division given percentagePrivate Sub Command1_Click ()Dim a!, b$a = Text1.TextIf a < 33 Then b = "fail"Else If a < 45 Then b = "third" Else If a < 60 Then b = "second"

Page 13

Else b = "first" End If End IfEnd IfText2 = bEnd Sub

place label : having caption enter percentageplace text1: having text property clearedplace label2 : having caption divisionplace text2: having text property clearedplace command1: having caption find division

program to check leap yearPrivate Sub Command1_Click()Dim a%a = Text1If a Mod 100 = 0 Then If a Mod 400 = 0 Then Text2 = "leap" Else Text2 = "not leap" End Ifelse If a Mod 4 = 0 Then Text2 = "leap" Else Text2 = "not leap" End IfEnd IfEnd SubPlace label: having caption enter yearPlace text1: having text property clearedPlace label2: having caption result of testingPlace text2: having text property clearedPlace command1: having caption check for leap year

Program to print message teenage, child, old etc. according to given age

Page 14

Private Sub Command1_Click ()Dim a!a = Text1Select Case (a) Case Is <= 8 Text2 = "child" Case 9 To 14 Text2 = "teenager" Case 15 To 20 Text2 = "young" Case 21 To 28 Text2 = "adult" Case Is > 28 Text2 = "old"End SelectEnd SubPlace label: having caption enter agePlace text1: having text property clearedPlace label2: having caption statePlace text2: having text property clearedPlace command1: having caption check age

State the difference between select case and if select-case

1. All programs made using select-case can be solved using if. Select case takes different action depending on value of a single variable.

2. ‘select-case’ leads to more structured programming and level of indentation is manageable even if we have nested select-case.

if-else

All programs made by ‘if’ are not possible to solve by ‘select-case’.

‘if’ leads to less structured

Programming and level of indentation is difficult to manage if using nested ‘ifs’.

Multiple if

1. Multiple ‘if. Else’ contains more

Nested if. else

1. Nested ‘if. Else’ contains more

Page 15

than one end if. Each ‘end if’ corresponds to each ‘if’.

2. Multiple if requires more comparison. Therefore it is not efficient.

than one ‘else if’ but just one ‘end if’..

2. Nested if requires less comparison. Therefore it is efficient.

Write short notes on go to statement and its limitations.‘Goto’ is a statement which is quite common in monolithic programming paradigm. Some languages like basic, FORTRAN etc. use it deliberately. Using go to we can do:1. Skipping of some statement without executing them.2. Transferring of control to a labeled statement.3. Coming out of loop whatever level of nesting of loop may be. Note that break statement can take out of loop inside which it lies but goto statement can take out of loops irrespective of level of nesting of loops.Different type of goto can be:a. Conditional-goto: if it is used with ‘if’ statement.b. Unconditional-goto: if it is not used with ‘if’ statement.Limitations of goto: unwise use of goto make it difficult to trace logic flow of program and makes it difficult to remove logical error of program therefore, as far as possible, we must avoid use of goto.Program to print 1 to 10 using goto statementPrivate Sub Command1_Click ()Dim a%, b%, c%, t$a = Text1b = Text2c = Text3mm: t = t & a & " "a = a + cIf a <= b Then Go To mmText4 = tEnd SubPlace label1: having caption enter starting termPlace text1: having text property clearedPlace label2: having caption enter stopping termPlace text2: having text property clearedPlace label3: having caption enter value to step byPlace text3: having text property cleared

Page 16

Place text4: having text property clearedPlace command1: having caption print series in text box

Why loop control structure is needed?Without loops we execute the same series of actions, in the same way, exactly once. Loops allows to execute same portion of program code repeatedly a specified no. of times or until a particular condition is being satisfied. This repetitive operation is done through a loop control structure.There are four methods using which we can repeat a part of a program which are:* For statement* while statement* do-while statement* Goto statement (not recommended)

Write short notes on ‘while’ (entry level control structure/test and do) loop.In programming we require to execute same set of instructions a fixed number of times. E.g. we want to calculate gross salary of ten different persons; we want to convert temperatures from centigrade to Fahrenheit for 15 different cities. The ‘while’ loop is suited for this.‘Program to print 1 to 10 on formPrivate sub command1_click ()Dim a%a=1Do while a<=10 print aa=a+1loopend subGeneral format is 1. initialize loop counter do while(condition is true) do this; increment loop counter; loop

Page 17

Write short notes on ‘while’ (entry level control structure/test and do) loop.In programming we require to execute same set of instructions a fixed number of times. E.g. we want to calculate gross salary of ten different persons; we want to convert temperatures from centigrade to Fahrenheit for 15 different cities. The ‘while’ loop is suited for this.‘Program to print 1 to 10 on form

Private sub command1_click ()Dim a%a=1do print aa=a+1loop while a<=10end subGeneral format is initialize loop counter do do this increment loop counter loop while(condition is true) Differentiate between while/while. Wend and do-while loop.Body of loop in case of ‘while’ loop will not execute even once if condition of while loop is false but in case of ‘do-while’ loop body of loop will run at least once because condition is tested at the end of loop body. Format of do. Loop is initialize loop counter do do this increment loop counter loop while(condition is true)

format of while loop: initialize loop counter while condition do this increment loop counter loop

Page 18

format of while.. wend loop: initialize loop counter while condition do this increment loop counter wend

Do while loop must test a condition that will eventually become false, otherwise the loop would be executed forever, indefinitely known as infinite or indefinite loop.While loop or while. Wend loop test condition and if condition is true then statements are executed if condition is false statements are not executed even once.Do.. While loop test condition later therefore if condition is false statements are executed at least once.While. Wend statement can not use ‘exit do’ statement to come out of loop whereas do. While and do. Loop…while can use ‘exit do’ statement to come out of loop.

Write short notes on for loop.‘For’ loop is most popular loop. ‘For’ loop allows us to specify three things about a loop in a single line which are:1. Setting a loop counter to initial value.2. Testing the loop counter to determine whether its value has reached the number of repetitions desired.3. Increasing the value of loop counter each time the program segment within the loop have been executed.The general format of for statement is as us under:for variable= intialvalue to end value step step value

do this and this and thisnext

Write short notes on odd loop.The loops in which no. of times statements inside loop body will execute are known as finite or determinate loop. The loops which will never terminate execution of statements inside loop body are known as infinite loop. The

Page 19

loop about which we are not certain how many times statements inside loop body will execute but we are sure that it will terminate after some time is known as odd loop.

Write program to demonstrate loops to solve Fibonacci series up to n terms.Private Sub Command1_Click ()Dim i%, term1&, term2&, term3&, t$, n termsterm1 = 0term2 = 1Terms = Text1

' method A- using for loop‘For i = 1 to n terms't = t & term1 & " "'term3 = term1 + term2'term1 = term2'term2 = term3'Next

‘method B-using do-while…loop'i = 1'Do While i <= nterms ' do loop until i>nterms't = t & term1 & " "'term3 = term1 + term2'term1 = term2'term2 = term3'i = i + 1'Loop‘ method C- using do…loop while'i = 1'Do't = t & term1 & " "'term3 = term1 + term2'term1 = term2'term2 = term3'i = i + 1'Loop While i <= nterms ' loop while until>nterms

‘method D-using while … wendi = 1

Page 20

While i <= ntermst = t & term1 & " "term3 = term1 + term2term1 = term2term2 = term3i = i + 1Wend

Text2 = t ‘series will go into a text boxEnd SubPlace label1: having caption enter no. of terms of Fibonacci seriesPlace text1: having text property clearedPlace label2: having caption series isPlace command1: having caption print series in text box

Write short Notes on ‘exit do / exit for’ in Loop/write program to check primality.We often come across situations when we want to jump out of a loop instantly, without waiting to get back to the conditional test. The keyword ‘exit do / exit for’ allows us to do this. When the keyword ‘‘exit do / exit for’’ is encountered inside any loop statement, control automatically passed to the first statement after the loop. An ‘exit do / exit for’ is usually associated with an ‘if’ statement applicable to loop.The keyword ‘exit do / exit for’ takes the control out of the loop inside which it is placed.

What is use of const keyword?Const keyword is useful to declare a constant with a given symbolic name whose value can not change during program run time.Const pi =3.1415

What do you mean by nested loop?Nested loop is a special case in which one loop contains other loop inside its loop body. For each value of outer loop counter, inner loop counter changes frequently.

Program to print prime series between 1 to 100 using for loop and exit forPrivate Sub Command1_Click ()

Page 21

Dim a%, b%, c%, n%, t$, i%a = 1b = 100For n = a to b For i = 2 to n - 1 If n Mod i = 0 Then Exit For End If Next If i >= n Then t = t & " " & n End IfNextText1 = tEnd SubPlace label1: having caption set to prime series isPlace text1: having text property clearedPlace command1: having caption print series in text box

Define Array.Array or Subscripted variables:Array is collection of variables having common name and common data type. Individual variable in collection is identified by index or subscript. Elements of array occupy contiguous memory location.

How can we declare a single dimension Array?Declaration (single dimension numeric array):Dim a (5) as integer OrDim a %( 5) ‘a’ is name of array.it means there are 6 variables viz. a(0),a(1),a(2),a(3),a(4),a(5) index or subscript will ange from 0 to 5. All variables will be integers.Dim b! (10) OrDim b (10) as single It means there are 11 variables viz. b (0), b (1)… b (5) index or subscript will change from 0 to 10. All variables will be single.

Page 22

How we can initialize an array?Initialization of array is not supported by vb.

What are the usages/Applications of Array?Application of arrays:* It is useful to solve simultaneous equation.* It is useful to solve problems of data structure like searching, sorting, linked list, graph etc.* Its is useful to solve such problems requiring variable of same data type in contiguous memory location.

What is Multi Dimension Arrays? What are their usages?Array declared with more than one dimension is known as multi-dimension array.Often multi dimension array is needed to store data for table and matrices. Multi -dimension array has more than one subscript. Two dimension arrays contains two subscript, three dimension arrays has three subscript and so on.

Program to add two matrix of order 3x3Place three command buttons on form labeled input, sort, printDim a %( 2, 2), b %( 2, 2), c %( 2, 2), i%, j%Private Sub Command1_Click ()MsgBox "enter value for array a"For i = 0 To 2 For j = 0 To 2 a(i, j) = InputBox("enter value") NextNextMsgBox "enter value for array b"For i = 0 To 2 For j = 0 To 2 b(i, j) = InputBox("enter value") NextNextEnd Sub

Private Sub Command2_Click ()For i = 0 To 2 For j = 0 To 2 c(i, j) = a(i, j) + b(i, j)

Page 23

NextNextEnd Sub

Private Sub Command3_Click ()For i = 0 To 2 For j = 0 To 2 Print c(i, j) & " "; Next PrintNextEnd Sub

Program to sort a given arrayPlace three command buttons on form labeled input, add, and printDim a%(4)Private Sub Command1_Click ()Dim i%For i = 0 To 4 a(i) = InputBox("enter value", "data entry", 1)NextEnd Sub

Private Sub Command2_Click ()Dim i%, j%For i = 0 To 3 For j = 0 To 3 - i If a(j) > a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t End If NextNextEnd Sub

Private Sub Command3_Click ()Dim i%For i = 0 To 4 Print a(i)

Page 24

NextEnd Sub

What is dynamic array?Dynamic array is an array whose no. of elements is not specified earlier. No. of elements can be requested from user at program run time. Redim keyword can be used to allocate memory for such no. of elements. After allocating memory we can store value in elements of array.Dynamic array saves memory because we have to allocate memory for such many elements which we want to use.

Program to sort an array using dynamic arrayDim a%(), n 'note element is not specifiedPrivate Sub Command1_Click()Dim i%' take no. of elements requiredn = InputBox("enter no. of elements")'allocate memoryReDim a(n - 1) ' workoutFor i = LBound(a) To UBound(a) a(i) = InputBox("enter value", "data entry", 1)NextEnd Sub

Private Sub Command2_Click ()Dim i%, j%For i = LBound(a) To UBound(a) - 1 For j = LBound(a) To UBound(a) - 1 - i If a(j) > a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t End If NextNextEnd Sub

Private Sub Command3_Click()Dim i%For i = LBound(a) To UBound(a)

Page 25

Print a(i)NextEnd SubPlace command1: having caption set to inputPlace command1: having caption set to sortPlace command1: having caption set to print

Program to add two matrixes using non-dynamic array.Dim a%(2, 2), b%(2, 2), c%(2, 2), i%, j%,t$Private Sub Command1_Click ()MsgBox "enter value for array a"For i = 0 To 2 For j = 0 To 2 a(i, j) = InputBox("enter value") NextNextMsgBox "enter value for array b"For i = 0 To 2 For j = 0 To 2 b(i, j) = InputBox("enter value") NextNextEnd Sub

Private Sub Command2_Click ()For i = 0 To 2 For j = 0 To 2 c(i, j) = a(i, j) + b(i, j) NextNextEnd SubPrivate Sub Command3_Click ()For i = 0 To 2 For j = 0 To 2 t=t & c(i, j) & " " Next t=t & vbcrlfNextEnd SubPlace command1: having caption set to input

Page 26

Place command1: having caption set to add7place text1: having multiline property true and scrollbars set to 2 for bothPlace command1: having caption set to print

Program to multiply two matrixes using dynamic array.Dim a%(), b%(), c%(), i%, j%, m%, n%, p%, q%Private Sub Command1_Click()m = InputBox("enter no of rows in matrix a")n = InputBox("enter no. of columns in matrix a")p = InputBox("enter no of rows in matrix b")q = InputBox("enter no. of columns in matrix b")If n <> p Then MsgBox "invalid matrix order for multiplication" Exit Sub ' come out of eventEnd IfMsgBox "enter value" & m * n & " for array a"ReDim a(m - 1, n - 1) 'allocate memory before storing valueFor i = LBound(a, 1) To UBound(a, 1) For j = LBound(a, 2) To UBound(a, 2) a(i, j) = InputBox("enter value") NextNext

MsgBox "enter value" & p * q & " for array b"ReDim b(p - 1, q - 1) 'allocate memory before storing valueFor i = LBound(b, 1) To UBound(b, 1) For j = LBound(b, 2) To UBound(b, 2) b(i, j) = InputBox("enter value") NextNextEnd Sub

Private Sub Command2_Click()ReDim c(m - 1, q - 1)For i = LBound(a, 1) To UBound(a, 1) For k = LBound(b, 2) To UBound(b, 2) c(i, k) = 0 For j = LBound(a, 2) To UBound(a, 2) c(i, k) = c(i, k) + a(i, j) * b(j, k)

Page 27

Next NextNextEnd SubPrivate Sub Command3_Click()For i = LBound(c, 1) To UBound(c, 1) For j = LBound(c, 2) To UBound(c, 2) Print c(i, j) & " "; Next PrintNextEnd SubPlace command1: having caption set to inputPlace command1: having caption set to multiplyPlace command1: having caption set to print

What is use of preserve keyword?Preserve keyword is useful to let the dynamic array remember the older contents it has.e.g.Private Sub Command1_Click ()Dim a %()'RedimensionReDim a (2)a (0) = 10a (1) = 20a(2) = 30Print a(0), a(1), a(2)

'Resize array without using redimReDim a(3)a(3) = 40

Print a(0), a(1), a(2), a(3)End Sub

Private Sub Command2_Click()Dim a%()'redimensionReDim a(2)

Page 28

a(0) = 10a(1) = 20a(2) = 30Print a(0), a(1), a(2)

'change array size and use preserveReDim Preserve a(3)a(3) = 40

Print a(0), a(1), a(2), a(3)End SubPlace command1: having caption set to test without preservePlace command1: having caption set to test with preserve

What is function?A number of statements grouped into a single logical unit are referred to as a function which returns a value and which is made to complete a specific task. A program can be made of many functions. Types of functions:User defined function: these are those functions which are made by programmer for his programming convenience.Library function: these are those functions which are readymade and are provided by compiler, uses of which are possible by including corresponding header files. Source code of library function is not available to programmer but its object codes are available in precompiled form.

What is procedure?A number of statements grouped into a single logical unit is referred to as a procedure or subroutine which does not return any value and which is made to complete a specific task. A program can be made of many procedures.

What are the usages/applications of functions/procedures?Usages are as follows:

1. Function/procedure avoids code repetition: - once a function/procedure has been made we can call the function/procedure to complete the task when and where necessary.2. Function/procedure used carefully makes the process of error removing easier called debugging.3. Once function/procedure is tested and satisfies the one’s needs, one can convert it in to library, and can distribute it others for use.

Page 29

4. Function/procedure allows breaking bigger task into smaller manageable subtasks which is soul of modular programming.5. Recursive function/procedure (function/procedure calling itself at least once) solves some typical programming tasks easily and with few lines of coding which otherwise would have taken several lines of code.

What do you mean by recursion? what are recursive function explain with an example.Expressing an entity in terms of itself is known as recursion. When function/procedure calls itself at least once the function/procedure is called recursive function/procedure. Recursive function/procedure contains a function/procedure call statement to call itself normally kept inside if-else construct. Putting function/procedure call inside if-else construct allows termination of recursive function/procedure call after some time.While defining a recursive function/procedure we must take care of these two points* Each time a function/procedure calls itself it must be closer, in some sense to a solution.* There must be a decision criterion for stopping recursive function/procedure call otherwise it will execute till the stack overflows.Write program to find factorial using recursive functionPrivate Sub Command1_Click ()Dim n%, m&n = Text1m = fact(n)Text2 = mEnd SubPrivate Function fact&(n As Integer)If n <= 1 Then fact = 1Else fact = n * fact(n - 1)End IfUser interface:Create a command button: having caption find factorialCreate text1: having text property clearCreate text2: having text property clearCreate label1: having caption property set to enter a value

Page 30

Create label2: having caption property set to factorial is

write program to find factorial using function.Private Sub Command1_Click ()Dim n%, f&n = Text1f = fact(n)Text2 = fEnd Sub'Private Function fact&(byref x%) ‘ by default calling by reference'Dim i%, f&'f = 1'For i = 1 To x' f = f * i'Next'fact = f'End FunctionPrivate Function fact&(ByVal x%)Dim i%, f&f = 1For i = 1 To x f = f * iNextfact = fEnd Functionuser interface:Create a command button: having caption find factorialCreate text1: having text property clearCreate text2: having text property clearCreate label1: having caption property set to enter a valueCreate label2: having caption property set to factorial is

Explain call by value and call by reference'When called routine is not able to change value of actual argument'Through dummy argument it is known as call by valuePrivate Sub Command1_Click ()Dim a%, b%a = Text1b = Text2swap a, b

Page 31

'after callText5 = aText6 = bEnd SubPrivate Sub swap(ByVal a%, ByVal b%) 'default is call by reference Text3 = aText4 = bDim temp%'interchangetemp = aa = bb = tempEnd Sub

call by reference:'When called routine is able to change value of actual argument'Through dummy argument it is known as call by referencePrivate Sub Command1_Click ()Dim a%, b%a = Text1b = Text2swap a, b'after callText5 = aText6 = bEnd SubPrivate Sub swap(Byref a%, Byref b%) 'default is call by reference Text3 = aText4 = bDim temp%'interchangetemp = aa = bb = tempEnd Subuser interface:6 textboxes: having text property clear and having default name text1, text2…

Page 32

6 labels: having caption enter value of a, enter value of b, within called subroutine value of a, within called subroutine value of b, after call to swap value of a, after call to swap value of b1 command button: having caption swap and having default name command1

Write program using passing array to function to sort and find sum of element of an array'passing array to functionPrivate Sub Command1_Click ()Dim a%(4), x%input_array asort_array aprint_array ax = sum_array(a)Print "sum=", xEnd SubPrivate Sub input_array(a%())'array is always passed by referenceDim i%For i = LBound(a) To UBound(a) a(i) = InputBox("enter value for element")NextEnd SubPrivate Sub print_array(a%())'array is always passed by referenceDim i%For i = LBound(a) To UBound(a) Print a(i)NextEnd Sub

Private Sub sort_array(a%())Dim i%, j%, t%For i = LBound(a) To UBound(a) For j = 0 To UBound(a) - 1 - i If a(j) > a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t

Page 33

End If NextNextEnd SubPrivate Function sum_array(a%())Dim s%For i = LBound(a) To UBound(a) s = s + a(i)Nextsum_array = sEnd Functionuser interface:command1: having caption set to input, print, sum of element Write program to sum two matrix of order 3x3 using function.Private Sub Command1_Click ()Dim a%(2, 2), b%(2, 2), c%(2, 2), i%, j%MsgBox "enter value for elements of array a"input_array aMsgBox "enter value for elements of array b"input_array bsum_array a, b, cprint_array cEnd SubPrivate Sub input_array(a%())For i = 0 To 2 For j = 0 To 2 a(i, j) = InputBox("enter value") NextNextEnd Sub

Private Sub sum_array(a%(), b%(), c%())For i = 0 To 2 For j = 0 To 2 c(i, j) = a(i, j) + b(i, j) NextNextEnd SubPrivate Sub print_array(c%())

Page 34

For i = 0 To 2 For j = 0 To 2 Print c(i, j) & " "; Next PrintNextEnd Subuser interface:command1: having caption input,add and print

Differentiate MsgBox and InputBox

InputBox MsgBox

Input box can be used to get user input of data and data can be numeric or string

MsgBox can be used to get user input of data in integer form only when used function format of MsgBox. When used subroutine format of MsgBox it can display message only.

Input box has ok, and cancel button only and text area to enter data.

MsgBox can have various button like, ok, cancel, abort, retry, ignore etc. it can display graphical symbol; we can set focus to command button.

Input box has following syntax

Prompt: the text which will appear in client are

Title: the text which will appear in title bar

Default: the default value already will be shown in text area

X,y : to position InputBox at particular location

Input box has following syntax

Prompt: the text which will appear in client are

Button: button which will appear in client area, the graphics which will appear and the focus.

title: the text which will appear in title bar

Helpfile:specify help file which

Page 35

Helpfile:specify help file which contents help

Context: specify help context id for input box

contents help

Context: specify help context id for input box

Write program to demonstrate various string functions.Private Sub command1_click ()Dim d$()a = "Hello Dear"b = UCase(a)Print "uppercase=" + b

b = LCase(a)Print "lowercase=" + b

b = StrReverse(a)Print "reverse string=" + b

a = "i am going"b = StrConv(a, vbProperCase)Print "proper case=" + b

a = "big mouse"b = Mid(a, 2, 4)Print "starting from position 2 and no. of character 4 of string 'big mouse' will be=" + b

a = "big mouse"b = Left(a, 3)Print "leftmost 3 characters of string 'big mouse' is =" + b

a = "big mouse"b = Right(a, 3)Print "rightmost 3 characters of string 'big mouse' is =" + b

a = "big mouse"b = Replace(a, "m", "h")Print "when 'm' is replaced by 'h' string 'big mouse' becomes=" + b

Page 36

a = " ranu "b = LTrim(a)Print "removing extra space of string ' ranu ' from left=" + b + "ok"

a = " ranu "b = RTrim(a)Print "removing extra space of string ' ranu ' from right=" + b + "ok"

a = " ranu "b = Trim(a)Print "removing space from both side of string ' ranu ' from right=" + b + "ok"

a = "i am beautiful"d = Split(a, " ") ' each word will be stored in different ' element of dynamic string array dPrint d(0)Print d(1)Print d(2)b = Join(d, ",")Print " content of dynamic string array is joined by seperator comma:" + b

a = "i am beautiful"n = InStr(a, "am")Print " string 'am' appears in string 'i am beautiful' at position =" & nEnd Sub

Explain date and time related functionsPrivate Sub Command1_Click()‘Differentiate now and date functionsPrint "current date and time=" & NowPrint "shows or set current date only=" & Date

Print "shows or sets current time=" & TimePrint "date part of current date=" & Day(Now)Print "month part of current date=" & Month(Now)Print "year part of current date=" & Year(Now)

Print "hour part of current time=" & Hour(Now)Print "minute part of current time=" & Minute(Now)Print "second part of current time=" & Second(Now)

Page 37

‘explain dateadd and datediff functionsDim d As Dated = #10/13/2004#Print "three days added to date 10/13/2004 will be" & (d + 3)Print "three days subtracted to date 10/13/2004 will be" & (d - 3)Print "three months added to date 10/13/2004 will be" & DateAdd("m", 3, d)Print "three days added to date 10/13/2004 will be" & DateAdd("d", 3, d)Print "three year added to date 10/13/2004 will be" & DateAdd("yyyy", 3, d)

Print "10/13/2004 and 2/4/2003 has no. of days between=" & DateDiff("d", #2/4/2003#, #10/13/2004#)Print "10/13/2004 and 2/4/2003 has no. of months between=" & DateDiff("m", #2/4/2003#, #10/13/2004#)Print "10/13/2004 and 2/4/2003 has no. of years between=" & DateDiff("yyyy", #2/4/2003#, #10/13/2004#)

End Sub

write program using format function to demonstrate use of format functionPrivate Sub Form_Click()Dim d As Date, t As Singled = #10/4/2004# 'date formattingPrint Format(d, "m/d/yy")Print Format(d, "mm/dd/yyyy")Print Format(d, "mmm/ddd/yyyy")Print Format(d, "mmmmm,yyyy")Print Format(d, "long date")Print Format(d, "short date")

t = 23.45678 'number formattingPrint Format(t, "##.##")Print Format(t, "####.##")Print Format(t, "0,0.00")Print Format(t, "000,0.00")Print Format(t, "fixed")Print Format(t, "scientific")

Print Format(t, "00,.00") 'divide no. by 1000 and show valuePrint Format(t, "0000,.00")

Page 38

u = "Raman" 'format stringPrint Format(u, "<") 'in small letterPrint Format(u, ">") 'in capital letter

Dim v As Date 'formatting timev = #10:12:20 AM#Print Format(v, "hh:mm:ss AM/PM")Print Format(v, "long time")Print Format(v, "short time")End Sub

Understanding User Interface:

What is form?Form is a container control it means that form can contain other control inside itself. Form is a control where programmer populates other control to construct graphical user interface. a form is instance(object) of generic class ‘form’ and we know object has certain properties or methods this is also true for form.

List out common properties of form/write any seven properties of form.(i)Name: this is the property possessed by any control which lets the control identified inside code.(ii)Appearance: form’s look can be flat or 3d.(iii)Auto redraws: if it is true control remembers what is drawn on surface of control.(iv) Back color: controls background color of form.(v) Border style: controls many settings related to border, sizing of form, placement of buttons on title bar etc.None: no title bar, no control box, no borderFixed: appears close button, title bar, border, form is not sizable.Sizable: this is default and appears title bar, close, minimize, maximize, control box all are visible.Fixed tool window: appears close button and title bar with half height.Sizable tool window: same as fixed tool window except it can be sized.

(vi) Caption: returns or sets title bar text.(vii) Draw mode: draw mode controls behaviors of newly drawn pixel on form with existing pixel.

Page 39

(viii) Draw style: controls line type of lines drawn e.g. dotted, dash dot.(ix) Drawwidth: outline width can be set or retrieve using this property.(x) Enabled: if enabled is true form can fire event as well as control placed on form.(xi) Fill color: controls color of fill pattern.(xii) Fill style: allows to set fill pattern used to fill object which are closed. (xiii) Font: set font name which will be used by print statement.(xiv) Forecolor: color that controls outline color of drawing methods and print statement.(xv) Height: gives height of form including title bar.(xvi) Icon: set icon which will appear in title bar.(xvii) Key preview: keyboard event of object is invoked later on form’s key event.(xviii) Left: gives horizontal distance of form with respect to its container (screen or mdiparent form)(xix) Maxbutton: set true if required maxbutton(xx) Mdichild: makes a form mdichild form if set true.(xxi) Maxbutton: set true if required maxbutton(xxii) Mouse icon: set mouse pointer property to custom and set mouse icon property to your choice.(xxiii) Movable: if true form can be moved(xxiv) Picture: use this property to set form background picture.(xxv) Scale height: this property gives height of form without height of title bar. You can use this property to divide overall height into a specified no. of units.(xxv) Scale width: this property gives width of form. You can use this property to divide overall width into a specified no. of units.

(To be printed...)Write any seven events of form.(i) Initialize: this event is called before load event. it is fired once.(ii) Load: this is an event which is fired automatically when a form is about to show( due to call of method show) or load (due to call of method load).(ii) Resize: this event is fired once when form is about to show and fired next time when size of form changes.(iii) Activate: this event is fired when form is about to show and fired next time when current form becomes active.(iv) Deactivate: this event is fired when form becomes deactivate due to click on title bar of other form.(v) Unload: this event is fired when form is about to close.

Page 40

(vi) Query unloads: this event is fired when form is about to close. this event has an argument.(vii) terminate: this is the last event fired when form is about to close.

Describe methods of form.Method is as follows:Though there are many methods some are of related to graphics and some are related to control working of form.Those which are related to working of form are as follows:1. Show: this method causes the form to show. if form is hidden it becomes visible. 2. Hide: this method hides the form but form still consumes memory in computer.3. Load: this method causes form to consume memory resources and whatever statements are written in form load and form initialize are run but form is not visible.4. Unload: this method is useful to free memory resources taken by form. if form is visible it becomes invisible.

Write program using forms demonstrating use of multiple forms./ program to add two nos. multiply to nos. etc. each applied on different formstart new standard exe project:it will have a form already included, type following code in form1’s code view:

Private Sub Command1_Click()Form2.ShowEnd Sub

Private Sub Command2_Click()Form3.ShowEnd Sub

Private Sub Command3_Click()Form4.ShowEnd Sub

Private Sub Command4_Click()Form5.ShowEnd Sub

Page 41

Private Sub Command5_Click()EndEnd Sub

user interface for form1:command1: set caption to ‘add’command1: set caption to ‘sub’command1: set caption to ‘divide’command1: set caption to ‘multiply’command1: set caption to ‘exit’

Private Sub Command1_Click()Text3 = CSng(Text1) + CSng(Text2)End Sub

Private Sub Command2_Click()Unload Me 'me means current formForm1.ShowEnd Sub

user interface for form2:label1: set caption to ‘enter first value’label2:set caption to ‘enter second value’label3:set caption to ‘result’

command1: set caption to ‘add’command2:set caption to ‘back’

similary design interface and code for form3, form4, form5 etc. but don’t forget to change operator sign and caption of command button1.

Explain frame control. List the advantages of using a fame control in vb?Frame is a container control. it means that this control can be used to place other controls inside it.Advantages of frame control:1. We can use frame control to place option buttons and create different set of option buttons user can choose any one option button from each set. if we don’t use frame we can not create different sets of option buttons and user can select only on option button.

Page 42

2. Controls used on form if are logically related we can place them inside frame to give use clue that those controls are interrelated thus increasing readability.3. Frame control decorates form.4. If we set enabled property to false of frame control all it child control will become disabled and vice versa.Useful property: caption-the text which appear in frame upper left corner.Enabled-if set true child controls will be enabled otherwise disabled.

What are menus? Explain the process of creating menus in vb:Menus are convenient means to place and organize commands that application supports in structured manner. Menu avoids putting of several command buttons to initiate the same sequence of commands supported by application. Menu prevents overcrowding of form from command buttons.Menu is composed of following items:a. Menu bar: the place where first level menu items appear are known as menu bar. The first level menu are placed on menu bar and provided hot keys and are known as menu pads. Menu pads can not have short-cut.b. Pull down menu: when menu pad is activating pull down menu appears which is the next level menu items. c. Submenu or cascading menu: second level menu item normally initiates a command or another submenu (which is actually third level menu items). Though we can have fourth level submenus yet these are not frequently used.Process of creating menu:Demo using menu to make text box text bold, italic, underline.Press control+e to bring menu editor dialog:Enter following information in menu editor dialog use left or right arrow, right arrow key to change indentation level, next button to create new item as necessary.Caption Name Shortcut Indentation level

&Format MnuFormat First

&Bold Mnubold Ctrl+b Second

&Italic Mnuitalic Ctrl+i Second

&Underline Mnuunderline Ctrl+u Secondplace a text box on form with name text1

Page 43

and type following event procedure codes :private sub mnubold_click()text1.fontbold=not text1.fontboldend subprivate sub mnuitalic_click()text1.fontitalic=not text1.fontitalicend subprivate sub mnuunderline_click()text1.fontunderline=not text1.fontunderlineend subrun the project and click on menu items.

Describe options of menu editor.Options are as follows:Name: allows you to enter a control name for the menu item. a control name is an identifier used only to access the menu item in code; it doesn’t appear in a menu.Index: allows you to as a numeric value that dermjines the control’s position withing a control array. This position isn’t related to the screen position.Shortcut: allows you to select a shortcut key for each command.Help context id: allows you to assign a unique numeric value for the context id. This value is used to find the appropriate help topic in the help file identified the help file property.Negotiate position: allow you to select the menu’s negotiate position property. The property determined whether and how the menu appears in a contain form.Checked: allows you to have a check mark appear initially at the left of a menu item. It generally used to indicate whether a toggle option is turned on or off.Enabled: allows you to select whether you want eh menu item to respond to events, or clear if you want the item to be unavailable and appear dimmed.Visible: allows you to have the menu item appear on the menu.Window list: determines if the menu control contains list of open mdi child forms in an mdi application.Right, left, up, down arrows: allows menu item indent, outset, move up, move down.Menu list: a list box that displays a hierarchical list of menu items. Submenu items are indented to indicate their hierarchical position or level.Next: move selection to the next line.Insert, delete: insert inserts a new menu item and delete deletes a menu item.

Page 44

ok: make menu item changes applied.Cancel: to abandon changes in menu items.

Differentiate menu and submenu.Menu Submenu

Menu contains submenu Submenu may contain other sub menu

Menu appear in menu bar Submenu appears in pull down menu when menu pad is click

Menu is first level menu item in menu editor

Submenu is second or further level menu items

Menu cannot have shortcut keys Submenu can have short cut keys

Menu can have window list item turned on in case of mdi application

Submenu does not uses this setting.

differentiate sub-procedure and function procedure.Subroutine Function

Sub procedure is more commonly known as procedure only.

Function procedure is more commonly known as function.

Subroutine does not return a value to calling routine therefore a variable can not appear in left side of assignment operator.

Function returns a value to calling routine therefore a variable can appear in left side of assignment operator.

Subroutine is used commonly when results many result are being produced.

Function is used commonly when a single result is being produced.

It uses sub..end sub keywords It uses function…end function keywords.

Differentiate list box and combo box.

Page 45

List box Combo box

List box contains list of items and user can select more than one items from list box

Combo box contains list of items and user can select any one item from list

List box does not have text area where user can type new item not in list portion.

Combo box has text area and user can type new item not in list

List box has two style settings: standard and check. check style puts check box before each item and user can tick mark items to select

Combo box has three style settings: simple, dropdown and dropdown list.

It has properties: multiselect, columns, selected, selcount which are not available in combo box.

It has properties: sellength, seltext, selstart which are not available in list box.

Height of list box can be changed Height of combo box is constant and can not be changed.

It has item check event. It does not fire item check event.

Differentiate check box and option button.Checkbox Option button

Check box control displays rectangle where user can click to item select/unselect.

Option button displays circle where user can click to put dot to select item.

We can have multiple check boxes selected

We can have only one option button selected among set of option buttons

The value property of check box contains 1 if tick mark present or 0 if tick mark is absent.

Option button value property is true when dot is present in circle otherwise false.

It is not compulsory to put check It is compulsory to put option

Page 46

boxes in container control like frame or picture box to create many sets.

buttons in container control like frame or picture box to create many sets

These controls are useful when we want user to select more than one items

These controls are useful when we want user to select any one out of more than one items.

Differentiate binary and random fileBinary Random

It is to read or write data such as data of ole controls, image files, data field in a table of data type blob(binary large object) etc. less commonly used to read text data.

Random files are used to read write text data in terms of fixed record length. less commonly used to read/write binary data in terms of fixed length record.

It does not allow random access It allows random access of data.

Binary can make use of input function

Random can not make use of input function.

Type..end type statement is not useful.

Type..end type statement is used to created user defined data type which helps to create fixed record length.

differentiate sequential and random access file.Sequential Random

Sequential does not use record of fixed length.

Random uses record of fixed length.

Sequential is useful to read text data in sequence.

Random can be used to read text and binary data in terms of fixed record length.

Sequential allows slow access of record

Random allows fast access of record randomly.

Page 47

Sequential file can use following statements which random file can not use: input, input#,line input ,print #,write#

It can use get and put statement which can not be used by sequential file.

differentiate image box and picture box.Image box Picture box

Image box is designed specifically for displaying picture.

Picture box is designed for displaying picture as well as drawing graphics.

It consumes less system resources and redraws picture fastly.

It consumes more system resources and redraws picture slowly.

Image box is not a contained control it means that other control can not be placed inside it.

Picture box is container control it means that we can place other control inside it.

If has properties and methods dis-similar to form. it has stretch property which when set true picture is stretched to fit in image control.

It has properties and method similar to that of form therefore it is some times known as form within form. it has autosize property which when set true picture box resizes itself to fit picture.

write short notes on keyboard events.Private Sub Command1_Click()MsgBox "name=" & Text1 & "age=" & Text2 & "salary=" & Text3End Sub

Private Sub Text1_Change()'this event is fired when textbox contain changesEnd Sub

Private Sub text1_GotFocus()'select text if text1 receives focusText1.SelStart = 0Text1.SelLength = Len(Text1)

Page 48

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)'this event is fired when user presses a key reports ansi value of key pressedIf KeyAscii = 13 Then 'ascii value of enter key SendKeys "{tab}"End If'avoid appearance of invalid keys'keyascii for backspace is 8If InStr("ABCDEFGHIJKLMNOPQRTSTUVWXYZ ,.", UCase(Chr(KeyAscii))) = 0 And KeyAscii <> 8 Then KeyAscii = 0End If'turn on letters to appear in capsIf KeyAscii >= 97 And KeyAscii <= 122 Then KeyAscii = KeyAscii - 32End IfEnd Sub

Private Sub Text1_Keydown(KeyCode As Integer, Shift As Integer)'this event is fired after keypress , when key is released'keycode reports code , shift reports control,shift,alter keys statusIf Chr(KeyCode) = "A" And Shift = vbCtrlMask Then 'means control+A Text1.SelText = "Mr."ElseIf Chr(KeyCode) = "A" And Shift = vbAltMask Then 'means alter+A Text1.SelText = "Mrs."ElseIf Chr(KeyCode) = "A" And Shift = vbCtrlMask + vbShiftMask Then 'means control+shift+A Text1.SelText = "Miss"ElseIf KeyCode = vbKeyF1 Then Text1.SelText = "Welcome"End IfEnd Sub

Private Sub Text1_Validate(Cancel As Boolean)'this event is fired when text box is about to lose focus'if cancel argument is assigned value true, text box can not lose focusIf Len(Trim(Text1)) = 0 Then MsgBox "please type name"

Page 49

Cancel = TrueEnd IfEnd Sub

What is mdi form?/write short notes on mdi form/ what are benefits of mdi form?.mdi form is a form which can be used to create mdi application. only one mdi form can be used in a project as soon as an mdi form is added the command becomes unavailable. more than one mdi childs can be attatched to a single mdi-parent form. some application like ms-word, ms-excel are using mdi concept. the benefits of using mdi application are as follows:a. user can open more than one documentb. data easily can be transferred from one document to other document.c. we can view more than one file side by side using tile command of windows menu.d. we can not move document window( mdi child form) outside border of mdi parent window.e. when menu system is defined on both mdi-parent and mdi-child as soon as mdi child window appear it replaces menu system defined in mdi-parent.f. when menu system is defined only in mdi-parent appearance of mdi-child window does not cause dis-appearance of mdi-parent menu.g. closing of mdi-parent window causes closing of all mdi-child windows.

Write steps involved to create mdi form.let us define steps involved in creating mdi forms:-1. start a new standard exe project: project will contain a form name form12. from project menu select add mdi form : name of mdi form is mdiform13. select form1 and set its mdichild property to true4. inside code view of mdiform1 :

declare an array by using statementdim f(2) as new form1 in general declaration sectioninsert following statements in mdiform_load event of mdiform1f(0).Caption = "document1"f(0).Showf(1).Caption = "document2"

Page 50

f(1).Showf(2).Caption = "document3"f(2).Show

5. make the mdiform1 as startupobject : use project->properties->startup object->mdiform16. run the project using f5

What is short cut for running the project?f5

Describe Select Case..End select/select case.. end select statementThe control statement which allows us to make a decision from the number of choices is called a select, or more correctly a select case – case else- end select. Since these three keywords go together to make up the control statement. They most often appear as follows:select case(integer or string expression) case is >= constant1: do this and thiscase constant2 do this and thiscase constant 3 to constant 4 do this do thiscase constant5,constant6 , constant7 do this do thiscase else do this do thisend select

the integer expression following the keyword select-case is any ‘vb’ expression that will generate an integer value or string constant. It could be an integer constant like 1,2,3 or an expression that evaluates to an integer or any string constant .When a match is found, then program executes the statements following that case, and all subsequent cases and default statements are not executedl. If no

Page 51

match is found with any of the case statement, only the statements following the case-else are executed. A few examples will show how this control works.

Write program to demonstrate mdi form arrange method, menu replacement and opening and saving text file.ans:in form1 design following menumnufile &File

mnuopen &Open…mnusave &Save…mnusep -mnuclose &Close

mnuwindow &Window (turn on window list check box)mnuarrange &Arrange Iconsmnucascade &Cascademnutilehor Tile &Horizontalmnutilever Tile &Vertical

in mdiform1 design following menumnufile &File

mnuopen &Open…mnusep -mnuexit &Exit

form form1 set mdichild property truefor mdiform1 set autoshowchildren property falseplace text1 on form1 and set its multiline true and scrollbars to 3.(A)type following code in form1:

Private Sub Form_Resize()Text1.Move 0, 0, Form1.Width, Form1.ScaleHeightEnd Sub

Private Sub mnuArrange_Click()MDIForm1.Arrange vbArrangeIconsEnd Sub

Private Sub mnucascade_Click()MDIForm1.Arrange vbCascadeEnd Sub

Page 52

Private Sub mnuClose_Click()Unload MDIForm1.ActiveFormEnd Sub

Private Sub mnuNew_Click()MDIForm1.mnuNew_ClickEnd Sub

Private Sub mnuOpen_Click()MDIForm1.mnuOpen_ClickEnd Sub

Private Sub mnuSave_Click()Dim filename As StringIf InStr(UCase(Me.Caption), "DOCUMENT") <> 0 Then filename = InputBox("enter text file name to save with complete path")Else filename = Me.CaptionEnd IfOpen filename For Output As #1Me.Caption = filenamet = Text1Print #1, tClose #1End SubPrivate Sub mnutilehor_Click()MDIForm1.Arrange vbTileHorizontalEnd SubPrivate Sub mnutilever_Click()MDIForm1.Arrange vbTileVerticalEnd Sub

(B) put following coding in mdiformPrivate Sub mnuExit_Click()EndEnd SubPublic Sub mnuNew_Click()Dim f As New Form1 Static i%

Page 53

f.Caption = "document:" & (i + 1) i = i + 1

f.Show

End Sub

Public Sub mnuOpen_Click()

'coding to open file

Dim filename As String

filename = InputBox("enter text file name with complete path")

Open filename For Input As #1

Form1.Text1 = Input(LOF(1), 1)

Form1.Caption = filename

Close #1

End Sub

What is meant by event driven programming in vb? Event driven programming vs procedure oriented programming.When a program consists of one or more than one event procedures and those procedures accomplish the task to be done by program it is know as event driven programming.Event is any action performed by either performed by user or performed by program itself. For example mouse-click, key press, window resize etc.

Structured/Procedure Oriented Event Driven Programming

Page 54

Program consists of one or more procedure.

Program consists of one or more event procedure.

Programming task is completed by procedure.

Programming task is completed by event procedure.

The order of execution of procedure is more or less predictable.

The order of execution of event procedure depends on user performed action.

Procedure oriented programming is not suitable for window based application.

Event driven programming is suitable for window based application.

Write control instruction with example.Control instruction decides the flow of control of the program. There are many control instructions available in vb. Control instruction can be categorized as :1. Conditional branching: conditional branching statement allows to execute some statement under one condition and other statements under some other condition. It is also known as selection statements.it includes if..else.endif, select case… end select2. Looping: if we want to run some set of statement again and again till the given condition is true, we can use loop controls.It includes do loop…while, do … while loop, while … wend, for…end forFor example of each control instruction please refers other pages in notes.

What is various types of operators in vb list them in each category.Arithmetic operator:+ For addition,- For subtraction.* For multiplication\ For integer division c=10\3 c will be 3\/ For float division c= 10/3 c will be 3.333^ For power e.g. c=10^3 therefore c will be 1000Mod for modulo division c=10 mod 3 c will be 1Relation operator >,>=,<,<=,=, <>Logical operator

Page 55

And, or, notAssignment =

Write data types used in vb.Data type of variable defines range, memory and valid operation for a variableData type Range Memory

1.Byte 0 , 255 1

2.Integer % 32767 , 0 , -32768 2

3. Single ! +/- 3.4 e +34 4

4.Double # +/- 1.7 e+308 8

5.Date 1-1-100 to 31-12-9999 8

6.string(variable) $ 2 billion characters

6.string(fixed) $

7.boolean True, false 2

8.object Reference of any object

9. variant Range for number is same as double

Range for string is same as 2 billion characters

What is mdi form, write five main differences between mdi and sdi application.What is mdiform ? How will you create mdi parent and child form.What is SDI? Explain it.What do you understand by MDI? Write with example? How it is better than SDI.mdi form is a form which can be used to create mdi application. Only one

Page 56

mdi form can be used in a project as soon as an mdi form is added the command becomes unavailable. more than one mdi Childs can be attached to a single mdi-parent form. Some application like ms-word, ms-excel are using mdi concept.the benefits of using mdi application over sdi application are as follows:h. user can open more than one document while in sdi only one document can be opened at a time.i. data easily can be transferred from one document to other document using drag and drop and we can see content of more than one document at a time.j. we can view more than one file side by side using tile command of windows menu.k. we can not move document window( mdi child form) outside border of mdi parent window.l. when menu system is defined on both mdi-parent and mdi-child as soon as mdi child window appear it replaces menu system defined in mdi-parent.m. when menu system is defined only in mdi-parent appearance of mdi-child window does not cause dis-appearance of mdi-parent menu.n. closing of mdi-parent window causes closing of all mdi-child windows.Sdi application on the other hand allows to open only one document at a time. If we have already open a document and try to open another document the application will ask to close the current document only then we can open other document.Steps involved to create mdi form.let us define steps involved in creating mdi forms:-7. start a new standard exe project: project will contain a form name form18. from project menu select add mdi form : name of mdi form is mdiform1 by default and this form will be mdiparent form9. select form1 and set its mdichild property to true then this form will be mdichild form.10. inside code view of mdiform1 :

declare an array by using statementdim f(2) as new form1 in general declaration sectioninsert following statements in mdiform_load event of mdiform1f(0).Caption = "document1"f(0).Show

Page 57

f(1).Caption = "document2"f(1).Showf(2).Caption = "document3"f(2).Show

11. make the mdiform1 as startupobject : use project->properties->startup object->mdiform112. run the project using f5

Describe scope of variable.What do you mean by scope and duration of a variable.Scope specifies the code range where value of variable is accessible.d. local variable: accessible inside a function or procedure. we use dim keyword to declare local variable.e. module level global variable: accessible inside a module but not outside from other module. we use dim or private keyword to declare module level global variable and declare it inside general declaration of module.f. global variable : accessible from every where. we use public or global keyword to declare global variable inside general declaration of module.Duration of a variable is also known as life time of variable, it means how long memory remain allotted to a variable?

Explain procedure in vb.What is procedure?a number of statements grouped into a single logical unit is referred to as a procedure or subroutine which does not return any value and which is made to complete a specific task. A program can be made of many procedures.Usages are as follows:1. Function/procedure avoids code repetition:- once a function/procedure has been made we can call the function/procedure to complete the task when and where necessary.2. Function/procedure used carefully makes the process of error removing easier called debugging.3. Once function/procedure is tested and satisfies the one’s needs, one can convert it in to library, and can distribute it others for use.4. Function/procedure allows breaking bigger task into smaller manageable subtasks which is soul of modular programming.5. Recursive function/procedure (function/procedure calling itself at least once) solves some typical programming tasks easily and with few lines

Page 58

of coding which otherwise would have taken several lines of code.Example of procedure:Demonstration of call by value and call by reference'When called routine is not able to change value of actual argument'Through dummy argument it is known as call by valuePrivate Sub Command1_Click ()Dim a%, b%a = Text1b = Text2Swap a, b'After callText5 = aText6 = bEnd SubPrivate Sub swap (By Val a%, By Val b%) 'Default is call by reference Text3 = aText4 = bDim temp%'InterchangeTemp = aa = bb = tempEnd Sub

Call by reference:'When called routine is able to change value of actual argument'Through dummy argument it is known as call by referencePrivate Sub Command1_Click ()Dim a%, b%a = Text1b = Text2Swap a, b'After callText5 = aText6 = bEnd SubPrivate Sub swap(Byref a%, Byref b%) 'Default is call by reference Text3 = a

Page 59

Text4 = bDim temp%'InterchangeTemp = aa = bb = tempEnd Subuser interface:6 textboxes: having text property clear and having default name text1,text2…6 labels: having caption enter value of a, enter value of b, within called subroutine value of a, within called subroutine value of b, after call to swap value of a, after call to swap value of b1 command button: having caption swap and having default name command1

What is IDE? Discuss any five components.Ide stands for integrated development environment. it is collection of program allowing to compose and edit the program, test the program, run the program and debug the program.Major components of vb Ide:1. Project startup dialog box: when we start vb program we get a dialog box which gives choice of project type to start.2. Project explorer window: project explorer window allows browsing different modules that make up our project. We can switch from one module to other module. We can see the object view, code view of the module. We can make save and save as the module, we can add new module from within the project explorer window.3. Form layout window: using form layout window we can set the startup position of a form on screen.4. Immediate window: using this window we can set new value for a variable while the project in debug window. We can check syntax of statement and function and we can use it as calculator also.5. Toolbox: toolbox contains various controls which we can place on form.6. Properties window: using this window we can set properties of a selected control or module.7. Form window: here we can place various control to design GUI for program.

Describe in brief all mouse events with example.

Page 60

Explain mouse events in VBMouse events are those events which are generated by mouse actions such as1. Mouse down: this event is fired when mouse button is hold down. This event reports mouse coordinate and button number which was press2. Mouse up: this event is fired when mouse button is left up. This event reports mouse coordinate and button number which was press3. Mouse move: this event is fired when mouse is moved. This event reports mouse coordinate. 4. Click: this event is fired when mouse button is hold down and left up. This event reports mouse coordinate and button number which was press5. Dblclick: this event is fired when mouse button is double clicked. This event reports mouse coordinate and button number which was press6. Drag drop: this event is fired when control is dragged and dropped over other control.7. Drag over: this event is fired when control is being dragged and enters the region of control on to which it is to be dropped.Start new standard exe project in vb and in code view window type following code to observe mouse events:

Private Sub Form Click ()Print "i am mouse click"End Sub

Private Sub Form_DblClick ()Print "i am mouse dblclick"End Sub

Private Sub Form_MouseDown (Button As Integer, Shift as Integer, X As Single, Y as Single)Print "i am mouse down reporting mouse coordinate and button"End Sub

Private Sub Form_MouseMove (Button As Integer, Shift as Integer, X As Single, Y as Single)Print " i am mouse move"End Sub

Private Sub Form_MouseUp (Button As Integer, Shift as Integer, X As Single, Y as Single)Print "i am mouse up reporting mouse coordinate and button"

Page 61

End Sub

Explain data report.orWrite down the step of generating report in vb through data environmentorWhat do you mean by data report and how will you create data report? Explain crystal report.Data reportData report is a reporting tool available in vb6.0. it is new feature of vb6.0. We can create, maintain, and access databases from within a visual basic application. The final piece of this set of building blocks is the capability to report on the data stored in the database. With vb6.0 we have a built-in reporting designed that works with the new data environment. Data report designer gives the capability to create database reports without using any third-party tools such as crystal report writer. It has following Features of data report:a. Drag and drop field placement: we can drag and drop the fields needed in report from data environment and vb automatically sets data member and data field property.b. Toolbox controls: the data report designer has its own set of control, which are automatically added to the toolbox on their own tab named Data reportc. Print preview: we can print the report in code by using the print report method or clicking the print button on the toolbar when in preview mode.d. File export: we can export the report in html, text or Unicode format using the export report method.

Steps of creating Data report using data environment:Suppose there is an ms-access database file having name: StudentInfo.mdbSuppose it contains a table having name: studentSuppose the table contains following fields: roll no, name, class It is required to prepare the report file then the steps required will be as follows:(1) Setting the data environment:A. project-> add data environmentB. in project explorer window double click on dataenvironment1

Page 62

C. right clicks on connection1 and selects propertiesD. double click on Microsoft jet 4.0 ole db providerE. on select or enter database name click command button with caption …F. selects the database student info from the locationG. click on ok to close data link properties dialog box.H. right clicks on connection1 and select add command.i right click on command1 and select propertiesj on database object select tablek on object name select studentl click on ok(2) Preparing data reportA. project-> add data reportB. select the data report and set its data source property to dataenvironment1, and data member property to command1C. right click on data report and select retrieve structure and click on yesD. drags the command1 from dataenvironment1 and drops it on detail sectionProperly adjust the fields on detail sectione. click on rptlabel on toolbox on data report tabAnd draw it on report header section and set its caption property to “Student List”(3) Set data report1 as startup object for this, use project->properties->start up object-> datareport1Save and run the project

Crystal Report:We can create, maintain, and access databases from within a visual basic application. The final piece of this set of building blocks is the capability to report on the data stored in the database.Crystal report is a third party report writing tool. It is created by Seagate technology it ships with visual basic6.0. Newer version of crystal report writer 9.0 supports use of data environment as data source and variety of other data sources that is used with crystal report 9.0. it takes approximately 300 mb of Hard disk space to installf. Drag and drop field placement: we can drag and drop the fields needed in report from data environment and crystal report automatically sets data member and data field property.g. Toolbox controls: the crystal report designer has its own set of controlh. Print preview: we can get print preview.i. File export: we can export the report in html, text or Unicode format

Page 63

j. Provides it own set of formulas for complex calculation.k. Provides reporting based on condition which makes a single report to be used on multiple situations.

What are dialog boxes? Explain different type of dialog boxes available in vb?Dialog boxes are windows that are quite commonly used for displaying some message or to collect some data from the user so as to perform some operation. Dialog boxes have fixed border and cannot be resized. It has close button, title bar and we can work on any other window in same application until we close it normally.VB offers two dialog boxes ready to useInputBox MsgBox

Input box can be used to get user input of data and data can be numeric or string

MsgBox can be used to get user input of data in integer form only when used function format of MsgBox. When used subroutine format of MsgBox it can display message only.

Input box has ok, and cancel button only and text area to enter data.

MsgBox can have various button like, ok, cancel, abort, retry, ignore etc. it can display graphical symbol; we can set focus to command button.

Input box has following syntax

Prompt: the text which will appear in client are

Title: the text which will appear in title bar

Default: the default value already will be shown in text area

X,y : to position InputBox at particular location

Input box has following syntax

Prompt: the text which will appear in client are

Button: button which will appear in client area, the graphics which will appear and the focus.

title: the text which will appear in title bar

Helpfile:specify help file which

Page 64

Helpfile:specify help file which contents help

Context: specify help context id for input box

contents help

Context: specify help context id for input box

What is property?Property of any object is actually member procedure which allows to set value in data member (working as mutator) or allows to retrieve value of data member (working as accessory).Properties of textbox for example are:1. name: this is property by which a textbox can be differentiated from other control2. height: height of the text box control3. width: width of the text box control4. locked: controls whether content of text box can be edited(locked: false) or cannot be edited(locked: true)5. Enabled: controls whether the text box can fire event or not.6. Text: controls the text that is to be shown in text box Etc.

What do you understand by front-end tool and back-end tool?Front end-tool normally provide graphical user interface or collect data or service request from the user. Front end tool require some data in order to fulfill requirement of user service for which it depends on back-end.Programming languages normally works as front end tool. For example visual basic application for library management system is a front end tool. In order to save, retrieve and report data it requires support of back end tool such as ms-access, oracle etc.

What are the connectivity features?OrWhat are DAO, ADO AND RDO?OrWrite the features of ado and difference between ADO, RDO and DAOADO (ActiveX data access Object):It uses Universal data access specification that means ADO can use data from variety of data sources. ADO is the application programming interface used to access information. Using ADO we can perform the following

Page 65

sequence of actions.1. Connect to a data source. Optionally you can ensure that all changes to the data source occur either successfully or not at all2. Specify a command to gain access to the data source3. Execute the command if the command causes data to be returned in the form of rows in a table, store the rows in a cache that you can easily examine, manipulate or change.4. if appropriate, update the data source with changes from the cache of rows5. Provide a general means to detect errors.

Features of ADOTypically we will use all theses steps in the programming model. However, ADO is flexible enough that we can do useful work by executing just part of the model.ADO object hierarchy is less hierarchical than RDO. Size of ADO object library is less than RDO and DAO. ADO is faster than RDO in performance. ADO provides greater no. of events than RDO and DAO. It uses command, connection, error, field, parameter, property, recordset objects. It uses errors, parameters, fields, properties collections

DAO (Data access Object):DAO is the oldest data access technology available in vb. Primary it was developed to write desktop database application with no client/server data base application development in mind.It can uses data through MS-jet database engine and ODBC. DAO object hierarchy is hierarchical. Size of DAO object library is larger than RDO and ADO. DAO is slower than ADO and RDO in performance. DAO provides least no. of events than ADO and RDO. It uses dbengine, workspace, error, database, tabledef, querydef, recordset, field, index, parameter, user, group, relation, property, container and document objects.It uses databases, users, groups, properties, errors, querydefs, recordsets, containers, relations, tabledef, fields, indexes, parameters, connections, workspaces, collections.

RDO (Remote Data access Object)RDO was developed after DAO. It was primary aimed to develop client/server database application development.It can use data through ODBC. ODBC was created to access data from only

Page 66

relational database. RDO object hierarchy is less hierarchical than DAO. Size of RDO object library is less than DAO. RDO is slower than ADO in performance. RDO provides greater no. of events than DAO.

DIFFERENCE AMONG ADO, DAO, RDO

ADO DAO RDO

It uses Universal data access specification that means ADO can use data from variety of data sources. ADO

is the application programming interface

used to access information.

It can uses data through MS-jet database engine

and ODBC

It can use data through ODBC. ODBC was

created to access data from only relational

database.

ADO object hierarchy is less hierarchical than

RDO

DAO object hierarchy is hierarchical

RDO object hierarchy is less hierarchical than

DAO

Size of ADO object library is less

Size of DAO object library is large

Size of RDO object library is less than

DAO

ADO is faster than RDO in performance

DAO is slower than RDO in performance

RDO is slower than ADO in performance

ADO provides greater no. of events than RDO

DAO provides least no. of events

RDO provides greater no. of events than DAO

It uses command, connection, error, field, parameter, property,

It uses db engine, workspace, error, database, tabledef,

Page 67

recordset objects. querydef, recordset, field, index, parameter, user, group, relation, property, container and document objects.

It uses errors, parameters, fields, properties collections

It uses databases, users, groups, properties, errors, querydefs, recordsets, containers, relations, tabledef, fields, indexes, parameters, connections, workspaces, collections.

What is dynamic array? What are the advantages of Dynamic Array?Dynamic array is an array whose no. of elements is not specified earlier. No. of elements can be requested from user at program run time. Redim keyword can be used to allocate memory for such no. of elements. After allocating memory we can store value in elements of array.Dynamic array saves memory because we have to allocate memory for such many elements which we want to use.EXAMPLE: PROGRAM TO SORT AN ARRAY USING DYNAMIC ARRAYDim a %(), n 'note element is not specifiedPrivate Sub Command1_Click ()Dim i%‘take no. of elements requiredn = InputBox ("enter no. of elements")'Allocate memoryReDim a(n - 1) ' workoutFor i = LBound(a) To UBound(a) a(i) = InputBox("enter value", "data entry", 1)NextEnd Sub

Page 68

Private Sub Command2_Click()Dim i%, j%For i = LBound(a) To UBound(a) - 1 For j = LBound(a) To UBound(a) - 1 - i If a(j) > a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t End If NextNextEnd Sub

Private Sub Command3_Click()Dim i%For i = LBound(a) To UBound(a) Print a(i)NextEnd Subplace command1:having caption set to inputplace command1:having caption set to sortplace command1:having caption set to print

Write various data conversion function along with its syntax.Functions whose name begins with c<type> convert an express from any data type into the specified data type.Sample syntax:A=cbool(int) ‘convert from integer to BooleanB=cbyte(int) ‘convert from integer to byteC=ccur(dbl) ‘ convert from double to currencyD =cdate(dbl) ‘ convert from double to dateE=cdec(hex) ‘convert from hexadecimal to decimalF=cdbl(vint) ‘ convert from variant to doubleG=cint(long) ‘ convert from long to integerH=clng(vint) ‘ convert from variant to logI= csng(curr) ‘ convert from currency to singleJ=cstr(dbl) ‘covert from double to string

Page 69

K=cvar(lng) ‘convert from long to variant

Explain the use of progress bar in vb. Write the step to print a progress bar on form.orExplain the use of progress bar and timer control in vb.Progress bar control is a control to give the user feedback that some process is going on and the user must wait for some time to finish the current on-going process. Progress bar uses timer control which helps in fill in the progress bar. Example: following example let’s the user wait for two secondsSteps1. start new standard exe project2. project->components -> place tick mark before Microsoft windows common control 6.0 (sp2)->ok3. place progress bar, and timer control on form.4. set timer interval to 100 ( timer event of timer control will fire in every 1/10 th second)5. set max to 60 and min to 0 for progress bar control6. right click on form and select code view window and type following codePrivate Sub Timer1_Timer()If ProgressBar1.Value < 60 Then ProgressBar1.Value = ProgressBar1.Value + 6End IfEnd Sub

What do you mean by ODBC?ODBC stands for open database connectivity. It is set of application programming interface written generally in c, c++ and assembly language to interact with wide variety of database supplied by different database vendors.ODBC provides a set of application programming interface that all developers could use, to connect and use databases and it was ODBC’S and ODBC driver’s responsibility to figure out how to talk to the database. As long as an ODBC driver was available for the database management system you were using, you only had to write your application to access the ODBC API. If an ODBC driver was not available, you had have to write to that DBMS’S API, or you had have to find some other method to access the

Page 70

database though some middleware product, such as Intersolv’s Q+E data drivers.

Write a program for storing the item database with field item name, item number, price, rate per item in sequential file and read data from the file.Steps1. start new visual basic standard exe project2. place five labels, five text boxes and two command buttonsset following properties:label1 caption enter namelabel2 caption enter item numberlabel3 caption enter sale pricelabel4 caption rate per itemtext1 text cleartext1 name txtnametext2 text cleartext2 name txtitemnumbertext3 text cleartext3 name txtsalepricetext4 text cleartext4 name txtrateperitemtext5 text cleartext5 name txtrecordtext5 multiline truetext5 scrollbars bothcommand1 caption addrecordcommand2 caption showrecordcommand1 name cmdaddrecordcommand2 name cmdshowrecord3. write following code in code view window

Private Sub cmdaddrecord_Click()Open "data" For Append As #1Print #1, txtnamePrint #1, txtitemnumberPrint #1, txtsalepricePrint #1, txtrateperitemClose #1txtname = ""txtitemnumber = ""

Page 71

txtsaleprice = ""txtrateperitem = ""End Sub

Private Sub cmdshowrecord_Click()Dim a$Open "data" For Input As #1txtrecord = "name,item number,sales price,rate per item" + vbCrLf

Do While Not EOF(1)Input #1, atxtrecord = txtrecord + aInput #1, atxtrecord = txtrecord + "," + aInput #1, atxtrecord = txtrecord + "," + aInput #1, atxtrecord = txtrecord + "," + a + vbCrLfLoopClose #1

End Sub

Differentiate different type of recordset.Recordset is set of records in memory resulted due to execution of query.Dynaset Table type Snapshot

This type of recordset is updateable

This type of record set is also updateable

This type of recordset is read-only and forward

We can use sql query for this type of record

We can use table name and we can not use sql query

We can use table name and sql query

It may take less than or equal to memory taken by table type

It takes higher memory It may take less than or equal to memory taken by table type

Page 72

It is slower It is slower in performance

It is faster

We can use find command and we can use index

We can make use of index to faster search the record

We can use find command and we can use index

Write short notes on VBP.orWhat is project file? why it is needed?Project file contains information about all those file which make the project. It stores location of individual file with path. When saving project it saves all files one by one inside project. When we open project it automatically opens all files which are part of project we need not to open each file one by one thus saving time. Project file has extension “vbp”.

Write short notes on list box and combo boxList box:List box contains list of items and user can select more than one items from list boxList box does not have text area where user can type new item not in list portion.List box has two style settings: standard and check. check style puts check box before each item and user can tick mark items to select.It has properties: multiselect, columns, selected, selcount which are not available in combo box. Height of list box can be changed. It has item check event.Combo box:Combo box contains list of items and user can select any one item from list. Combo box has text area and user can type new item not in list. Combo box has three style settings: simple, dropdown and dropdown list. It has properties: sellength, seltext, selstart which are not available in list box. Height of combo box is constant and can not be changed.It does not fire item check event.Both list box and combo box can be used to give user many choices and user can select choice from the list.Following are the common properties:1. List: it is an array property which holds the item in the list portion.

Page 73

2. List index: it is a property that gives index of the item selected and we can make an item selected. If no item is selected then it value is -1.3. Sorted: if true then items are arranged.4. List count: gives no. of items in list portion.Following are the common methods:1. Clear: it is useful to remove all items from list portion.2. Add item: it is useful to add an item in list portion.3. Remove item: it useful to remove an item from list portion.

Write short notes on immediate window.Immediate window is a window that normally appears in bottom. We can use immediate window to know value of variablePrint xWe can use immediate window to assign new value to variable when program is in break modeX=10We can use immediate window to check syntax of a functionPrint Len(“rama”)

Differentiate toolbar and menu bar.Toolbar Menu bar

Toolbar contains icons which starts a command

Menu bar contain menu pads which is made of text, normally menu bar opens pull down menu. Pull down menu may have item with icons which may start other submenu or command

Toolbar contains short cuts to start some command

Menu bar doesn’t contain short cut

Toolbar doesn’t contain highlight character

Menu bar contains highlight characters

Explain different types of data file in vb.Binary : It is to read or write data such as data of ole controls, image files, data field in a table of data type blob(binary large object) etc. less commonly used to read text data. It does not allow random access. Binary can make use of input function. Type. end type statement is not useful.

Page 74

Random : Random files are used to read write text data in terms of fixed record length. less commonly used to read/write binary data in terms of fixed length record. It allows random access of data. Random can not make use of input function. Type...end type statement is used to created user defined data type which helps to create fixed record length.Sequential : Sequential does not use record of fixed length. Sequential is useful to read text data in sequence. Sequential allows slow access of record. Sequential file can use following statements which random file can not use: input, input#, line input ,print #,write#Random : Random uses record of fixed length. Random can be used to read text and binary data in terms of fixed record length. Random allows fast access of record randomly. It can use get and put statement which can not be used by sequential file.

Write short notes on Form Layout Window.Form layout window is useful to set startup position of the form on screen graphically. To use form layout window we must run our project at least once then icon of the form appears in form layout window. Using mouse we can adjust position of form icon within form layout window. Now if we run the project the form will be in new position according to setting done within form layout window.

Write short notes on Option button (Radio button)Option button displays circle where user can click to put dot to select item. We can have only one option button selected among set of option buttons. Option button value property is true when dot is present in circle otherwise false. It is compulsory to put option buttons in container control like frame or picture box to create many sets. These controls are useful when we want user to select any one out of more than one item.Commonly use properties are as follows:1. Name: name properties are useful to identify one option button out of several controls in code view.2. Caption: this is the text that appears along with control.3. Value: this property is true when option button is selected otherwise its value is false.4. style: this property changes the look and feel of the radio button

Page 75

What is purpose of Val function?Val function extracts numeric value from string. If string starts with numeric value it gives numeric value. If string starts with non-numeric value it gives 0.Dim a#a = Val("123.456")Print a‘ print 123.456

a = Val("hello")Print a‘prints 0

a = Val("hello12")Print a‘prints 0

a = Val("hello 12")Print a‘prints 0

a = Val("12hello")Print a‘print 12

a = Val("12 34 .456hello")Print a‘prints 1234.456

Write short notes on Startup formWe can have many forms in our projects. When we run the project one of the forms will be startup form. To change the startup form we can use project->properties->startup object and we can specify the startup form from the combo box and we click on ok

Write short notes on visual data managerVisual data manager is a tool that ships along with VB. As its name employs we can use it to manage database.Following are operations we can do in visual data manager: (Add ins-> visual data manager)

Page 76

1. creating new database2. Opening existing database, redefining structure of table.3. Creating tables, renaming tables, deleting tables, creating primary key, unique key and defining fields.4. Setting validation text, rule for fields.5. compacting and repairing Microsoft access database6. find and replace value in a field based on criteria7. Data adding, editing and deleting in table.8. Running sql query and saving the query.

Write short notes on data control.VB provides a very useful control called data control that lets you access data coming from a database. You can perform most data access operations using data control without writing any code at all. The data control enables you to move from record to record and to display and manipulate data from the records coming from.Following are the properties which are quite commonly used:1. Database name: determines the path and filename of the database file.2. Exclusive: if this property is set to true, then when you open the database only you will have exclusive access to the database and others can’t access the database.3. Options: determines access constraints for the tables you are working on.4. Read-only: when true, you can not update the database.5. Record source: determines the source of the set of records retrieved by the data control.

What are the type of recordsets available in DAODifferentiate different types of recordset in DAOThere are 5 types of recordsets available in DAO but 3 are available in design time.1. Table-type: it represents the base table in a code form. It can be used to add, change, or delete records from a single database table.2. Dynaset type: it represents the result of a query that can have updatable records. It can be used to add, change, or delete records from one table. Fields can come from one or more database tables.3. Snapshot type: it is a static copy of a set of records that you can use to find data or generate reports. It can contain fields from one or more database tables. It is not updateable.

Page 77

4. Forward only: this recordset is identical to a snapshot except that no cursor is provided. You can only scroll forward through records.5. Dynamic type: it represents a query result set from one or more base table in which you can add, change, or delete records from a row-returning query. Further the records added, deleted or edited by other users, in the base tables also appear in your recordset.

Write short notes on bound controlsA bound control is also called data-aware control is a control that can provide access to a specific column or columns in a data source through a data control. A data-aware control can be bound to a data control through its data source and data field properties. When a data control move from one row to the next, all bound controls connected to data control change to display data from columns in the current row. If user changes in a bound control and then move to a different row, the changes are automatically saved in the data source.For e.g.Textbox, checkbox, label etc.

What is control Array? What is its utility?A control array is group of controls that share same name and type. A control array has at least one element and can grow up to 32767 elements. The elements of the same control array may have their own property settingsThe control arrays are useful for following things:1. Control arrays use fewer resources than multiple controls of same type.2. Code can be shared among the elements of a control array.

Write short notes on activex control.Or .ocxActivex controls which exist as separate files within .ocx file name extension. An activex control is an interactive object that can reside on any form that supports OCX( Ole controls) controls. An activex control is an extension to the visual basic toolbox. You can use activex controls just as you would use any of the standard built-in controls such as a scrollbar. Theses include controls that are available only in the profession and enterprise editions. Many third-party activex controls are also available.Adding activex controls to the toolbox1. from the project menu, choose components

Page 78

2. select the check box next to the name of the desired .ocx control, then choose okTo remove an activex control1. Remove all instances of the control from the forms in your project. Delete any references to the control in the project’s code. If references to a deleted control are left in your code, an error message will display when you compile the application.2. from the project menu, choose components. Clear the check box next to the name of the .ocx control, and then choose ok.

Write short notes on Ole control.The ole container control enables you to add insert able object to the forms in visual basic project. With ole control we can:1. Create a placeholder in our application for an insert able object. At run time we can create the object that is displayed within the ole control or change an object we placed within the ole container control at design time.2. Create a linked object in application.3. Bind the ole container control to a database using the data control.Commonly used properties:1. class: the property that returns the name of the application that produced the object.2. sourcedoc: the property that returns the data or a reference to the data.3. sourceitem: the property that returns the image of the data. This applies to linked objects only.4. sizemode: the property controls how ole control is sized5. oletypeallowed: this property determines whether source document is embedded, linked or bothCommonly used method1. create embed : useful to create embedded object.2. create link: useful to create linked object.

What are the categories of controls?There are three categories of controls in vb:1. Intrinsic controls: these controls are contained inside the visual basic .exe file. Intrinsic controls are always included in the toolbox.2. activex controls: it exists in separate files having .ocx extension.3. Insert able objects: some objects such as Microsoft excel sheet, word document can be added into toolbox and can be used like control.

Write short notes on Drawing Methods.

Page 79

Following are the graphics methods:1. cls : clears drawing area2. line: using this method line can be drawn, even rectangle can be created.3. circle: using this method we can draw arc, circle, pie slice and ellipse4. pset: it is used to draw a point5. print: we can print some text on control

What is dll?Dll stands for dynamic link library file. Dll file contains some functions and subroutines written in any language that supports creation of dll files. More than one application programs can call functions and subroutines in a dll file. More than one copy of dll file is not needed if more than one application programs are using same function or subroutine because dll file is used in shared environment. So disk space is saved and memory space is also saved.

Write short notes on animation in vbA common user for timer control is to create graphics animation, because the way you create animation is by displaying successive frames of the animation sequence at intervals. That is good job for the timer control.To see how this works, we will create an example now. In this example, we will just switch back and forth between two simple images, image1.bmp and image2.bmp, which are simple strips of solid color, red and blue.Step1. start new standard exe project2. place a picture box control and timer control3. set interval property to 1000 for timer control and enabled property to true4. add following code to code view windowprivate sub timer1_timer()static blnimage1 as Booleanif blnimage1 then picture1.picture=loadpicture(“image1.bmp”)else picture1.picture=loadpicture(“image2.bmp”)end ifblnimage1=not blnimage1end sub

Write short notes on on error, resume statements in VB.

Page 80

Vb provides many tools for debugging project1. on error goto label/line no : when you execute an on error goto label/line no statement in your code execution is transferred to the code starting at label if a trappable error has occurred. The code following that label is your error handler.2. on error goto 0 : if you want to turn off error trapping at some point in your code, you can execute the statement on error goto 0 just before that piece of code . then again you can give on error goto label statement for error trapping after that piece of code.3. on error resume next : on error resume next statement provides an easy way to disregard errors, if you want to do so. Once you execute this statement, execution continues with the next line of code if the current line generates an error, and the error is disregarded.4. resume: when you are writing code for an error handler, you can return control to the main body of the procedure using the resume statement. Program execution starts again with the line that caused the error, and this can be very valuable if you are able to fix the error in the error handler. 5. resume label: when your are writing code for an error handler, you can return control to a particular line in the main body of the procedure using the resume label statement. To a label a line, you just place the label’s text directly into the code, followed by a colon.6. resume next: this statement resumes program execution in the line after the one that caused the error.

What are err object and error function?Err: err is an object if we use err. Number then it gives error no. that occurred in statement, if we use err. Description it gives short description of the error occurred, if we use err. Raise we can raise an error intentionally.Error: it is a function if we give error no. as argument to it, it gives us error description.

Write short notes on debugging tools in vb.Visual basic offers a powerful suite of debugging options-notable the ability to single – step through your code as it is executing. The standard way to debug is to place a breakpoint at a particular line in your code, and when execution reaches that line, it will halt and visual basic will enter the debug state, give you access to your code and variables. You can examine the contents of those variables and work through your code line by line, watching program execution behind the scenes. To move through your program step-by-step you can select these stepping

Page 81

options in the debug menu:1. Step into-single step though the code, entering called procedures if encountered.2. Step over- single-step through the code, stepping over procedure calls.3. Step out- step out of the current procedure.Setting debugging breakpointsBreakpoints are the foundation of vb debugging. When you set breakpoints in a program and run that program, program execution continues until one of the breakpoints is encountered and program execution stops, making vb enter the debug state. You place a breakpoint in code by moving the text insertion caret to that line and either selecting toggle breakpoint in the debug menu or pressing f9.Examining variable and expression: just select the expression and press shift+f9 to evaluate variable and expression.Adding debug watch windows: you can add a watch window to your debugging session and display the values of selected variables or expressions in that window continuously as you execute your program line by line.Immediate window: when debugging, you can use the immediate window to examine expressions or variables immediately, just by typing them in.