You are on page 1of 34

Techno India College of Technology

2nd Year 4Th Sem CSE (2014-18)


Software Tools (CS 492) Assignment
VISUAL BASIC ASSIGNMENT
Course Code: CS492
Course Name: Software Tools

NAME: SURAVI BANDYOPADHYAY


ROLL NO: 18700114083

1. To implement a Visual Basic Form with load event with design a Digital clock with a date. (L1-
Recognizing) [CO1]

Ans:-
A new standard EXE project is opened by selecting New command from the file menu.
Two textbox controls are placed in the Form.
The timer control is chosen from the textbox and placed in the form.
The Properties window of the timer control is viewed by clicking it and pressing F4.
The interval property of the timer control is set to 1000 which implies that the timer is activated
every single second.
The following code is entered in the form_load() procedure.

Private Sub Form_Load()


Text1.Text = Time$
Text2.Text = Date$
End Sub

The following code is entered in the Timer1_Timer procedure.


Private Sub Timer1_Timer()
Text1.Text = Time$
End Sub
The form is executed by pressing F5.It displays the current date and time in the Textbox_controls

1
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

OUTPUT

2
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

4. Write a Visual Basic script to display the name of the students given by users (use input box and
message box). (L1-RECOGNIZING)[CO3]

Ans.
A new Standard EXE project is opened by selecting New command from the File menu.
A InputBox is placed to enter a name.
A CommandButton is placed to perform the required task.
The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim name As String
name = InputBox(" Enter your name")
MsgBox "Entered name is " + name
End Sub

OUTPUT

3
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

5. Design a simple calculator. (L1) [CO3]


Ans:-
A new standard EXE project is opened by selecting New command from the file menu.
Two textbox controls are placed in the Form.
Four CommandButton are placed for basic calculation operations.
One CommandButton is placed at the end to generate the calculated result

The following code is entered from command1_click()


Dim op1, op2 As Double
Dim opr As String

Private Sub Command1_Click()


op1 = Val(Text1.Text)
opr = "+"
End Sub

The following code is entered from command2_click()


Private Sub Command2_Click()
op1 = Val(Text1.Text)
opr = "-"
End Sub

The following code is entered from command3_click()


Private Sub Command3_Click()
op1 = Val(Text1.Text)
opr = "*"
End Sub

The following code is entered from command4_click()


Private Sub Command4_Click()
op1 = Val(Text1.Text)
opr = "/"
End Sub

The following code is entered from command2_click()


Private Sub Command5_Click()
op1 = Val(Text1.Text)
op2 = Val(Text2.Text)
Select Case opr
Case "+": MsgBox op1 + op2
Case "-": MsgBox op1 - op2
Case "*": MsgBox op1 * op2
Case "/": MsgBox op1 / op2
End Select

4
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
End Sub

OUTPUT

5
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
7. Southern railways need to validate the date of travel for the reservation facility. The booking
should be either on that current day or for the next 15 days. How could we implement this in visual
basic? (L2) [CO3]

Ans.
A new Standard EXE project is opened by selecting New command from the File menu.
A CommandButton is placed to display the entered date.
A TextBox is created to enter the date of travel.
After clicking OK the validity of entered date is checked.
The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim ret_date As Date
ret_date = InputBox("Enter the date of travel", "DATE OF TRAVEL")
If ret_date >= Date And ret_date <= Date + 15 Then
MsgBox "DATE VALID"
Else
MsgBox "INVALID DATE!! Re-enter"
End If
End Sub

6
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
OUTPUT

7
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

8. Write an event procedure in VB to calculate the future value of a given present amount (interest
rate per annum and year are given) (L1-remebering) [CO2]
Ans:-

A new standard EXE project is opened by selecting New command from the file menu.
A textbox control and a lebel is placed in the Form.
In the TextBox the amount is given for the required calculation.
The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim i As Double
Dim p, r, t As Integer
p = Val(Text1.Text)
r = 12
t=5
i = (p * r * t) / 100
MsgBox "future value of amount is" + Str(i)
End Sub

OUTPUT

8
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

9. Write an event procedure to convert the number from Fahrenheit to Centigrade using simple
Textbox and Button. (L1) [CO3]
Ans:-

A new standard EXE project is opened by selecting New command from the file menu.
A textbox controls is placed in the Form.
In the TextBox the temperature in Fahrenheit is given for the required calculation.
The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim c, f As Double
f = Val(Text1.Text)
c = (5 * (f - 32)) / 9
MsgBox "the temp in centigrade is" + Str(c)
End Sub

OUTPUT

9
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

10. Write a Visual Basic script to create a Temperature Conversion Application. The form should
look like this. (L2) [CO3]

Ans:-

A new standard EXE project is opened by selecting New command from the file menu.
Two textbox controls are placed in the Form for the required fields as shown.
A vertical scroll bar is placed as shown above.
TextBox 1 is for temperature in Fahrenheit.

The code is entered in command1_click()

Private Sub Command1_Click()


Unload Me
End Sub

The code is entered in VScroll1_Change()

Private Sub VScroll1_Change()


Dim cen, far As Integer
cen = 1
While cen < VScroll1.Value

10
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
Text1.Text = cen
far = (9 * cen) / 5 + 32
Text2.Text = Str(far)
cen = cen + 1
Wend
End Sub

OUTPUT

11
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

14. Write a Visual Basic program to check the number is odd or not. (L2) [CO3]

Ans.
A new Standard EXE project is opened and saved.
A CommandButton is placed to check whether the entered number is even or odd.
A TextBox is created to enter the number.
After clicking CHECK EVEN OR ODD the required program is executed.
The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim a, chk As Integer
a = Val(Text1.Text)
If a Mod 2 = 0 Then
MsgBox ("Entered number is even")
Else
MsgBox ("Entered number is odd")
End If
End Sub

12
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
OUTPUT

15. Write a Visual Basic script to find out the factorial of a number. (L2) [CO3]

.Ans.
A new Standard EXE project is opened and saved.
A CommandButton is placed to calculate the factorial of a number.
A TextBox is created to enter the number.
After clicking FACTORIAL the required program is executed.
The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim a, sum As Integer
a = Val(Text1.Text)
sum = 1
For i = 1 To a
sum = sum * i
Next
MsgBox "The factorial " + Str(a) + " is" + Str(sum)
End
End Sub
OUTPUT

13
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

16. Write a program in Visual basic to check the number is Armstrong number or not using Input
Box() and Message Box() (L2) [CO3]

Ans:-

A new Standard EXE project is opened and saved.


A CommandButton is placed to check whether the number is Armstrong or not.
A TextBox is created to enter the number.
After clicking CHECK the required program is executed.

The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim i, x, r, n As Integer
n = Val(Text1.Text)
x=n
i=0
While (x > 0)

14
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
r = x Mod 10
i=i+r*r*r
x = x / 10
Wend
If n = i Then
Print "the number is armstrong"
Else
Print "the number is not armstrong"
End If
End Sub

OUTPUT

19. Write a function procedure using call by value and also call by references. (L2) [CO2]

i) To find the power of a number.

Ans:-
A new Standard EXE project is opened and saved.
A CommandButton is placed to calculate power of a number.

15
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
After clicking on command button the required program is executed.
The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim p, n As Integer
n = Val(InputBox("enter the number to compute power"))
c = Val(InputBox("enter the value of power"))
p = power(n, c)
MsgBox Str(n) + " to the power " + Str(c) + " is " + " " + Str(p)
End Sub
Function power(ByVal n As Integer, ByVal c As Integer) As Integer
Dim pow As Integer
pow = 1
While c > 0
pow = pow * n
c=c-1
Wend

power = pow
End Function

OUTPUT

16
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

The code is entered in Command1_Click() using call by reference

Private Sub Command1_Click()


Dim p, n As Integer
n = Val(InputBox("enter the number to compute power"))
c = Val(InputBox("enter the value of power"))
p = power(n, c)
MsgBox Str(n) + " to the power " + Str(c) + " is " + " " + Str(p)
End Sub
Function power (ByRef n As Integer, ByVal c As Integer) As Integer
Dim pow As Integer
pow = 1
While c > 0
pow = pow * n
c=c-1
Wend
power = pow
End Function

OUTPUT

17
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

ii) To convert the temperature in Fahrenheit into Celsius.


Ans:-

A new standard EXE project is opened by selecting New command from the file menu.
A textbox control is placed in the Form.
A CommandButton conversion is placed for calculating temperature in Celsius.
The code is entered in Command1_click()

Private Sub Command1_Click()


Dim c, f As Double
f = Val(Text1.Text)
c = convert(f)
MsgBox "the temp in centigrade is " + Str(c)
End Sub
Function convert(ByRef As Double) As Double
Dim cent As Double
cent = ((f - 32) / 9) * 5
convert = cent
End Function

OUTPUT

18
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

iii) To check whether the number is prime is not.


Ans:-

A new standard EXE project is opened by selecting New command from the file menu.
A textbox control is placed in the Form for input.
A CommandButton is placed for checking whether its a prime number or not.
The code is entered in Command1_click()

Private Sub Command1_Click()


Dim n As Integer
n = Val(InputBox("Enter the number"))
p = prime(n)
If p = 0 Then
MsgBox "The number is prime " + Str(n)
Else
MsgBox "The number is not prime" + Str(n)
End If
End Sub
Function prime(ByVal n As Integer) As Integer
Dim i, flag, r As Integer
flag = 0
i=2
Do While i < n / 2
r = n Mod i

19
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
If r = 0 Then
flag = 1
Exit Do
End If
i=i+1
Loop
prime = flag
End Function

OUTPUT

The code is entered in Command1_Click() using call by reference

Private Sub Command1_Click()


Dim n As Integer
n = Val(InputBox("Enter the number"))
p = prime(n)
If p = 0 Then
MsgBox "The number is prime " + Str(n)
Else
MsgBox "The number is not prime" + Str(n)
End If
End Sub
Function prime (ByRef n As Integer) As Integer

20
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
Dim i, flag, r As Integer
flag = 0
i=2
Do While i < n / 2
r = n Mod i
If r = 0 Then
flag = 1
Exit Do
End If
i=i+1
Loop
prime = flag
End Function

OUTPUT

21
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
20. Design a Form that has two combo boxes that displays the names of trains and the days of the
week. (L2) [CO3]

There are certain trains which will not operate on a particular day of the week and the details are
enlisted below; (use message box)

Train Name Day


Shatabdi Express Tuesday

Blue Mountain Express Sunday

Mysore Chennai Express Friday

.Ans.
A new Standard EXE project is opened and saved. The caption property of the form is set as
Train Schedules
The form is designed as per the specifications given in the following table.
Object Property Value
Label Caption Enter the Day of Journey
Combo box Name List CboTrName
Nellaui Express
Vaigai Express
Brindavan Express
Lalbagh Express
Shatabdi Express
Mysore-Chennai Express
Blue mountain Express
RockFort Express
Text
Train Names
Combo box Name CboDay
List Sunday
Monday, etc
Text Days

The following code is entered in the Click() event of the cboDay combo box control.

Private Sub cboDay_click()


If CboDay.Text = "Tuesday" And _
CboTrName.Text = "Shatabdi Express" Then
MsgBox "The Train is not scheduled to operate on Tuesdays"
ElseIf CboDay.Text = "Sunday" And _
CboTrName.Text = "Blue Mountain Express" Then
MsgBox "The Train is not scheduled to operate on Sundays "
ElseIf CboDay.Text = "Friday" And _
CboTrName.Text = "Mysore-Chennai Express" Then
MsgBox "The train will not operate on Fridays"

22
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
Else
MsgBox "The Train will be plying"
End If
End Sub

OUTPUT

23
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
Q21. Write a Visual Basic programe to implement a circle (with graphics programming). (L3)
[CO3]
Ans.

A new Standard EXE project is opened and saved


The following code is entered in the Form_Click() procedure.

Private Sub Form_Click()


Dim CX, CY, Radius
ScaleMode = 3
CX = ScaleWidth / 2
CY = ScaleHeight / 2
If CX > CY Then limit = CY Else limit = CX
For Radius = 0 To limit
Circle (CX, CY), Radius, RGB(Rnd * 255, Rnd * 255, Rnd * 255)
Next Radius
End Sub

OUTPUT

23. Write a Visual Basic Program to addition of number using 1-D array. (L2) [CO3]
Ans:-

24
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
A new standard EXE project is opened by selecting New command from the file menu.
A commandButton is placed in the form to calculate the sum.
The following code is entered under Command_Click() procedure.

Private Sub Command1_Click()


Dim a(5) As Integer
Dim sum, i As Integer
a(1) = 4
a(2) = 9
a(3) = 2
a(4) = 10
a(5) = 5
sum = 0
For i = 1 To 5
sum = sum + a(i)
Next
MsgBox "the sum is" + Str(sum)
End Sub

OUTPUT

25
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
24. Write a Visual Basic program to find the maximum, minimum number from a 1-D array. (L2) [CO3]

Ans:-
A new standard EXE project is opened by selecting New command from the file menu.
A CommandButton is placed in the form to check.
The following code is entered under Command1_Click() procedure.

Private Sub Command1_Click()


Dim a(6) As Integer
Dim max, min, i As Integer
a(1) = 6
a(2) = 8
a(3) = 2
a(4) = 7
a(5) = 9
a(6) = 1
max = min = a(1)
For i = 1 To 6
If a(i) > max Then
max = a(i)
End If
Next i
For i = 1 To 6
If a(i) < min Then
min = a(i)
End If
Next i
MsgBox "the maximum and minimum number is" + Str(max) + Str(min)
End Sub

26
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
OUTPUT

27
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
26. Develop an application to implement menu control arrays at run time where the new trains can
be added and non-existent ones can be deleted (The last menu item mnSep is selected to add new
train no.).(L3) [CO4]

Caption Name

&File mnufile

&Add mnadd

&Delete mndelete

E&xit mnexit

- mnsep

Ans.
A new Standard EXE project is opened and saved. The caption property of the form is changed to
menu Control Arrays. Menu items are added to the Form as given below:
Caption Name
File mnuFile
&Add mnAdd
&Delete mnDelete
E&xit mnExit
- mnSep
The last menu item mnSep is selected and the Index is set tob 0.
The following code is entered in the declaration section of the Form.

Option Explicit
Dim LastItem As Integer

The following code is entered in the Form_Load() procedure.

Private Sub Form_Load()


LastItem = 0
mndelete.Enabled = False
End Sub

The following code is entered in the mnAdd_Click() procedure.

Private Sub mnadd_Click()

28
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
LastItem = LastItem + 1
Load mnsep(LastItem)
mnsep(LastItem).Caption = "TRAIN NO." + Str(LastItem)
mndelete = True
End Sub

The following code is entered in the mnDelete_Click() procedure.

Private Sub mndelete_Click()


Unload mnsep(LastItem)
LastItem = LastItem - 1
If LastItem = 0 Then
mndelete.Enabled = False
End If
End Sub

The following code is entered in the mnexit_Click() procedure.

Private Sub mnexit_Click()


End
End Sub

The following code is entered in the mnSep_Click() procedure.

Private Sub mnsep_Click(index As Integer)


MsgBox " the selected train no. is " + Str(index)
End Sub

OUTPUT

29
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

28. Write a Visual Basic script where a pizza order can be entered by simply clicking on option
buttons and check boxes. (L2) [CO3]

Ans.

A new Standard EXE project is opened by selecting New command from the File menu.
Radio buttons and check boxes are according to the layout given.
Two CommandButton are placed to display the entered name.
The following code is entered in the Command1_Click() procedure.

Private Sub Command1_Click()


Dim size, ctype, need, all As String
Dim op1, op2, op3, op4, op5, op6, op7 As String
Dim chk1, chk2, chk3, chk4, chk5, chk6 As String
op1 = Option1.Caption

30
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
op2 = Option2.Caption
op3 = Option3.Caption
op4 = Option4.Caption
op5 = Option5.Caption
op6 = Option6.Caption
op7 = Option7.Caption
If Option1.Value = True Then
size = op1
ElseIf Option2.Value = True Then
size = op2
Else
size = op3
End If
If Option4.Value = True Then
ctype = Option4.Caption
Else
ctype = Option5.Caption
End If
If Option6.Value = True Then
need = Option6.Caption
Else
need = Option7.Caption
End If
If Check1.Value = 1 Then
chk1 = Check1.Caption
MsgBox "You have selected one " + size + " pizza with " + ctype + " having " + chk1
If Check1.Value = 1 Then
chk2 = Check2.Caption
MsgBox "You have selected one " + size + " pizza with " + ctype + " having " + chk2
ElseIf Check3.Value = 1 Then
chk3 = Check3.Caption
MsgBox "You have selected one " + size + " pizza with " + ctype + " having " + chk3
ElseIf Check4.Value = 1 Then
chk4 = Check4.Caption
MsgBox "You have selected one " + size + " pizza with " + ctype + " having " + chk4
ElseIf Check5.Value = 1 Then
chk5 = Check5.Caption
MsgBox "You have selected one " + size + " pizza with " + ctype + " having " + chk5
ElseIf Check6.Value = 1 Then
chk6 = Check6.Caption
MsgBox "You have selected one " + size + " pizza with " + ctype + " having " + chk6
Else
all = chk1 + chk2 + chk3 + chk4 + chk5 + chk6
MsgBox "You have selected one " + size + " pizza with " + ctype + " having " + chk6
End If
End If
End Sub

Private Sub Command2_Click()


Unload Me

31
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
End Sub

OUTPUT

32
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment

30. Create a student database and develop a VB application using ODBC database connectivity
where the value from the database will display in the form with suitable design (L2) [CO4]

(Assume student table contains fields roll, name, address, course, marks)
Ans:-

Using ADODC control, the following steps are given:

1. Right click on tool box, select component.


2. Click on the check box MS ADO data control 6.0(OLEDB).
3. Click on apply, click on OK.
4. Drag the icon ADODC in form.
5. Select ADODC1.Right click, select ADODC properties.
6. Select option button use connection string.
7. Click on build button.
8. Select the provider, MS jet 3.51 OLE DB provider.
9. Click on next button. Select the database.
10. Click on Test connection, perform test.
11. Click Ok.
12. Click on record source tab.
13. Select the command type as ADCMD table.
14. Select the table name.
15. Click on apply button.
16. Click on OK.
17. Select text box. Select data source option.
18. Select data field. Perform following action.

33
Techno India College of Technology
2nd Year 4Th Sem CSE (2014-18)
Software Tools (CS 492) Assignment
OUTPUT

34

You might also like