You are on page 1of 37

CA -1 Lab Que.1) Write a program to reverse a number.

Assignment -3

Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding a command button with caption Display A Numbers Reverse by dragging and dropping it to the form as shown in the following snapshot:

d) Now, open code window by either double clicking on the command button or by selecting Code from View Menu. e) Now, write code for the application in the code window between Private and End sub as shown in the box:

Created By: - Daksh Chadha

CA -1 Lab
Private Sub Command1_Click() Dim k As Integer k = InputBox("enter Number") While (k <> 0) r = k Mod 10 k = k / 10 rk = (rk * 10) + r Wend Print "Reverse of Number is" & rk End Sub

Assignment -3

f) Now, close the code window and click on Run button in the toolbar or start option in the run menu. g) A window appears with the form design by you. h) Now, click on the command button to enter any number and find its reverse as shown in the snapshot given below:

Created By: - Daksh Chadha

CA -1 Lab
Que.2) Write a program to sort an array.

Assignment -3

Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding a command button with caption Sort Array by dragging and dropping it to the form as shown in the following snapshot:

d) Now, open code window by either double clicking on the command button or by selecting Code from View Menu. e) Now, write code for the application in the code window between Private and End sub as shown in the box:

Created By: - Daksh Chadha

CA -1 Lab Private Sub Command1_Click() Dim a(50) As Integer n = InputBox("Enter Number Of Element In Array") For i = 1 To n a(i) = InputBox("Enter Element") Next i For i = 1 To n For j = 0 To n - i If a(j) > a(j + 1) Then t = a(j) a(j) = a(j + 1) a(j + 1) = t End If Next j Next i For i = 1 To n Print a(i) Next i End Sub

Assignment -3

f) Now, close the code window and click on Run button in the toolbar or start option in the run menu. g) A window appears with the form design by you. h) Now, click on the command button and enter the element to be sort and it will be print on form in sorted manner as shown in the snapshot given below:

Created By: - Daksh Chadha

CA -1 Lab Que.3) Write a program to merge an array.

Assignment -3

Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding a command button with caption Merge Array by dragging and dropping it to the form as shown in the following snapshot:

d) Now, open code window by either double clicking on the command button or by selecting Code from View Menu. e) Now, write code for the application in the code window between Private and End sub as shown in the box:

Created By: - Daksh Chadha

CA -1 Lab

Assignment -3

Private Sub Command1_Click() Dim a(5) As Integer Dim b(5) As Integer Dim c(10) As Integer For i = 1 To 5 a(i) = InputBox("Enter Element In First Array") Next i Print "The First array is" For i = 1 To 5 Print a(i) Next i

For i = 1 To 5 b(i) = InputBox("Enter Element In Second Array") Next i Print "The second array is" For i = 1 To 5 Print b(i) Next i For j = 1 To 5 c(j) = a(j) Next j i=j For j = 1 To 5 c(i) = b(j) i=i+1 Next j Print "The merged array is" For i = 1 To 10 Print c(i) Next i Created By: - Daksh Chadha
6

CA -1 Lab End Sub

Assignment -3

f) g)

Now, close the code window and click on Run button in the toolbar or start option in the run menu. A window appears with the form design by you.

h) Now, click on the command button and enter 1st and 2nd array which is to be merged as shown in the snapshot given below:

Created By: - Daksh Chadha

CA -1 Lab Que.4) Write a program to search an element in an array

Assignment -3

Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding a command button with caption Search Array by dragging and dropping it to the form as shown in the following snapshot:

d) Now, open code window by either double clicking on the command button or by selecting Code from View Menu. e) Now, write code for the application in the code window between Private and End sub as shown in the box:

Created By: - Daksh Chadha

CA -1 Lab

Assignment -3

Private Sub Command1_Click() Dim a(10) As Integer For i = 1 To 10 a(i) = InputBox("Enter Element") Next i e = InputBox("Enter Element to be find") For i = 1 To 10 If e = a(i) Then MsgBox "Element find at" & i GoTo out End If Next i out: MsgBox "Search Complete" End Sub

f) g)

Now, close the code window and click on Run button in the toolbar or start option in the run menu. A window appears with the form design by you.

Created By: - Daksh Chadha

CA -1 Lab

Assignment -3

h) Now, click on the command button and enter the elements of array and element to be find as shown in the following snapshot:

Created By: - Daksh Chadha


10

CA -1 Lab

Assignment -3

Created By: - Daksh Chadha


11

CA -1 Lab Que.5) Write a program to print pyramids with *.

Assignment -3

Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding a command button with caption Print Pyramids by dragging and dropping it to the form as shown in the following snapshot:

d) Now, open code window by either double clicking on the command button or by selecting Code from View Menu. e) Now, write code for the application in the code window between Private and End sub as shown in the box:

Created By: - Daksh Chadha


12

CA -1 Lab

Assignment -3

Private Sub Command1_Click() For i = 1 To 5 For j = 0 To i - 1 Print "*'"; Next j Print Next i End Sub

f) g) h)

Now, close the code window and click on Run button in the toolbar or start option in the run menu. A window appears with the form design by you. Now, click on the command button to print pyramid as shown in the snapshot given below:

Created By: - Daksh Chadha


13

CA -1 Lab Que.6) Write a program to implement OLE (Object Linking and Embedding).

Assignment -3

Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding a OLE control by dragging and dropping it to the form. An Insert Object dialog box will appear. d)

In the dialog box select Create From File option and then browse your object to be link

with the Visual Basic application and the check the Link and Display as Icon option and then click OK. As shown in the following snap:

Created By: - Daksh Chadha


14

CA -1 Lab

Assignment -3

e)

Now your Visual Basic application is linked with the file you selected and our form will

look like:

f) g) h)

Now, close the code window and click on Run button in the toolbar or start option in the run menu. A window appears with the form design by you. Now, click on the OLE control to access your file as shown in the snapshot given below:

Created By: - Daksh Chadha


15

CA -1 Lab

Assignment -3

Following snap displaying opened file which was linked with the Visual Basic application:

Created By: - Daksh Chadha


16

CA -1 Lab Que.7) Write a program to implement DSN (Data Source Name).

Assignment -3

In order to implement DSN, follow the instructions given below: a) Go to Administrative tools available in Control Panel. b) Open Data Sources (ODBC). A dialog box appear, Click ADD in it as shown in the following snap:

c) Create New Data Source will appear where you select the file type for which you want to create

DSN. Select that file type and click Finish. As shown in the following snap:

Created By: - Daksh Chadha


17

CA -1 Lab

Assignment -3

d) When you click Finish, ODBC Microsoft Access Setup dialog box will appear where you will

name your DSN and then select file by clicking on Select button as shown below:

e) After clicking select button, select your desire file for which DSN is to be created and click OK as shown below:

f) Now, Click Ok in ODBC Microsoft Access Setup dialog box.

Created By: - Daksh Chadha


18

CA -1 Lab

Assignment -3

g) Now, click on OK in dialog box and your DSN is created as shown below:

Created By: - Daksh Chadha


19

CA -1 Lab

Assignment -3

Que.8) Write a program to implement User Define Data Type (UDT) and record details of 5 employees with the fields: Employee ID Employee Name Employee Designation Employee Salary.
Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding a command button with caption Enter Records Reverse by dragging and dropping it to the form as shown in the following snapshot:

d) Now, open code window by either double clicking on the command button or by selecting Code from View Menu.

Created By: - Daksh Chadha


20

CA -1 Lab

Assignment -3

e)

Now, write code for the application in the code window:

Code to be written in General Declarations: Private Type employee id As Integer name As String desig As String sal As Integer End Type Dim emp(5) As employee

Code to be written on click on command button: Private Sub Command1_Click() emp(i).id = InputBox("Enter") emp(i).name = InputBox("Enter") emp(i).desig = InputBox("Enter") emp(i).sal = InputBox("Enter") Print "ID is" & emp(i).id Print "name is" & emp(i).name Print "designation is" & emp(i).desig Print "salery is" & emp(i).sal End Sub

f) Your UDT is created now, close the code window and click on Run button in the toolbar or start option in the run menu. g) A window appears with the form design by you.

Created By: - Daksh Chadha


21

CA -1 Lab

Assignment -3

h) below:

Now, click on the command button to enter details of employees as shown in the snapshot given

Created By: - Daksh Chadha


22

CA -1 Lab

Assignment -3

Que.9) Write a program to add, subtract, multiply and divide two matrices according to the button selected by user. Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding 4 command buttons with caption ADD, SUBTRACT, MULTIPLY and DIVIDE by dragging and dropping it to the form as shown in the following snapshot:

d) Now, open code window by either double clicking on the command button or by selecting Code from View Menu. e) Now, write code for the application in the code window between Private and End sub as shown in the box:

Created By: - Daksh Chadha


23

CA -1 Lab

Assignment -3

Code to be written for adding two matrices:

Private Sub Command1_Click()

Dim a(2, 2), b(2,2), c(2,2) As Integer For i = 1 To 2 For j = 1 To 2 a(i, j) = InputBox("Enter Element in 1st Matrice") Next j Next i For i = 1 To 2 For j = 1 To 2 Print a(i, j); Next j Print Next i For i = 1 To 2 For j = 1 To 2 b(i, j) = InputBox("Enter Element in 2nd Matrice") Next j Next i For i = 1 To 2 For j = 1 To 2 Print b(i, j); Next j Print Next i For i = 1 To 2 For j = 1 To 2 c(i, j) = a(i, j) + b(i, j) Next j Next i For i = 1 To 2 For j = 1 To 2 Print c(i, j); Next j Print Next i Created By: - Daksh Chadha
24

CA -1 Lab End Sub


Code to be written to subtract two matrices: Private Sub Command1_Click()

Assignment -3

Dim a(2, 2), b(2,2), c(2,2) As Integer


For i = 1 To 2 For j = 1 To 2 a(i, j) = InputBox("Enter Element in 1st Matrice") Next j Next i For i = 1 To 2 For j = 1 To 2 Print a(i, j); Next j Print Next i For i = 1 To 2 For j = 1 To 2 b(i, j) = InputBox("Enter Element in 2nd Matrice") Next j Next i For i = 1 To 2 For j = 1 To 2 Print b(i, j); Next j Print Next i For i = 1 To 2 For j = 1 To 2 c(i, j) = a(i, j) - b(i, j) Next j Next i For i = 1 To 2 For j = 1 To 2 Print c(i, j); Next j Print Next i End Sub

Created By: - Daksh Chadha


25

CA -1 Lab
Code to be written for multiplying two matrices:

Assignment -3

Private Sub Command1_Click()

Dim a(2, 2), b(2,2), c(2,2) As Integer


For i = 1 To 2 For j = 1 To 2 a(i, j) = InputBox("enter elements in 1st matrice") Next j Next i For i = 1 To 2 For j = 1 To 2 Print a(i, j); Next j Print Next i For i = 1 To 2 For j = 1 To 2 b(i, j) = InputBox("enter elements in 2nd matrice") Next j Next i For i = 1 To 2 For j = 1 To 2 Print b(i, j); Next j Print Next i For i = 1 To 2 For j = 1 To 2 For k = 1 To 2 c(i, j) = c(i, j) + (a(i, k) * b(k, j)) Next k Next j Next i For i = 1 To 2 For j = 1 To 2 Print c(i, j); Next j Print Next i End Sub

Created By: - Daksh Chadha


26

CA -1 Lab
Code to be written to divide two matrices:

Assignment -3

Private Sub Command1_Click()

Dim a(2, 2), b(2,2), c(2,2) As Integer For i = 1 To 2 For j = 1 To 2 a(i, j) = InputBox("Enter Element in 1st Matrice") Next j Next i For i = 1 To 2 For j = 1 To 2 Print a(i, j); Next j Print Next i For i = 1 To 2 For j = 1 To 2 b(i, j) = InputBox("Enter Element in 2nd Matrice") Next j Next i For i = 1 To 2 For j = 1 To 2 Print b(i, j); Next j Print Next i For i = 1 To 2 For j = 1 To 2 c(i, j) = a(i, j) / b(i, j) Next j Next i For i = 1 To 2 For j = 1 To 2 Print c(i, j); Next j Print Next i End Sub Created By: - Daksh Chadha
27

CA -1 Lab

Assignment -3

f) Now, close the code window and click on Run button in the toolbar or start option in the run menu. g) A window appears with the form design by you. h) Now, click on the command button which function you want to do (add/subtract/multiply/divide) as shown in the snapshot given below:

Created By: - Daksh Chadha


28

CA -1 Lab
Que.10) Write a program to implement DAO (Data Access Object).

Assignment -3

Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, design your form by adding 2 labels (with caption Roll Number and Name), 2 text boxes and a DAO control on form by dragging and dropping it to the form as shown in the following snapshot:

d)

Now, go to Visual Data Manager available in Add-Ins menu in Menu bar.

Created By: - Daksh Chadha


29

CA -1 Lab

Assignment -3

e) A new window with title VisData will appear. In this window go to Microsoft Access sub menu in New option available in File Menu and save your New MS-ACCESS file in your desired location and click Save. Then your VisData window will look like:

f) In the Database window displayed in above snap, right click and select New Table. Table Structure Dialog Box will appear, enter the name of table and fields to be add in the table and then click build the table to make the table. As shown in the snap given below:

Created By: - Daksh Chadha


30

CA -1 Lab
g) h)

Assignment -3
Now, right click on the table you made and select open. A new window will appear. Now, in order to add data in table by clicking on ADD.

i)

A new dialog box will appear, add data in it and click Update.

Created By: - Daksh Chadha


31

CA -1 Lab
j)

Assignment -3
Now, close the VisData window and change the properties of DAO Control and Text box. Properties to be changed of DAO control. Database Name: in this, select the location of your database Record Source: in this, select your table.

Properties to be changed of Text boxes: Data Source: in this, select data control i.e. DATA1 for both the text boxes Data Field: in this, select which field you want to display. Select Roll Number in 1 st and Name in nd 2 text box. k) Now, click on Run button in the toolbar or start option in the run menu. l) A window appears with the form design by you. m) In form, the entries of table is visible and you can see other by using DAO control key as shown in the snapshot given below:

Created By: - Daksh Chadha


32

CA -1 Lab
Que.11) Write a program to implement ADO (Active Data Object).

Assignment -3

Steps to be followed: a) Open Standard.exe form in Visual Basic. b) A blank form appears. c) Now, Go to Components option available in Project Menu or press CTRL+T. A dialog box appears, check the option with name Microsoft ADO Data Control 6.0 (OLEDB) and click Ok. d) ADO control will be added in the toolbox. e) Now, design your form by adding 2 labels (with caption Roll Number and Name), 2 text boxes and a ADO control on form by dragging and dropping it to the form as shown in the following snapshot:

f)

Now, change the properties of ADO Control and Text box. Properties to be changed of Text boxes: Data Source: in this select data control i.e. DATA1 for both the text boxes Data Field: in this select which field you want to display. Select Roll Number in 1st and nd Name in 2 text box.

Created By: - Daksh Chadha


33

CA -1 Lab

Assignment -3

Properties to be changed of DAO control. Connection String: In this you have to select the provider for your control. To select the provider, follow the steps given below: i. Click on the browse button in the Connection String. a dialog box appear, click on the build.

ii.

As you click on the Build button a dialog box appear select the Microsoft Jet 4.0 OLE DB Provider and click Next as shown in the following snap:

Created By: - Daksh Chadha


34

CA -1 Lab

Assignment -3

iii.

Now, select your database from any location you want just click on the browse button and select. After selecting database text your connection by clicking on Text Connection button if it is succeeded then it will display a message box that your connection succeeded. As shown in the following snap:

Created By: - Daksh Chadha


35

CA -1 Lab

Assignment -3

iv.

Now close dialog boxes by clicking Ok.

Record Source: in this, select your table by clicking on browse button and select the Command Type as 2-adCmdTable and Table Name as Student. Click OK. As shown in the following snap:

Properties to be changed of Text boxes: Data Source: in this, select data control i.e. ADODC1th the text boxes Data Field: in this, select which field you want to display. Select Roll Number in 1 st and Name in nd 2 text box. g) Now, click on Run button in the toolbar or start option in the run menu. h) A window appears with the form design by you. i) In form, the entries of table is visible and you can see other by using ADO control key as shown in the snapshot given below:

Created By: - Daksh Chadha


36

CA -1 Lab

Assignment -3

Created By: - Daksh Chadha


37

You might also like