Docsity

VISUAL BASIC PROGRAMMING QUESTIONS AND ANSWERS, Exercises of Computer science

Toggle sidebar
bg1
Visual Basic Programming
1
V Semester-B.Sc, BISM, BCA
Unit 1
Part A (2 Marks)
1. Write any three common properties for several visual basic controls.
BackColor and ForeColor- The BackColor property sets the background color of an object while the
ForeColor property changes the foreground color used to display text.
Caption-It sets the text displayed in the object's title bar or on the object.
Font-You can set the font property from the Properties Window.
2. What is toolbox? List the common collection of tools.
Displays the standard Visual Basic controls plus any ActiveX controls and inser table objects you have
added to your project. The tools in toolbox are label, textbox, combobox, option button, checkbox,
command button.
3. Define Variables. How to declare variable
variables are areas allocated by the computer memory to hold data. In Visual Basic, it is a good
practice to declare the variables before using them by assigning names and data types. They are
normally declared in the general section of the codes' windows using the Dim statement.
Dim VariableName As DataType
Dim yourName As String
Dim firstnum As Integer
4. Define Constants.
Constants are different from variables in the sense that their values do not change during the running of
the program.
Constant Name As Data Type = Value
Const Pi As Single=3.142
5. List the built_in functions with example.
Rnd is is very useful function for dealing with the concept of chance and probability.
Print Rnd
Int is the function that converts a number into an integer by truncating its decimal part.
Int(0.032)=0
Log is the function that returns the natural Logarithm of a number. For example,
Log 10= 2.302585
6. How to declare multidimensional arrays in VB?
Dim a(2,3) as integer
2 represent rows
3 represents column
7. Define array.
An array is a set of values that are logically related to each other, such as the number of students in each
grade in a grammar school.
Declare a single-dimension array of 5 values
Dim numbers(4) As Integer
8. Write the syntax of inputbox function. Explain.
An InputBox( ) function will display a message box where the user can enter a value or a message in the
form of text. The format is
myMessage=InputBox(Prompt, Title, default_text, x-position, y-position)
THE QUAIDE MILLETH COLLEGE FOR MEN
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27

Partial preview of the text

Download VISUAL BASIC PROGRAMMING QUESTIONS AND ANSWERS and more Exercises Computer science in PDF only on Docsity!

V Semester-B.Sc, BISM, BCA Unit 1 Part A (2 Marks)

1. Write any three common properties for several visual basic controls. BackColor and ForeColor - The BackColor property sets the background color of an object while the ForeColor property changes the foreground color used to display text. Caption -It sets the text displayed in the object's title bar or on the object. Font -You can set the font property from the Properties Window. 2. What is toolbox? List the common collection of tools. Displays the standard Visual Basic controls plus any ActiveX controls and inser table objects you have added to your project. The tools in toolbox are label, textbox, combobox, option button, checkbox, command button. 3. Define Variables. How to declare variable variables are areas allocated by the computer memory to hold data. In Visual Basic, it is a good practice to declare the variables before using them by assigning names and data types. They are normally declared in the general section of the codes' windows using the Dim statement. Dim VariableName As DataType Dim yourName As String Dim firstnum As Integer 4. Define Constants. Constants are different from variables in the sense that their values do not change during the running of the program. Constant Name As Data Type = Value Const Pi As Single=3. 5. List the built_in functions with example. Rnd is is very useful function for dealing with the concept of chance and probability. Print Rnd Int is the function that converts a number into an integer by truncating its decimal part. Int(0.032)= Log is the function that returns the natural Logarithm of a number. For example, Log 10= 2. 6. How to declare multidimensional arrays in VB? Dim a(2,3) as integer 2 represent rows 3 represents column 7. Define array. An array is a set of values that are logically related to each other, such as the number of students in each grade in a grammar school. Declare a single-dimension array of 5 values Dim numbers(4) As Integer 8. Write the syntax of inputbox function. Explain. An InputBox( ) function will display a message box where the user can enter a value or a message in the form of text. The format is myMessage=InputBox(Prompt, Title, default_text, x-position, y-position)

THE QUAIDE MILLETH COLLEGE FOR MEN

9. What are image controls? The Image Box is another control that handles images and pictures. It functions almost identically to the picture box. Image1.Picture=LoadPicture ("C:\VBprogram\Images\grape.gif") 10. What are labels? The label is a very useful control for Visual Basic, as it is not only used to provide instructions and guides to the users, it can also be used to display outputs. One of its most important properties is Caption. 11. Write note on variant data type. A Variant is a special data type that can contain any kind of data except fixed-lengthString data. Dim a 12. Explain about the Text Box The text box is the standard control for accepting input from the user as well as to display the output. It can handle string (text) and numeric data but not images or pictures. Text1.text=”hai”.

  1. List the relational operator in VB. Operator Meaning = Equal to

    More than < Less Than = More than or equal <= Less than or equal <> Not Equal to **_____________________________________________________________________________________ Unit 1 Part B (5 Marks)

  2. Write the six form properties.** AutoSize

Resize the form according to the setting of AutoSizeMode.

BackColor

Gets or sets the background color for the control.

Font

Gets or sets the font of the text displayed by the control.

Name

Gets or sets the name of the control.

ResizeRedraw

Gets or sets a value indicating whether the control redraws itself when resized.

THE QUAIDE MILLETH COLLEGE FOR MEN

4. Explain about the form with its properties and methods.

Form is the work place in visual basic were the user can place controls in it the header area as a

caption. Control menu and maximums , minima’s closed button.

The large area of the form is called the client area in visual basic the basic building block of on

application is a form which is simple a window and controls like check box, text box, label etc..or

place in it….

Properties :-

Captions :- this properties set the title of the form by default the caption is form one.

Name:- the user can change the name of the form as per his wish by default form1. Is the name this

properties is used while writing codes

Appearance :- this properties desides the forms appearance like normal 2d,3d

Border style :- the border dstyle value ranges from 0 to 5.

  • -> none
  • 1-> fixed single
  • 2-> size able
  • 3-> fixed double
  • 4-> fixed tool window
  • 5-> sizeable tool window.

Font :- the user can set the font, font style and size by using this properties

Text Gets or sets the current text in the TextBox.

THE QUAIDE MILLETH COLLEGE FOR MEN

Height width :- this properties desides the height and width of a form.

Window state :- specified the state of the window like maximize minimize and normal

Events :-

Load :- this event is fixed when the form is loaded secondary memory to the primary memory

Unload :- this event is fired when the user closed the form.

Reseize :- respond to when the user resize the form.

Click :- respond to a mouse click.

Double click :- respond to a mouse double click

Change :- respond to when change is made on the controls.

Got focus :- fired when the controls received the input focus

Los focus :- fires when the control leaves the passes to another control

Key press :- respond when the user press a key

Key down :- respond when the user translate the key ansi numeric code

Key up :- respond when the user releases the key.

Mouse down :- fires when the user click the mouse

Mouse up :- fires when the user release the mouse

Mouse move :- fires when the user move the control

___________________________________________________________________________________

Unit 1 Part C (10 Marks)

1. Explain the VB controls and their uses with example.

THE QUAIDE MILLETH COLLEGE FOR MEN

2. Explain about the IDE of VB indetail.

Consist Of A Number Of Element Including Menu Bar, Title Bar, Tool Bar, Tool Box, Project Explorer And Properties Window. The Main Window In The Middle Of the Screen Contain A Form Named Form One The Form Is The Application Window Were The Uses Interfaces Can Be Placed Menu Bar :- The Menu Bar Contains The Command Needed To Works With Visual Basic File :- Contains The Command For Opening And Saving Projects Edit :- Contains Editing Commands And Other Formatting Tools View :- Contains Command For Showing Or Hiding Components Of Hide Project: - Contains Commands That Add Components To The Current Project Format:- Contains commands for aligning the control on the form Debug :- contains debugging tools Run :- contains commands start, break and end execution Query :- contains commands that simple the structure query language

THE QUAIDE MILLETH COLLEGE FOR MEN^ Project explorer

Project explorer displaced the components of the project. The user can switch over form code to design view and viz.. Properties windows

Properties windows displays the properties of a form on a control.properties Are artibutes of an object search as its size,name,captions and color. Form layout

The form layout window in the lower right corner of the vb IDE. It is use to determain the initial position form in the application this window is usefull for the application that use multipul forms Tool box :-

Tool box contains a set of controls with are used to customized form using this controls and interface between user and application can be created by default tool box contains 21 activex controls to place a control on a form select it with the mouse and then move the mouse over the form. And draw the control on the form. Otherway is just double click on the required controls. Pointer :- pointer is uded to interact with the controls on the form.

THE QUAIDE MILLETH COLLEGE FOR MEN

Form is the work places in visual basic were the user can place controls in it the header area as a caption. Control menu and maximums, minima’s closed button. The large area of the form is called the client area in visual basic the basic building block of on application is a form which is simple a window and controls like check box, text box, label etc..or place in it. __________________________________________________________________________________________

THE QUAIDE MILLETH COLLEGE FOR MEN

Unit II Part A (2 Marks)

1. Give the syntax of Instr function. InStr([start,]string1,string2[,compare]) Parameter Description start Optional. Numeric expression that sets the startingposition for each search. Default 1. string1 Required. String expression being searched. string2 Required. String expression searched for. compare Optional. Numeric value indicating the kind of comparison to use when evaluating substrings. 2. How to display information on a form? Print method is used to display information in a form. Formname.print”string expression” Form1.print”welcome” 3. Illustrate the concept of with statement. Executes a series of statements that repeatedly refer to a single object or structure so that the statements can use a simplified syntax when accessing members of the object or structure. With objectExpression [ statements ] End With 4. What are determinate loops?discuss with example. The For...Next construction performs the loop a set number of times. It uses a loop control variable, also called a counter or determinate lops , to keep track of the repetitions. 5. Define array. An array is a set of values that are logically related to each other, such as the number of students in each grade in a grammar school. Declare a single-dimension array of 5 values Dim numbers(4) As Integer 6. What are the two types of array? a. Fixed Dim a(5) as integer b. Dynamic Dimb() as integer 7. What are public variables? Public variable can be accessed globally in a project. Public con as string

THE QUAIDE MILLETH COLLEGE FOR MEN

Case Else result.Caption="Fail" End Select End Sub

2. Write note on looping statement in visual basic. Visual Basic allows a procedure to be repeated many times until a condition or a set of conditions is fulfilled. This is generally called looping. Looping is a very useful feature of Visual Basic because it makes repetitive works easier. There are two kinds of loops in Visual Basic, the Do...Loop and the For.......Next loop. Do Loop The Do Loop statements have three different forms, as shown below: a) Do While condition Block of one or more VB statements Loop b) Do Block of one or more VB statements Loop While condition c) Do Until condition Block of one or more VB statements Loop d) Do Block of one or more VB statements Loop Until condition Example: Do while counter <= num.Text=counter counter =counter+ Loop For....Next Loop The For....Next Loop event procedure is written as follows: For counter=startNumber to endNumber (Step increment) One or more VB statements Next Example: For counter=1 to 10 display.Text=counter Next The While….Wend Loop The structure of a While….Wend Loop is very similar to the Do Loop. it takes the following form: While condition Statements Wend

THE QUAIDE MILLETH COLLEGE FOR MEN

3. Write a short note on messagebox. The objective of MsgBox is to produce a pop-up message box that prompt the user to click on a command button before he /she can continues. This format is as follows: yourMsg=MsgBox(Prompt, Style Value, Title) The first argument, Prompt, will display the message in the message box. The Style Value will determine what type of command buttons appear on the message box, please refer Table 10.1 for types of command button displayed. The Title argument will display the title of the message board. Style Value Named Constant Buttons Displayed 0 vbOkOnly Ok button 1 vbOkCancel Ok and Cancel buttons 2 vbAbortRetryIgnore Abort, Retry and Ignore buttons. 3 vbYesNoCancel Yes, No and Cancel buttons 4 vbYesNo Yes and No buttons 5 vbRetryCancel Retry and Cancel buttons Example: Private Sub Test_Click() Dim testmsg As Integer testmsg = MsgBox("Click to test", 1, "Test message") If testmsg = 1 Then Display.Caption = "Testing Successful" Else Display.Caption = "Testing fail" End If End Sub 4. Explain the math function in visual basic. The mathematical functions are very useful and important in programming because very often we need to deal with mathematical concepts in programming such as chance and probability, variables, mathematical logics, calculations, coordinates, time intervals and etc. Visual Basic 6 function Description Abs Returns the absolute value of a specified number. Atn Returns a Double value containing the angle whose tangent is the specified number. Cos Returns a Double value containing the cosine of the specified angle. Exp Returns a Double value containing e (the base of natural logarithms) raised to the specified power. Log Returns a Double value containing the logarithm of a specified number. This method is overloaded and can return either the natural (base e)

THE QUAIDE MILLETH COLLEGE FOR MEN

= More than or equal <= Less than or equal <> Not Equal to Logical Operators In addition to conditional operators, there are a few logical operators that offer added power to the VB programs. Operator Meaning And Both sides must be true Or One side or other must be true Xor One side or other must be true but not both Not Negates truth

6. Explain the Date and Time functions in VB. Function Extracted Portion Year ( ) Year (Now) Month ( ) Month (Now) Day ( ) Day (Now) WeekDay ( ) WeekDay (Now) Hour ( ) Hour (Now) Minute ( ) Minute (Now) Second ( ) Second (Now) DateAdd ( ) Returns a date to which a specific interval has been added DateDiff ( ) Returns a Long data type value specifying the interval between the two values DatePart ( ) Returns an Integer containing the specified part of a given date DateValue ( ) Converts a string to a Date

THE QUAIDE MILLETH COLLEGE FOR MEN

TimeValue ( ) Converts a string to a time DateSerial ( ) Returns a date for specified year, month and day


Unit II Part C (10 Marks)

1. Explain the string function in visual basic. Functions Description Asc Returns an Integer value representing the character code corresponding to a character. Chr Returns the character associated with the specified character code. InStr Returns an integer specifying the start position of the first occurrence of one string within another. InStrRev Returns the position of the first occurrence of one string within another, starting from the right side of the string. Join Returns a string created by joining a number of substrings contained in an array. LCase Returns a string or character converted to lowercase. Left Returns a string containing a specified number of characters from the left side of a string. Len Returns an integer that contains the number of characters in a string. LTrim Returns a string containing a copy of a specified string with no leading spaces. Mid Returns a string containing a specified number of characters from a string. Replace Returns a string in which a specified substring has been replaced with another substring a specified number of times. Right Returns a string containing a specified number of characters from the right side of a string. RTrim Returns a string containing a copy of a specified string with no trailing spaces. Space Returns a string consisting of the specified number of spaces. Split Returns a zero-based, one-dimensional array containing a specified number of substrings. StrComp Returns -1, 0, or 1, based on the result of a string comparison. Trim Returns a string containing a copy of a specified string with no leading or trailing spaces. UCase Returns a string or character containing the specified string converted to uppercase. 2. Explain in detail about Function Procedures. A Function procedure is a series of Visual Basic statements enclosed by the Function and End Function statements. The Function procedure performs a task and then returns control to the calling code. When it returns control, it also returns a value to the calling code. Each time the procedure is called, its statements run, starting with the first executable statement after the Function statement and ending with the first End Function, Exit Function, or Return statement encountered.

THE QUAIDE MILLETH COLLEGE FOR MEN

x = Val(TxtNum1.Text) y = Val(TxtNum2.Text) sum x, y End Sub Sub sum(a As Single, b As Single) MsgBox ("sum=" & a + b) End Sub

THE QUAIDE MILLETH COLLEGE FOR MEN

UNIT 3

PART A(2 MARKS)

1. What is meant by object?explain An object is a combination of code and data that can be treated as a unit. An object can be a piece of an application, like a control or a form. An entire application can also be an object. 2. What is the use of refresh methos? Forces a complete repaint of a form or control. 3. List down the properties of line control. BorderColor (the color of the line) BorderStyle (the same as a form's DrawStyle property) BorderWidth (the same as a form's DrawWidth property) and DrawMode.


**UNIT 3 

PART C (10 MARKS)

  1. What is control array? How to create it? Explain** A control array is a group of controls that share the same name type and the same event procedures. Adding controls with control arrays uses fewer resources than adding multiple control of same type at design time. A control array can be created only at design time, and at the very minimum at least one control must belong to it. You create a control array following one of these three methods:
  • You create a control and then assign a numeric, non-negative value to its Index property; you have thus created a control array with just one element.
  • You create two controls of the same class and assign them an identical Name property. Visual Basic shows a dialog box warning you that there's already a control with that name and asks whether you want to create a control array. Click on the Yes button.
  • You select a control on the form, press Ctrl+C to copy it to the clipboard, and then press Ctrl+V to paste a new instance of the control, which has the same Name property as the original one. Visual Basic shows the warning mentioned in the previous bullet. Control arrays are one of the most interesting features of the Visual Basic environment, and they add a lot of flexibility to your programs:
  • Controls that belong to the same control array share the same set of event procedures; this often dramatically reduces the amount of code you have to write to respond to a user's actions.
  • You can dynamically add new elements to a control array at run time; in other words, you can effectively create new controls that didn't exist at design time.
    • The fact that multiple controls can share the same set of event procedures is often in itself a good reason to create a control array. For example, say that you want to change the background color of each of your TextBox controls to yellow when it receives the input focus and restore its background color to white when the user clicks on another field:
    • Private Sub Text1_GotFocus(Index As Integer) Text1(Index).BackColor = vbYellow End Sub Private Sub Text1_LostFocus(Index As Integer)

THE QUAIDE MILLETH COLLEGE FOR MEN