image

Solution of Assignment Synopsis & Project Dissertation Report


PRODUCT DETAILS

Online-Typing-and-Filling

Title Name Amity Solved Assignment BSC IT 2nd Sem for Visual Basic
University AMITY
Service Type Assignment
Course B.Sc-(IT)
Semister Semester-II Cource: B.Sc-(IT)
Short Name or Subject Code Visual Basic
Commerce line item Type Semester-II Cource: B.Sc-(IT)
Product Assignment of B.Sc-(IT) Semester-II (AMITY)

Solved Assignment


  Questions :-

                                                                                                                     Visual Basic                                                        

 Assignment A

1 . What do you understand by event driven programming? List and explain about some of the events supported by Visual Basic Objects.  
2 . What are the different data types supported by Visual Basic ? How they can be declared? Also mention their uses.  
3 . Give examples of passing arguments by value and passing arguments by reference in Visual Basic procedures.  
4 . Give difference between arrays and dynamic arrays. How they can be created in Visual Basic? Give Syntax.  
5 . What are the advantage of ADO Data Control ? Explain about different objects of ADO model.  
6 . Write a small hand calculator. Use command buttons for the number keys, the Enter key and the + key etc. Use a label to display the results.

 

 

 

Assignment B

CASE STUDY

1. Write a program using dynamic arrays to record the high temperatures of last seven days and to display all of them with the average of high temperatures. Use
three buttons on the screen, one to enter the temperature, second to display the result and third to exit from program. 
2. Develop a WordPad application using MDI forms, having basic features of File and Edit. 
3. Write an event procedure to automate the billing system of a supermarket. Give the details of database tables, forms, controls and menu design (if any). Make
assumptions, wherever necessary. 

 

 

 

Assignment C

1. VB is considered to be a

(A) First-generation language.

(B) Package.

(C) Higher-level language.

(D) Machine language

 

 

2. The person who actually runs a computer program is called a

(A) user.

(B) Customer.

(C) Client.

(D) Tester.

(E) Runner.

 

 

3. Programming in VB is different from most other programming environments because first you should

(A) Write the code.

(B) Input the data.

(C) Name the buttons.

(D) Draw the user interface.

 

 

4. GUI stands for

(A) Graphical user interface.

(B) Graphing user introduction.

(C) Graphical unit interface.

(D) Graphical user input.

 

 

5. Press F4 to

(A) Run a program.

(B) Display the Properties window.

(C) Display the Solution Explorer window.

(D) Terminate a program.

 

 

6. Which of the properties in a control´s list of properties is used to give the control a meaningful name?

(A) Text

(B) ContextMenu

(C) ControlName

(D) Name

 

 

7. When a VB program is running, the user can move from one control to another using the keyboard by pressing the

(A) Tab key.

(B) Space bar.

(C) Enter key.

(D) Backspace key.

 

 

8. Which of the following properties determines the words appearing in a form´s title bar?

(A) Text

(B) Caption

(C) Name

(D) Title

 

 

9. What effect will the following statement have? Label1.Visible = False

(A) Enable Label1

(B) Delete Label1

(C) Make Label1 invisible

(D) It is not a valid VB statement.

 

 

10. The Font dialog box allows you to select different Fonts, their style, their size, and some other special effects. How do you bring up this Font dialog box?

(A) In the Properties window, click the ellipsis (…) on the right side of the settings box for the Font property.

(B) Double-click the textbox, and select Font Property.

(C) Right-click the textbox, and select Font Property.

(D) None of the above.

 

 

11. What keyboard shortcut allows you to run the current program?

(A) F4

(B) F5

(C) F6

(D) F7

 

 

12. Which property is available for most controls that allows you to hide/unhide them either manually by setting the property or by setting it during runtime via code?

(A) Clear

(B) Refresh

(C) Visible

(D) View-Control

 

 

13. When the user clicks a button, _________ is triggered.

(A) An event

(B) A method

(C) A setting

(D) A property

 

 

14. Select the code statement that will set the current text color to Red.

(A) txtBox.ForeColor = "Red"

(B) txtBox.ForeColor = Red

(C) txtBox.ForeColor = Color.Red

(D) txtBox.ForeColor = "Color.Red"

 

 

15. The statement btnButton.Focus()

(A) Has no effect.

(B) Moves the focus to the button btnButton.

(C) Has the same effect as clicking on the button btnButton.

(D) is invalid in VB.

 

 

16. Which of the following statements sets the words on a button to "Submit Button"?

(A) btnButton.Name = "Submit Button"

(B) btnButton.Text = Submit Button

(C) btnButton.Text = " Submit Button"

(D) btnButton = " Submit Button "

 

 

17. A user action such as clicking a button is called:

(A) An accident

(B) an event

(C) A procedure

(D) A property

 

 

18. What is the correct statement when declaring and assigning the value of 100 to an Integer variable called commission?

(A) Dim commission = 100

(B) Dim commission = Int(100)

(C) Commission = 100

(D) Dim commission As Integer = 100

 

 

19. Which of the following statements removes all text from lstBox?

(A) lstBox.Clear()

(B) lstBox.Items.Clear()

(C) lstBox.Text.Clear()

(D) lstBox.Items.Add("")

 

 

20. Which statement will assign the words gHello Worldh to a text box?

(A) txtBox.Text = Hello & World

(B) txtBox.Text = "Hello " & World

(C) txtBox.Text = Hello & " World"

(D) txtBox.Text = "Hello" & " World"

 

 

21. What character is used to signify the beginning of a comment statement?

(A) Asterisk

(B) Exclamation mark

(C) Apostrophe

(D) Backslash

 

 

22. What will be displayed when the following lines are executed?

Dim x As Double = 2

´x = 3

txtBox.Text = CStr(x)

(A) 3

(B) 0

(C) 2

(D) None of the above

 

 

23. When an End Sub statement is reached in a Sub procedure, execution jumps to

(A) The statement before the call statement which invoked the Sub procedure.

(B) The statement after the call statement which invoked the Sub procedure.

(C) The beginning of the event procedure containing the call statement.

(D) The end of the event procedure containing the call statement.

 

 

24. Which one of the following is true about arguments and parameters?

(A) Arguments appear in call statements; parameters appear in Sub statements.

(B) Parameters appear in call statements; arguments appear in Sub statements.

(C) They are synonymous terms.

(D) They are completely unrelated in a program.

 

 

25. Items appearing in the parentheses of a call statement are known as____________.

(A) Call variables

(B) Call strings

(C) Parameters

(D) Arguments

 

 

26. Variables declared inside a procedure are said to have ________________.

(A) Local scope

(B) procedure-level scope

(C) class-level scope

(D) None of the above

 

 

27. Assume that A, B, and C are conditions, with A being true, B being true, and C being false. Give the truth value of each of the following conditions.

(a) A And (Not B) = False

(b) A And Not (B Or C) = False

(c) Not (A And B) = False

 

 

28. Consider the following two sets of code.

(a) If (a = 1) And (b = 1) Then (b) If a = 1 Then

txtBox.Text = "Hi" If b = 1 Then

End If txtBox.Text = "Hi"

End If

End If

Which one of the following statements is true?

(A) (a) and (b) will produce different outputs.

(B) (b) is not a valid set of VB instructions.

(C) The two sets of code are equivalent, but (a) is preferred to (b) because (a) is clearer.

(D) The condition statement in (a) is not valid.

 

 

29. What will be displayed by the following program when the button is clicked?

Private Sub btnDisplay_Click(...) Handles btnDisplay.Click

Dim a, b, c, x As Double

a = 5

b = 3

c = 6

If a > c Then

x = 1

Else

If b > c Then

11

x = 2

Else

x = 3

txtBox.Text = CStr(x)

End If

End If

End Sub

(A) 1

(B) 2

(C) 3

(D) None of the above.

 

 

 

30. If the loop is to be executed at least once, the condition should be checked at the __________.

(A) Top of the loop

(B) Middle of the loop

(C) Bottom of the loop

(D) Nothing should be checked

 

 

31. Suppose a variable is to tell whether or not the user wants further information. A good data type for such a variable is

(A) Boolean

(B) Integer

(C) Double

(D) String

 

 

32. VB uses an object called ____________ to hold a table.

(A) Record

(B) Recordset

(C) File

(D) Table

 

 

33. Which of these is not an collection of the VB project?

(A) The Global Module

(B) The form Module

(C) The object Module

(D) The class Module

 

 

34. Which of these is used to open an database?

(A) Set dbMyDB = OpenDatabase("MyDatabase.mdbh)

(B) dbMyDB = OpenDatabase("MyDatabase.mdb")

(C) Set dbMyDB = OpenDatabase None of these

(D) None of these

 

 

35. MDI stands for

(A) Multiple Document Interface

(B) Modular Document Interface

(C) Management Document Interface

(D) Multilingual Document Interface

 

 

36. Microsoft Notepad is __________ based application.

(A) SDI

(B) MDI

(C) Both

(D) None

 

 

37. The ________ Forms are forms from where user can switch to any other Forms in the application without closing it.

a. Modeless

b. Modal

c. Unique

d. None of the above

 

 

38. ODBC stands for

A. Open database connectivity

B. Other database connectivity

C. Optimistic database connectivity

D. Old database connectivity

 

 

39. Visual Basic uses the ______property to determine the control that would receive the focus next when a tab key is pressed.

a. TabIndex

b. TabFocus

c. Focus

d. IndexFocus

 

 

40. ______________ makes the compulsory declaration of all the variables.

a. Dim

b. Default

c. Option Explicit

d. None of the above

  Answers :-

                                                                                                                                                              VISUAL BASIC

Assignment A

Q1. What do you understand by event driven programming? List and explain about some of the events supported by Visual Basic Objects.

Answer: Visual Basic is an event driven programming language. Before proceeding to the next chapter, it is very important to have a good concept of event driven programming. The common events are Click, DblClick, Load, MouseMove, MouseDown, MouseUp, KeyPress, KeyUp, KeyDown, GotFocus, LostFocus etc.

When the user clicks, presses key or moves the mouse, the particular block of code of the corresponding event procedure is executed. Then the program behaves in a certain way. This is event driven programming. When you fire an event, the code in the event procedure is executed, and then visual basic does what the code in the event procedure instructs to do. For example, in the first sample program, when you click the Print button, click event is fired. Then the code in the click event procedure gets executed. The code instructs to print a text on the form. After that you see a text printed on the form. This is the concept of event driven programming. That means, the code is not executed from top to bottom but it works when the corresponding event procedure is invoked.

Example:

Write the following code in the DblClick event procedure of the form.

Private Sub Form_DblClick ()

    Print "You have double clicked"

End Sub

Output

When you double-click on the form, the DblClick event procedure of the Form object is invoked and the code in the DblClick event procedure is executed. As a result, the code instructs to print a text on the form.

 

 

 

Q2. What are the different data types supported by Visual Basic? How they can be declared? Also mention their uses.

Answer: There are a number of different data types supported by Visual Basic. The following chart illustrates the most common data types used in Visual Basic:

There are number of ways to declare variables, the Dim statement is the most commonly used to declare variables (think of Dim as short for dimension)

Here is the general form of a variable declaration:

Here are a couple of examples of a variable declaration:

Declare multiple variables of the same type with one declaration statement, as shown in the following example:

 

Rules for naming variables

  • The first character must be a letter or an underscore (_) character
  • Maximum 255 characters
  • Cannot contain spaces or periods
  • Must contain only letters, numbers and underscore character (_); NO PUNCTUATION!
  • Cannot contain Visual Basic keywords, such as If, Dim, Time, ElseIf, etc.

 

LOCAL VARIABLES

A variable declared at the beginning of a procedure is accessible to any statement in that procedure. This means that any statement in the procedure can refer to the variable, change its value, and so on. This variable is said to be local to the procedure because its scope is limited to that procedure. Statements outside the procedure do not have access to the variable.

 

 

Q3. Give examples of passing arguments by value and passing arguments by reference in Visual Basic procedures. Solve by www.solvezone.in

Answer: We have two choices regarding how arguments are passed to it: by reference or by value. Basically passes the variable´s address in memory to the procedure, which can modify it directly. When execution returns to the calling procedure, the variable contains the modified value.

When an argument is passed by value, VBA passes a copy of the variable to the procedure. Then, the procedure modifies the copy, and the original value of the variable remains intact; when execution returns to the calling procedure, the variable contains the same value that it had before being passed.

By default, VBA passes arguments by reference. To pass an argument by value, precede the argument with the ByVal keyword in the procedure definition, as shown here: 

Function SomeProc (strText As String, _

                  ByVal lngX As Long) As Boolean

 

We can preface the argument with the By Ref keyword in the argument list, if want to denote explicitly that an argument is passed by reference.

Passing by reference can be useful as long as we understand how it works. For example, we must pass arrays by reference; we will get a syntax error if we try to pass an array by value. Because arrays are passed by reference, we can pass an array to another procedure to be modified, and then we can continue working with the modified array in the calling procedure.

 

 

Q4. Give difference between arrays and dynamic arrays. How they can be created in Visual Basic? Give Syntax.

Answer: Dynamic arrays difference from fixed arrays because a subscript ranges for the array elements is not specified when the array is dimensioned. Instead, the subscript range is set using the ReDim statement. With dynamic arrays, the number of array elements can be set based on other conditions in your procedure. For example, you may want to use an array to store a set of values entered by the user, but you may not know in advance how many values the user will enter. In this case, you dimension the array without specifying a subscript range and then execute a ReDim statement each time the user enters a new value. Or you may want to prompt for the number of values to be entered and execute one ReDim statement to set the size of the array before prompting for the values.

If use ReDim to change the size of an array and want to preserve the contents of the array at the same time, be sure to include the Preserve argument to the ReDim statement:

Redim Preserve Array Name (n)

The following procedure uses a dynamic array, varray, to hold cash flow values entered by the user:

Sub main

   Dim aprate as Single

   Dim varray() as Double

   Dim cflowper as Integer

   Dim msgtext as String

   Dim x as Integer

   Dim netpv as Double

   cflowper= 2

   ReDim varray (cflowper)

   For x= 1 to cflowper

   Varray (x) =500

   Next x

   aprate= 10

   If aprate>1 then

      aprate= aprate/100

   End If

   netpv= NPV(aprate,varray())

   msgtext="The net present value is: "

   msgtext = msgtext & Format(netpv, "Currency")

   TheApplication.raiseErrorText msgtext

End Sub

 

 

Q5. What are the advantage of ADO Data Control? Explain about different objects of ADO model.

Answer: There are few advantages of ADO over data control:

  • ADO is faster with most databases compared to data control.
  • ADO separates Data handling and Database Structure manipulation, hence it’s easier to protect the database for corruption.
  • It supports Hierarchical record-sets and allows to close a connection and still work with a record set

 

Making ADO objects less dependent on each other has interesting and useful consequences besides just conceptual clarity: As a consequence of the example just given, you can create an ADO Record set object that never has to be connected to an existing data source—and you can therefore use such a disconnected Record set to track and maintain virtual data created entirely within your application or to maintain data from a database offline.

  • ADO provides the programmer more opportunities to finetune the data cursor of a Record set. A data cursor (or just a "cursor") represents a set of resources initiated by a data connection that provides a connection to a specific row in a set of data. The data cursor can change position to point to a different row of data. ADO enables you to directly specify where the cursor is implemented (client or server side) and several different types of cursors.
  • ADO provides better overall performance than earlier object models.
  • ADO is more resource-efficient than earlier object models.
  • ADO provides more universal data access, due to the universal nature of its underlying standard, OLE DB.

 

Following are the objects exposed in the ADO object model:

  • Connection object. Specifies information about the physical connection with a data source.
  • Command object. Stores information about actions performed on the data, such as data modification and retrieval. You can use a Command object to execute actions on the data or to return data from the server in a Record set object.
  • Record set object. Provides a rich selection of properties, events, and methods to expose data in a field-row format, and thus allows you to programmatically traverse, examine, and manipulate specific fields in specific rows of data.
  • Parameters collection of the Command object (made up of Parameter objects). Contains information about parameter values that are passed by a Command object.
  • Fields collection of the Record set object (made up of Field objects). Contains information about field structure and content of the data in a Record set object.
  • Properties collection (made up of Property objects). Contains information about provider-specific properties of Command and Parameter objects.
  • Errors collection of the Connection object (made up of Error objects). Contains information about the most recent error that occurred when attempting an ADO operation.

 


 

Assignment B

Question 1: Write a program using dynamic arrays to record the high temperatures of last seven days and to display all of them with the average of high temperatures. Use three buttons on the screen, one to enter the temperature, second to display the result and third to exit from program.

Answer: Here an example in VBA (Visual Basic for Application - Office):

Steps to do:

1) Open MS Excel (new workbook is created)

2) Use ALT+F11 to go to MS Visual Basic for App COde Editor

3) Use Menu: Insert->User Form

4) Add controls to User Form:

- 1x List Box (change property "Name" to LstTemp

- 3x Command Buttons (change property "Name" to: CmdAddTemp, CmdDisplay, CmdExit)

- 1x Textbox (change property "Name" to: TxtAvgTemp)

5) Copy code below

6) Paste it into User Form module

7) Have a fun Wink | ;)

 

´declare variables

Option Explicit

´set arrays low bound = 0

Option Base 0

´array to store temp

Dim a Temp() As Single

´

Dim iArr As Integer

Private Sub UserForm_Initialize()

´coz array start from 0 (zero)

iArr = 0

End Sub

Private Sub CmdAddTemp_Click()

Dim sTemp As String

´on error goto error handler

On Error GoTo Err_CmdAddTemp_Click

´display inputbox

sTemp = InputBox("Enter temperature", "Enter value...", "0")

´when Cancel button was pressed

If sTemp = "" Then GoTo Exit_CmdAddTemp_Click

´change array size

ReDim Preserve aTemp(iArr + 1)

´check for numeric value using convertion

´when it´s not numeric go to error handler

aTemp(iArr + 1) = CSng(sTemp)

´get new array size

iArr = UBound(aTemp)

´add temperature on the end of list

Me.LstTemp.AddItem sTemp

´exit sub

Exit_CmdAddTemp_Click:

    Exit Sub

´error handler

Err_CmdAddTemp_Click:

    ´catch all errors including convertion errors

    Select Case Err.Number

        Case 13 ´can´t convert value to single

            MsgBox "Enter corect value of temperature!", vbExclamation, "Error no. " & Err.Number

        Case Else

            MsgBox Err.Description, vbExclamation, "Error no. " & Err.Number

    End Select

    Resume Exit_CmdAddTemp_Click

   

End Sub

Private Sub CmdDisplay_Click()

Dim i As Integer, avgTemp As Single

´sum temperature

For i = LBound(aTemp) To UBound(aTemp)

    avgTemp = avgTemp + aTemp(i)

Next i

´divide by array size to get average temperature

avgTemp = avgTemp / UBound(aTemp)

´display returned value

Me.TxtAvgTemp = avgTemp

End Sub

 

 

Q2. Write a small hand calculator. Use command buttons for the number keys, the Enter key and the + key etc. Use a label to display the results.

Answer: The logic is fairly simple:

  • For 0-9: The content of the textbox gets appended as soon as you press any of these keys.
  • For +,-,*,/ : The content of the textbox (Operand 1) is stored in a variable and the textbox is cleared to enable the user to enter the second operand.
  • For decimal: If the textbox is empty then "0." is appended else simply a decmal.
  • For Eqaul: the entire logic is on pressing the = key...The result of the calculation is displayed in the text box using switch case.

CODE

Dim i As Integer

Dim a, b As Double

Private Sub Command1_Click()

´1

Text1.Text = Text1.Text + "1"

End Sub

 

Private Sub Command2_Click()

´2

Text1.Text = Text1.Text + "2"

End Sub

 

Private Sub Command3_Click()

´3

Text1.Text = Text1.Text + "3"

End Sub

 

Private Sub Command4_Click()

´4

Text1.Text = Text1.Text + "4"

End Sub

 

Private Sub Command5_Click()

´5

Text1.Text = Text1.Text + "5"

End Sub

 

Private Sub Command6_Click()

´6

Text1.Text = Text1.Text + "6"

End Sub

 

Private Sub Command7_Click()

´7

Text1.Text = Text1.Text + "7"

End Sub

 

Private Sub Command8_Click()

´8

Text1.Text = Text1.Text + "8"

End Sub

 

Private Sub Command9_Click()

´9

Text1.Text = Text1.Text + "9"

End Sub

 

Private Sub Command10_Click()

´0

Text1.Text = Text1.Text + "0"

End Sub

 

 

Private Sub Command11_Click()

´ON

Text1.Text = ""

Text1.SetFocus

End Sub

 

 

Private Sub Command12_Click()

´DECIMAL

If Text1.Text = "" Then

Text1.Text = Text1.Text + "0."

Else

Text1.Text = Text1.Text + "."

End If

End Sub

 

Private Sub Command13_Click()

´+

i = 1

a = Val(Text1.Text)

Text1.Text = ""

Text1.SetFocus

End Sub

 

Private Sub Command14_Click()

´-

i = 2

a = Val(Text1.Text)

Text1.Text = ""

Text1.SetFocus

End Sub

 

Private Sub Command15_Click()‘*

i = 3

a = Val(Text1.Text)

Text1.Text = ""

Text1.SetFocus

End Sub

 

Private Sub Command16_Click()

´/

i = 4

a = Val(Text1.Text)

Text1.Text = ""

Text1.SetFocus

End Sub

 

Private Sub Command17_Click()

´EQUALS

If i = 1 Then

 b = Val(Text1.Text)

   Text1.Text = a + b

End If

 

If i = 2 Then

 b = Val(Text1.Text)

 Text1.Text = a - b

End If

 

If i = 3 Then

 b = Val(Text1.Text)

 Text1.Text = a * b

End If

 

If i = 4 Then

 b = Val(Text1.Text)

 Text1.Text = a / b

End If

 End Sub

 

 

 

Q3. Develop a WordPad application using MDI forms, having basic features of File and Edit.

Answer: To Develop an MDI Application take the following steps (Describe with details in Page 12 to 22 Pages):

1. Create a new project using File -> New Project and select Standard Exe as the type of the project.
2. At this stage a new project is created with just one form. The form that is created by Visual Basic is a normal form. But as our application is based on MDI, it needs an MDIForm. 
3. Add an MDIForm to project using Project -> Add MDIForm.
4. Visual Basic adds an MDIForm to the current project.
5. After MDIForm is added to current project, Add MDIForm option in Project menu will be disabled. Remember there can be only one MDIForm in a Visual Basic project.

Adding Menu to Application
Add required menus to MDIForm by following the steps below.

1. Make MDIForm active form in the project.
2. Select Tools->Menu Editor
3. Add the following menu using Menu Editor 

File 
New Creates a new document. It creates a new child form and displays empty window.
Open… F3 Allows user to select a text file. Creates a new child window and displays the contents of the text file for editing in that window. 
Close closes the currently active document. Takes confirmation before closing a document, if document was modified but not saved.
Save F2 Saves changes made to current document. If current document is a new document, it will prompt user to enter a filename using Save As dialog box.
Save As Allows current document to be saved under a different filename.
Print Prints the current document to printer.
Exit terminates the application. Takes confirmation before the application is terminated.

Edit 
Cut Ctrl + X Cuts the selected text in the current document and places the text on the clipboard.
Copy Ctrl + C Copies the selected text in the current document to clipboard.
Paste Ctrl + V Extracts text from clipboard and pastes it into current document.

Window 
Cascade F5 Arranges all open windows using cascade format, where title bars of all open windows will be displayed.
Tile Horizontal Tiles all open windows horizontally.
Tile Vertically Tiles all open windows vertically.
Arrange Icons Arranges all minimized windows.
Windows list Displays captions of all open child forms.

Help 
About Displays about dialog box.


Displaying Window List 
One of the common features of an MDI application is Window menu displaying list of open windows. For example, in MS-Word, you get the list of open documents at the end of the window menu. Visual Basic IDE is also an MDI application. If you see Window menu of Visual Basic IDE while working with a project. As you can see at the Window Menu the list of open windows are displayed

To display windows list in MDI application:

1. Invoke Menu Editor of MDIForm using Tools -> Menu Editor when MDIForm is active
2. Select Window menu in the list of menu. As we want to display list of windows at the bottom of Window menu.
3. Turn on WindowList checkbox
That’s all you have to do to display the list of windows at the bottom of Window menu. Visual Basic takes care of adding and removing windows from the list as you open and close documents. 

Enabling the display of list of windows at the bottom of Window menu

Making Form1 MDIChild form
Now our project contains two forms – MDIForm1 and Form1. MDIForm1 is the parent that forms the base for the application. Form1 is the form that displays the contents of the file and allows user to edit. We take multiple copies of Form1 at run time to display multiple documents. In order to display copies of Form1 within MDIForm1, first we have to make Form1 a child form.

To make Form1 an MDI Child form:

1. Invoke Properties Window of Form1 by selecting the form and pressing F4.
2. Change MDIChild property to True.

Child form will display the contents of the selected file and also allows user to edit the contents. To display the contents of the selected file, we place a text box in child form. The textbox will occupy the entire client area of the child form and it also contains scrollbars to allow user to scroll.

Place a textbox and change its property as follows.

1. Place a textbox on the form. The position and size of the textbox are not so important because they are changed at run time using Resize event (see listing 12.1) of the form so that textbox occupies the entire client area of the form.

Private Sub Form_Resize() ‘Make textbox occupy the entire client area’.
Text1.Move 0, 0, Me.ScaleWidth, Me.ScaleHeight
End Sub
Listing 12.1: Filling the entire client area of the form using resize event of the form.

2. Change the MultiLine property to True, and Scrollbars property to 3-both.

Changing Startup Object of the Project
If you run the project now, Form1 will be displayed as the first form. But we want MDIForm to be displayed first. To display MDIForm1 as the first form in the project we have to change Startup Object property of the project.

To change startup object:

1. Select Project -> Project Properties (In place of Project in Project Properties option, the name of the current project name is displayed).
2. Visual Basic displays project properties dialogbox .
3. Select General tab if it is not selected.
4. From Startup object drop down, select MDIForm1 to make MDIForm1 the startup object.
5. Click on Ok to close properties dialogbox.
Now, if you run the project, MDIForm1 will be displayed as the first form 

Writing code for Options in File menu
The following section will explain the code for options of File menu.

Writing code for New option
We will now write code for New option of File menu. When user selects New option from File menu a new window is to be displayed so that user can start typing text. Subsequently, if user chooses Save option then the typed contents will be saved under the given name. 

New option creates a new copy of Form1 and displays that copy with Noname as the caption of the form. As we have to prompt user, if user is trying to close the document without saving changes, we use Tag property of the form. Tag property of the form will be set to 0 in the beginning. Tag property is set to 1 whenever user makes a change to the content. Again Tag is set to 0 when user saves changes. That means at the time of closing document if Tag is set to 1, it means user is trying to close a document that was modified but not saved. In this case, program has to prompt user to save pending changes. We will create code for close option later.

Here is code for new option.

Private Sub mnunew_Click()
Dim f As New Form1 ‘ create a new copy of Form1
f.Caption = "Noname"
f.Tag = 0 ´ not modified
f.Show ‘ display form
End Sub
Listing 12.2: Code for new option of file menu.

Writing code for Open Option
For this option, as we have to prompt the user to select a filename. First of all to use open dialog, we have to load common dialog control into project.

To load common dialog control:
1. Select Project-> Components
2. Move down until you get to Microsoft Common Dialog Control 6.0 and select it (turn on the checkbox). 
3. Click on Ok button
Visual Basic places the control in Toolbox.
4. Place common dialog control on MDIForm1.
Open option of File menu does the following:

• Accepts a filename from user through Open common dialog box.
• Creates a new instance of Child form (Form 1).
• Loads the content of selected file into the text box of child form.
• Displays the child form.
Here is the code for Open option of File menu.
Private Sub mnuopen_Click()
‘Create a New instance of form
Dim nf As New Form1
Dim oneline As String, filecontent As String

´ trap error that might occur
On Error GoTo errlbl

´ display open dialog box to user
With CommonDialog1
.Filter = "Text files|*.txt|All files|*.*"
´cause error if user doesn´t select any file
.CancelError = True
.ShowOpen
´ user has selected a file. Read the content and display content
´ in textbox
´ change mouse pointer to indicate system is busy
Screen.MousePointer = vbHourglass
´ open file
Open .FileName For Input As #1

Do Until EOF(1)
´ read one line at a time
Line Input #1, oneline
´ concatenate line along with new line to lines read so far
filecontent = filecontent & oneline & vbCr & vbLf
Loop
Close #1

´ load the text into textbox of child form
nf.Text1 = filecontent
´ set Tag to 0 to indicate that content is not modified
nf.Tag = 0
´ change caption to file name
nf.Caption = .FileName
´display child form
nf.Show
´ reset mouse pointer
Screen.MousePointer = vbDefault
End With

Exit Sub

errlbl:
´ ignore the error and free memory allocation to nf and quit
Set nf = Nothing
End Sub 
Listing 12.3: Code for Open option of File menu.


Writing code for Save and Save As options
Save option saves the changes made to current form. If current form contains a new document (with caption property set to Noname) then Save option works like Save As, otherwise Save saves the changes made to current document. 

Save As prompts the user to enter a new filename and then saves the contents in the new filename.
This is also invoked by Save option when user is saving a new document.

As both Save and Save As options write the document into a file, it is better to implement code as a separate procedure. 

General procedures such as SaveFile in this case, are accessed generally from more than one form. So it is better to create a code module and place all such general procedures into code module because procedure placed in code module can be accessed through the project. 

Creating SaveFile procedure in Code module
First let us create a new code module and then create a SaveFile procedure in code module.

To add a code module to project:

1. Select Project -> Add Module.
2. Visual Basic adds a code module to project with default name Module1.

To create SaveFile procedure:

1. Make code module active.
2. Select Tools -> Add Procedure option.
3. When Visual Basic displays Add Procedure dialog box, enter SaveFile as the name of the procedure and click on Ok.
4. In code window enter the code shown in listing.

Public Sub SaveFile(fn As String, content As String)
Open fn For Output As #1
Print #1, content
Close #1
´ set tag property to 0 to indicate that
´ changes are saved
MDIForm1.ActiveForm.Tag = 0
End Sub
Listing 12.4: Code for SaveFile procedure.

The following is the code for Save and Save As options.

Private Sub mnusave_Click()
´ call Save As if name of the file is Noname
With MDIForm1.ActiveForm
If .Caption = "Noname" Then
´ call save as
mnusaveas_Click
Else
SaveFile .Caption, .Text1.Text
End If
End With

End Sub

Private Sub mnusaveas_Click()

´trap error that might occur
On Error GoTo errlbl

´display save as dialog box to user
With CommonDialog1
´ set the file name as the default
.FileName = MDIForm1.ActiveForm.Caption
.Filter = "Text files|*.txt|All files|*.*"
´cause error if user doesn´t any file
.CancelError = True
.ShowSave
´ set new file to caption
MDIForm1.ActiveForm.Caption = .FileName
´ save file contents to new filename
SaveFile .FileName, MDIForm1.ActiveForm.Text1.Text
End With

Exit Sub

errlbl:
´ignore errors and continue
End Sub
Listing 12.5: Code for Save and Save As options of File menu.

As you can see from the code, both these event procedures make use of SaveFile procedure created in code module.

Note: ActiveForm property of MDIForm refers to the form that is currently active among child forms.

Code for Close option of File menu
Whenever user chooses Close option from File menu, the active form is to be closed. But if active form has modifications that were not saved then you should prompt the user to save the modifications. 

Clicking on close button (X) may also close a child form. In this case also user should be prompted to save modifications. 

Prompting user to save changes using QueryUnload event
QueryUnload event occurs just before a form is unloaded. QueryUnload event can cancel unloading form if you set Cancel parameter to True. We use QueryUnload event to prompt the user and take necessary action, as this event occurs in both cases – user clicking on close button of the form and form is getting unloaded because of program executing Unload statement. The second method is used for Close option of File menu.

The following is the code for Close option of file menu.

Private Sub mnuclose_Click()
´ unload active form
Unload MDIForm1.ActiveForm

End Sub
Listing 12.6: Code for close option of file menu.

The following is the code for Change event of Text box in child form. This event occurs whenever text in the textbox changes. At this event we set Tag property of the form to 1 to indicate the content of the textbox has changed.

The final in this context is the code for QueryUnload event of the child form.

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

´ check whether changes are pending
If Me.Tag = 1 Then
´ display confirmation box
resp = MsgBox("Do you want to save changes?", vbYesNoCancel _
+ vbQuestion, "Save Changes")
‘ if user has selected Cancel button 
If resp = vbCancel Then
´ cancel unload process
Cancel = True
‘ if user has selected Yes to save changes
ElseIf resp = vbYes Then ´ save changes and then quit
SaveFile Me.Caption, Text1.Text
End If
End If
End Sub
Listing 12.7: Code for Queryunload event of form.


Private Sub Text1_Change()
´ change tag property to indicate modification
Me.Tag = 1
End Sub
Listing 12.8: Code for change event of text box.

The prompt displayed by MsgBox function will be identical 

Message box displayed when user tries to quit without saving changes.

The following will be the action taken for each of the buttons.

Yes Saves the modification and then closes the form.
No Closes the form without saving the modifications.
Cancel Cancels closing process.

Writing code for Print option in File menu
Print option prints the contents of current document to default printer. Printer object is used to print to default printer.

Here is the code to print current document.

Private Sub mnuprint_Click()
´ print current document to printer object
Printer.Print MDIForm1.ActiveForm.Text1.Text
Printer.EndDoc
End Sub
Listing 12.9: Code for print option of file menu.

Writing code for Edit menu
Code for edit menu is much like the code that we have written in chapter 11 for clipboard object. I do not feel any need to explain the code here. For details, please see chapter 11(System Objects).

The code for Cut, Copy and Paste options and Edit menu is given in listing 12.10.

Private Sub mnuedit_Click()

´ disable all options
mnucut.Enabled = False
mnucopy.Enabled = False
mnupaste.Enabled = False

If MDIForm1.ActiveForm.Text1.SelText <> "" Then
´ disable all options
mnucut.Enabled = True
mnucopy.Enabled = True
End If

If Clipboard.GetFormat(vbCFText) Then
mnupaste.Enabled = True
End If
End Sub

Private Sub mnucopy_Click()
´copy the selected text on to clipboard
Clipboard.SetText MDIForm1.ActiveForm.Text1.SelText
End Sub

Private Sub mnucut_Click()
´copy the selected text on to clipboard
Clipboard.SetText MDIForm1.ActiveForm.Text1.SelText
´cut the selected text
MDIForm1.ActiveForm.Text1.SelText = ""
End Sub

Private Sub mnupaste_Click()
´Place the text that is existing in clipboard at
´the cursor position
MDIForm1.ActiveForm.Text1.SelText = Clipboard.GetText
End Sub
Listing 12.10: Code for Edit menu and its options.


Writing code for Window menu
All options in window menu make use of Arrange method of MDIForm. Arrange method is used to arrange child forms of MDIForm in the specified format. Here is the complete syntax of Arrange method.

Arrange arrangement

The arrangement may be any of the values given below.

Constant Value Description 
vbCascade 0 Cascades all nonminimized MDI child forms
vbTileHorizontal 1 Tiles all nonminimized MDI child forms horizontally
vbTileVertical 2 Tiles all nonminimized MDI child forms vertically
vbArrangeIcons 3 Arranges icons for minimized MDI child forms

Here is the code for options in Window menu.
Private Sub mnucascade_Click()
MDIForm1.Arrange vbCascade
End Sub

Private Sub mnuth_Click()
MDIForm1.Arrange vbTileHorizontal
End Sub

Private Sub mnutv_Click()
MDIForm1.Arrange vbTileVertical
End Sub

Private Sub mnuai_Click()
MDIForm1.Arrange vbArrangeIcons
End Sub

Listing 12.11: Code for options in Window menu.

Creating About dialog box
Visual Basic provides a template for About dialog box. All you have to do is change the required properties of labels that are placed in the about dialog box. This is the process to add about dialog box to the project.

To add About dialog box to project:

1. Select Project -> Add Form.
Visual Basic displays a list of predefined forms. 
2. Select About dialog and click on Open button.
Visual Basic adds an about dialog to current project and form is given name frmAbout. 
At design time, About dialog box that is added 

To invoke About dialog box:

Write code for click event of About option in Help menu. About dialog box is to be displayed as a modal window (by using vbModal option for Show method).

Private Sub mnuabout_Click()
frmAbout.Show vbModal
End Sub
Listing 12.12: Code to invoke about dialog box.

Note: About dialog box takes properties of current project and fills some of the labels on the form. We have to fill the remaining with the required information.

Test Run 
Now we have reached the end of the development. Now it is time to run the application and test all its features.

1. Run project using Run-> Start option or F5 or by clicking on Start icon in toolbar.
2. When Visual Basic displays MDIForm, choose File->New option to create a new document. Enter some text in the text box.
3. Now try to save this document by pressing F2 or by selecting File -> Save. 
4. As the document is new document, Save option will prompt you to enter the name of the file in which the document is to be saved. 
5. Enter filename Sample.txt.
6. Close the file by choosing File->Close.
7. Open the file sample.txt using File-> Open.
8. Enter one more line to the document.
9. Try to close the file using File->Close. As we are trying to close without saving the changes, program displays message box prompting you to save changes.
10. Choose Cancel to cancel closing operation.
11. This time click on Close button of the child form.
12. This will also result in the same prompt. Select Yes button in message box to save changes and then quit.
13. Now choose File->New options for a few times to create a few new MDI child windows.
14. Choose Window->Tile Vertical to file windows vertically.
At this stage MDIForm .
15. Exit MDIForm using File->Exit.

 


Q4. Write an event procedure to automate the billing system of a supermarket. Give the details of database tables, forms, controls and menu design (if any). Make assumptions, wherever necessary.

Answer: Supermarkets are getting crowded these days at the billing area and lot of time is being consumed for billing the products. Also at the counter the person responsible must go through the whole items which have been taken by the customers, it would be a time consuming process. Presently supermarket use barcodes. Regarding the barcodes, generally, a barcode is made up of a series of black and white lines. The cash register uses the data from the code to identify the item and look up its latest price and print the information on the customer’s receipt. Bar codes are commonly used to store data such as prices and stock codes relating to products in the supermarkets.

Details of Database tables, Forms, Controls and Menu Design

ORACLE 10G

Oracle Database 10g is the first database designed for grid computing, the most flexible and cost-effective way to manage enterprise information. It cuts costs of management while providing the highest possible quality of service.

In addition to providing numerous quality and performance enhancements, Oracle Database 10g significantly reduces the costs of managing the IT environment, with a simplified install, greatly reduced configuration and management requirements, and automatic performance diagnosis and SQL tuning.

JDBC (JAVA DATABASE CONNECTIVITY)

JDBC technology is an API(included in both J2SE and J2EE releases) that provides cross DBMS connectivity to a wide range of SQL database and access to other tabular data sources, such as spreadsheets or flat files.

The JDBC API makes it possible to do three things:

  • Establish a connection with a database or access any tabular data source
  • Send SQL statements
  • Process the results

RFID TECHNOLOGY

The system aims to trace the position of workers, vehicle and machineries with the help of RFID Technology. With the help of Tomcat Server, the administrator maintains all the details of the workers, vehicle and machineries. Radio-frequency identification (RFID) is the use of an object (typically referred to a san RFID tag) applied to or incorporated into a product, animal, or person for the purpose of identification and tracking using radio waves. Some tags can be read from several meters away and beyond the line of sight of the reader. Radio-frequency identification comprises readers and tags. The chip can store as much as 2 kilobytes of data. To retrieve the data stored on an RFID tag, you need a reader.

 

HARDWARE INTERFACE:

Client Side Mobile Phone, which is Access the Internet and Application

Server Side     RAM: 256 MB or more

                        Hard disk: 40 GB hard disk recommended.

                        Tools: RFID Reader, RFID Tag

 

SOFTWARE INTERFACE:

Client Side

            Programming language: java1.5 or jdk5, j2me

            Tools: J2ME toolkit2.5.2.

            Operating system: Windows XP or later

            Technology: Java 2 Micro Edition (J2ME)

 

Server Side

            Front End

                        Operating system: Windows XP or later

                        Technology: JDBC.

                        Tools: Net Beans IDE 6.9.1

            Back End

                        Database: Oracle 10g

                        Server: Apache Tomcat 6.0

 

COMMUNICATION INTERFACE: GPRS, RFID Reader, RFID Tag.

DESIGN

Design is the first step in the development phase for any engineering product or system. It may be defined as a "the process of applying various techniques and principles for the purpose of defining a device, a process, or a system insufficient detail to permit its physical realization". Software design is an iterative process through which requirements are translated into a "blue print" for the constructing software. The design is represented at high level of abstraction, a level that can be directly translated to a specific data, functional behaviour requirements.

 

INPUT DESIGN

Input design is the process of converting user-oriented input to a computer based format. Input design is a part of overall system design, which requires very careful attention. Often the collection of input data is the most expensive part of the system. The main objectives of the input design are? Produce cost effective method of input? Achieve highest possible level of accuracy? Ensure that the input is acceptable to and understood by the staff.

 

OUTPUT DESIGN

Outputs from computer systems are required primarily to communicate the results of processing to users. They are also used to provide a permanent copy of these results for latter consultation. Computer output is the most important and direct source of information to the users.

 

DATA FLOW DIAGRAM

USER REGITRATION

PRODUCT SEARCH

BILL PAYMENT

DATABASE DESIGN

DATABASE TABLE

 

 


 

Assignment C

  1. VB is considered to be a

(A) First-generation language.

(B) Package.

(C) Higher-level language.

(D) Machine language

 

 

  1. The person who actually runs a computer program is called a

(A) user.

(B) Customer.

(C) Client.

(D) Tester.

(E) Runner.

 

 

  1. Programming in VB is different from most other programming environments because first you should

(A) Write the code.

(B) Input the data.

(C) Name the buttons.

(D) Draw the user interface.

 

 

  1. GUI stands for

(A) Graphical user interface.

(B) Graphing user introduction.

(C) Graphical unit interface.

(D) Graphical user input.

 

 

  1. Press F4 to

(A) Run a program.

(B) Display the Properties window.

(C) Display the Solution Explorer window.

(D) Terminate a program.

 

 

  1. Which of the properties in a control´s list of properties is used to give the control a meaningful name?

(A) Text

(B) ContextMenu

(C) ControlName

(D) Name

 

 

  1. When a VB program is running, the user can move from one control to another using the keyboard by pressing the

(A) Tab key.

(B) Space bar.

(C) Enter key.

(D) Backspace key.

 

 

  1. Which of the following properties determines the words appearing in a form´s title bar?

(A) Text

(B) Caption

(C) Name

(D) Title

 

 

  1. What effect will the following statement have? Label1.Visible = False

(A) Enable Label1

(B) Delete Label1

(C) Make Label1 invisible

(D) It is not a valid VB statement.

 

 

  1. The Font dialog box allows you to select different Fonts, their style, their size, and some other special effects. How do you bring up this Font dialog box?

(A) In the Properties window, click the ellipsis (…) on the right side of the settings box for the Font property.

(B) Double-click the textbox, and select Font Property.

(C) Right-click the textbox, and select Font Property.

(D) None of the above.

 

 

  1. What keyboard shortcut allows you to run the current program?

(A) F4

(B) F5

(C) F6

(D) F7

 

 

  1. Which property is available for most controls that allows you to hide/unhide them either manually by setting the property or by setting it during runtime via code?

(A) Clear

(B) Refresh

(C) Visible

(D) View-Control

 

 

  1. When the user clicks a button, _________ is triggered.

(A) An event

(B) A method

(C) A setting

(D) A property

 

 

  1. Select the code statement that will set the current text color to Red.

(A) txtBox.ForeColor = "Red"

(B) txtBox.ForeColor = Red

(C) txtBox.ForeColor = Color.Red

(D) txtBox.ForeColor = "Color.Red"

 

 

  1. The statement btnButton.Focus()

(A) Has no effect.

(B) Moves the focus to the button btnButton.

(C) Has the same effect as clicking on the button btnButton.

(D) is invalid in VB.

 

 

  1. Which of the following statements sets the words on a button to "Submit Button"?

(A) btnButton.Name = "Submit Button"

(B) btnButton.Text = Submit Button

(C) btnButton.Text = " Submit Button"

(D) btnButton = " Submit Button "

 

 

  1. A user action such as clicking a button is called:

(A) An accident

(B) an event

(C) A procedure

Review

Average user rating

4.8 / 5

Rating breakdown

5
80% Complete (danger)
1
4
80% Complete (danger)
1
3
80% Complete (danger)
0
2
80% Complete (danger)
0
1
80% Complete (danger)
0

January 29, 2015
This was nice in buy
Assignment from solve zone is probably one of the first preference of students.

October 09, 2016
This was nice in buy
I recommend a website that was really helpful throughout your session.

March 19, 2017
Some day ago
This was nice in buy
This was good in buy . I found all the answer correct and meaningful and had scored good marks