Professional Documents
Culture Documents
List of Exercises
Cycle I (Visual Basic)
1. Interest Calculation
2. Fibonacci Series
3. Designing a Scientific Calculator using Control Array
4. String Operations
5. Matrix Operations
6. Free Hand Writing
7. Simple MDI Text Editor
8. Creating and Updating a Database
9. Designing a Digital Clock
10. Horizontal and Vertical Scrolling for Changing Colors.
11. Designing a Calendar
12. Student Mark Sheet
13. Database Applications using data control.
Cycle II (Visual C++)
14. Palindrome Checking
15. Pattern Numbers using For Loops
16. Minipaint application
17. File Operations
18. Mouse Interface
19. ActiveX Control
20. Message Box Display
21. Creating and Using DLLs
Lab Incharges
A1 Batch Dr. A. Geetha
A2 Batch Dr. P. Dhanalakshmi
Cycle I
Visual Basic
INTEREST CALCULATION
Ex. No: 1
Aim:
To implement a Visual Basic program to calculate the simple interest and compound
interest.
Procedure :
1. Start
2. Design the form with four text boxes and four command buttons. Display appropriate
messages in label boxes
3. Write the script in the click event on the simple interest and compound interest command
buttons as follows:
i) Set p=Text1. Text
ii) Set n=Te xt2. Text
iii) Set r=Text3.Text
iv) Si=(P*n*r)/100
v) Ci=p*(1+r/100)^n
vi) Text4. Text=Si
vii) Text5.Text=Ci
4. Stop
Property Settings:
Control
Label
Label
Label
Label
Text Box
Text Box
Text Box
Text Box
Command
Command
Command
Command
Name
Label1
Label2
Label3
Label4
Text1
Text2
Text3
Text4
Command1
Command2
Command3
Command3
Property
Caption
Caption
Caption
Caption
Text
Text
Text
Text
Caption
Caption
Caption
Caption
Value
Principle
Rate of interest
Number of Year
Result
Simple Interest
Compound Interest
Exit
Clear
Form Design:
Source Code:
Dim p, r, n As Integer
Private Sub Command1_Click()
p = Val(Text1.Text)
r = Val(Text2.Text)
n = Val(Text3.Text)
Text4.Text = (p * r * n) / 100
End Sub
Private Sub Command2_Click()
p = Val(Text1.Text)
r = Val(Text2.Text)
n = Val(Text3.Text)
Text4.Text = p * (1 + r / 100) ^ n
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Command4_Click()
End
End Sub
Output :
Result : Thus the Visual Basic program to calculate the simple interest and compound interest
has been executed successfully.
FIBONACCI SERIES
Ex. No : 2
Aim:
To implement a Visual Basic program to create Fibonacci series.
Procedure :
1. Start
2. Design a form with all necessary controls.
3. Write code in the click event of the compute command button to print the Fibonacci series
4. Write appropriate code in the click events of exit and clear command buttons.
5. Stop
Property Settings:
Control
Label
Label
Text Box
List Box
Command
Command
Command
Form Design:
Name
Label1
Label2
Text1
list1
Command1
Command2
Command3
Property
Caption
Caption
Text
Caption
Caption
Caption
Caption
Value
Enter the number
Result
Compute
Exit
Clear
Source Code:
Private Sub Command1_Click()
Dim f1, f2, f3, i As Integer
f1 = -1
f2 = 1
n = Val(Text1.Text)
For i = 1 To n
f3 = f1 + f2
List1.AddItem (f3)
f1 = f2
f2 = f3
Next i
End Sub
Private Sub Command2_Click()
End
End Sub
Private Sub Command3_Click()
Text1.Text = ""
List1.cl
End Sub
Result : Thus the Visual Basic program to create Fibonacci series has been implemented and
executed successfully.
Name
Text1
Text2
Command 1
Command 2
Property
Text
Text
Caption, Index
Caption, Index
Value
1, 1
2, 2
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Form Design:
Command 3
Command4
Command 5
Command6
Command 7
Command 8
Command 9
Command 10
Command 11
Command 12
Command 13
Command 14
Command 15
Command 16
Command 17
Command 18
Command 19
Command 20
Command 21
Command 22
Command 23
Command 24
Command 25
Command 26
Command 27
Command 28
Command 29
Command 30
Caption, Index
Caption, Index
Caption, Index
Caption, Index
Caption, Index
Caption, Index
Caption, Index
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
3, 3
4, 4
5, 5
6, 6
7, 7
8, 8
9, 9
.
0
=
+
*
/
x^2
x^3
x^4
sqrt
Mod
Sin
Cos
Tan
10^x
1/x
x!
Pi
Clear
Exit
Source Code:
Dim a, b, d As Integer
Dim c As String
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0:
Unload Me
Case 1:
Text1.Text = Text1.Text & 1
Case 2:
Text1.Text = Text1.Text & 2
Case 3:
Text1.Text = Text1.Text & 3
Case 4:
Text1.Text = Text1.Text & 4
Case 5:
Text1.Text = Text1.Text & 5
Case 6:
Text1.Text = Text1.Text & 6
Case 7:
Text1.Text = Text1.Text & 7
Case 8:
Text1.Text = Text1.Text & 8
Case 9:
Text1.Text = Text1.Text & 9
Case 10:
Text1.Text = Text1.Text & "."
Case 11:
Text1.Text = Text1.Text & 0
Case 12:
b = Val(Text1.Text)
Text1.Text = ""
If c = "+" Then
d=a+b
Text1.Text = d
ElseIf c = "-" Then
d=a-b
Text1.Text = d
ElseIf c = "*" Then
d=a*b
Text1.Text = d
ElseIf c = "/" Then
d=a/b
Text1.Text = d
ElseIf c = "mod" Then
d = a Mod b
Text1.Text = d
End If
Case 13:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
c = "+"
End If
Case 14:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
c = "-"
End If
Case 15:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
c = "*"
End If
Case 16:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
c = "/"
End If
Case 17:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
Text1.Text = a * a
End If
Case 18:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
Text1.Text = a * a * a
End If
Case 19:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
Text1.Text = a * a * a * a
End If
Case 20:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
Text1.Text = a ^ 0.5
End If
Case 21:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
c = "mod"
End If
Case 22:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text) * (3.14 / 180)
Text1.Text = ""
Text1.Text = Sin(a)
End If
Case 23:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text) * (3.18 / 180)
Text1.Text = ""
Text1.Text = Cos(a)
End If
Case 24:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text) * (3.18 / 180)
Text1.Text = ""
Text1.Text = Tan(a)
End If
Case 25:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
Text1.Text = 10 ^ a
End If
Case 26:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
Text1.Text = 1 / a
End If
Case 27:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
s=1
For i = 1 To n
s=s*i
Next i
Text1.Text = s
End If
Case 28:
If Trim(Text1.Text) <> "" Then
a = Val(Text1.Text)
Text1.Text = ""
Text1.Text = a * 3.14
End If
Case Else:
MsgBox ("sorry....")
End Select
End Sub
Private Sub Command29_Click()
Text1.Text = ""
End Sub
Private Sub Command30_Click()
End
End Sub
Output :
Result : Thus the Visual Basic program to create a scientific calculator has been implemented
and executed successfully.
STRING OPERATIONS
Ex. No: 4
Aim:
To implement a Visual Basic program to perform string operations based on the user choice.
Procedure :
1. Start
2. Read the string 1&string 2
3. Get the choice from the user
4. If Choice=Compare, Then
Invoke StrComp ( ) and Print whether the strings are equal or unequal.
5. Else If Choice=Concat , Then
Use + operator to concatenate two strings and print the concatenated string.
6. Else If Choice =Replace , Then
Invoke Replace( ) and Print the resultant string.
7. Else If Choice=Length , Then
Invoke LEN( ) and Print the length of the given string.
8. Else If Choice=Trim, Then
Invoke Trin( ) to remove spaces in the string and Print the resultant string.
9. Else If Choice=Reverse, Then
Invoke StrReverse( ) to reverse the string and Print the reversed string.
10. Else If Choice=Space, Then
Invoke Space( ) to add spaces in the string and Print the resultant string.
11. Else If Choice=Conversion, Then
Invoke StrConv( ) to convert the case of a given string and Print the converted string.
12. Stop.
Propery Settings:
Control
Label
Label
Label
Text Box
Text Box
Text Box
Command
Command
Command
Command
Command
Command
Command
Command
Command
Command
Form Design:
Name
Label1
Label2
Label3
Text1
Text2
Text3
Command1
Command2
Command3
Command4
Command5
Command6
Command7
Command8
Command9
Command10
Property
Caption
Caption
Caption
Text
Text
Text
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Caption
Value
String1
String2
Result
Replace
Length
Space
Conversion
Concatenate
Compare
Reverse
Trim
Clear
Exit
Source Code:
Private Sub Command1_Click()
Dim a, b As String
a = Text1.Text
b = Text2.Text
Text3.Text = Replace(a, "a", b, 1, 1)
End Sub
Private Sub Command10_Click()
End
End Sub
Private Sub Command2_Click()
Text3.Text = Len(Text1)
End Sub
Private Sub Command3_Click()
Dim a As String
a = Text1.Text
Text3.Text = Space(5) + a
End Sub
Private Sub Command4_Click()
Dim a As String
a = Text1.Text
Text3.Text = StrConv(a, 1)
End Sub
Private Sub Command5_Click()
Dim a As String
a = Text1.Text
b = Text2.Text
Text3.Text = a + b
End Sub
Result : Thus the Visual Basic program to perform string operations has been implemented and
executed successfully.
MATRIX OPERATIONS
Ex. No: 5
Aim:
To implement a Visual Basic program to perform matrix operations.
Procedure :
1. Start
2. Design the form with 3 label boxes, 3 list boxes and 6 command buttons.
3. Display appropriate messages in the label boxes.
4. Write the script in the click events of the matrix addition, subtraction, multiplication and
Inverse, clear and exit command buttons.
6. Stop.
Property Settings:
Control
Name
Property
Value
Label
Label
Label
Text Box
Text Box
Text Box
Command
Command
Command
Command
Command
Command
Label1
Label2
Label3
Text1
Text2
Text3
Command1
Command2
Command3
Command4
Command5
Command6
Caption
Caption
Caption
Text
Text
Text
Caption
Caption
Caption
Caption
Caption
Caption
Matrix1
Matrix2
Result
Addition
Subtract
Multiply
Inverse
Clear
Exit
Form Design:
Source Code:
Dim a(10, 10), b(10, 10), c(10, 10) As Integer
Dim m, n, p, q, i, j, k As Integer
Dim str As String
Private Sub Command1_Click()
List1.Clear
List2.Clear
List3.Clear
l1:
m = InputBox("Enter m value")
n = InputBox("Enter n value")
p = InputBox("Enter p value")
q = InputBox("Enter q value")
If m <> p And n <> q Then
GoTo l1
End If
ina
inb
For i = 1 To m
str = ""
For j = 1 To n
c(i, j) = a(i, j) - b(i, j)
str = str & c(i, j) & " "
Next j
List3.AddItem str
Next i
End Sub
Private Sub Command3_Click()
List1.Clear
List2.Clear
List3.Clear
l1:
m = InputBox("Enter m value")
n = InputBox("Enter n value")
p = InputBox("Enter p value")
q = InputBox("Enter q value")
If m <> p And n <> q Then
MsgBox ("Multi operation not possible")
GoTo l1:
End If
ina
inb
For i = 1 To m
str = " "
For j = 1 To q
c(i, j) = 0
For k = 1 To p
c(i, j) = c(i, j) + a(i, k) * b(k, j)
Next k
str = str & c(i, j) & " "
Next j
List3.AddItem str
Next i
End Sub
Private Sub Command4_Click()
List1.Clear
List2.Clear
List3.Clear
Label2.Visible = False
List2.Visible = False
m = InputBox("Enter m value")
n = InputBox("Enter n value")
ina
For i = 1 To m
str = ""
For j = 1 To n
c(i, j) = Val(a(j, i))
str = str & c(i, j) & " "
Next j
List3.AddItem str
Next i
End Sub
Private Sub Command5_Click()
List1.Clear
List2.Clear
List3.Clear
End Sub
Private Sub Command6_Click()
End
End Sub
Output :
Result : Thus the Visual Basic program to perform matrix operations has been implemented and
executed successfully.
FREEHAND DRAWING
Ex. No: 6
Aim:
To implement a Visual Basic program to create a free hand drawing.
Procedure :
1. Start
2. Design the form by adding a frame, 4 command buttons, 1 picture box and 1 combo
box
3. Write the script in the click events of size, color, clear and exit command buttons.
4. On click and drag on the picture box lines are drawn by following mouse pointer.
5. On click and drag on the frame both (picture box and frame) are moved to the mouse
pointer direction.
6. On clicking clear the contents of picture box should be cleared
Property Settings :
Control
Name
Command Command1
Command Command2
Command Command3
Command Command4
Picture box Picture1
Combo box
Form Design :
Combo1
Property
Value
Caption
Caption
Caption
Caption
Size
Color
Clear
Exit
Source Code :
Dim clr As OLE_COLOR
Dim i As Integer
Private Sub Command1_Click()
Combo1.Visible = True
End Sub
Private Sub Command2_Click()
cd1.ShowColor
clr = cd1.Color
End Sub
Private Sub Command3_Click()
Picture1.Cls
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private Sub Form_Load()
clr = vbBlack
For i = 1 To 15
Combo1.AddItem (i)
Next i
End Sub
Private Sub Picture1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Combo1.Visible = False
If Button = vbLeftButton Then
Picture1.PSet (x, y), clr
Picture1.DrawWidth = Combo1.Text
ElseIf Button = vbRightButton Then
Picture1.DrawWidth = 1
Picture1.PSet (x, y), Combo1.Text * 10
End If
End Sub
Result : Thus the Visual Basic program to create a free hand drawing has been implemented
and executed successfully.
Sub-Menu
Caption
open
Save
Save as
Print
Exit
Edit
Cut
Copy
Paste
Format
Bold
Italic
Underline
Strikethrough
5. To invoke components, click project -> components
Name
open
save
saveas
print
exit
cut
copy
paste
bold
italic
underline
Strikethrough
then select Microsoft rich text
box control, Microsoft common dialog box control from components window.
6. Load the combo boxes with some font names and size. By selecting the combo boxes
the font and size of the text are altered respectively.
7. By selecting the operations on menus the corresponding tasks should be performed
using common dialog box and clipboard events.
If (Button.Index = 1) Then
Call New_Click
ElseIf (Button.Index = 2) Then
Call open_Click
ElseIf (Button.Index = 3) Then
Call Save_Click
ElseIf (Button.Index = 4) Then
Call Cut_Click
ElseIf (Button.Index = 5) Then
Call Copy_Click
ElseIf (Button.Index = 6) Then
Call past_Click
End If
End Sub
Rich text box :Private Sub rt_mousedown(Button As Integer, shift As Integer, x As Single, y As Single)
If Button = 2 Then
PopupMenu Edit
End If
End Sub
Output :
Result : Thus a Visual Basic application has been created with MDI features and text editing
capabilities.
Click Ok
Similarly enter all the field names and their corresponding type
When finished click close
Click the>>button in the middle and then click Build the form
Click the project option and select project1 properties to change the startup object
Result : Thus a Visual Basic application has been created to perform basic functions in a
database.
Timer
Form Design:
Name
label1
label2
Command1
Frame1
Timer1
Property
Value
Text
Text
Caption
Caption
Exit
Digital Clock
Interval
1000
Source code:
Private Sub Command1_Click()
End
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Time
Label2.Caption = Date
End Sub
Output :
Result : Thus a Visual Basic program to design a digital clock has been implemented and
executed successfully.
Form Design:-
Source code:
Dim r, g, b As Integer
Private Sub Command1_Click()
End
End Sub
Private Sub HScroll1_Change()
r = VScroll1.Value
g = VScroll2.Value
b = HScroll1.Value
Shape1.BackColor = RGB(r, g, b)
Label10.Caption = HScroll1.Value
End Sub
Label8.Caption = VScroll2.Value
End Sub
Output :
Result : Thus a Visual Basic program has been implemented to use horizontal and vertical bars
for changing colors and executed successfully.
DESIGNING A CALENDAR
Ex. No : 11
Aim:
To implement a Visual Basic program to design a calendar.
Procedure :
1. Start
2. Design the form with 1 calendar control and two label boxes.
3. Display appropriate messages in the Label boxes.
4. Stop
Form design:Select the control as follows:
Project -> components (ctrl+t) ->Select microsoft calendar control 6.0
Result : Thus a Visual Basic program to create a calendar has been implemented and executed .
Form Design:
End If
Text16.Text = Val(Text14.Text) + Val(Text15.Text)
s = Text16.Text
If (Text16.Text >= 90 And Text16.Text <= 100) Then
Text32.Text = "s"
ElseIf (Text16.Text >= 80 And Text16.Text <= 89) Then
Text32.Text = "A"
ElseIf (Text16.Text >= 70 And Text16.Text <= 79) Then
Text32.Text = "B"
ElseIf (Text16.Text >= 60 And Text16.Text <= 69) Then
Text32.Text = "c"
ElseIf (Text16.Text >= 55 And Text16.Text <= 59) Then
Text32.Text = "D"
ElseIf (Text16.Text >= 50 And Text16.Text <= 54) Then
Text32.Text = "E"
ElseIf (Text16.Text <= 50) Then
Text32.Text = "F"
End If
Text19.Text = Val(Text17.Text) + Val(Text18.Text)
u = Text19.Text
If (Text19.Text >= 90 And Text16.Text <= 100) Then
Text33.Text = "s"
ElseIf (Text19.Text >= 80 And Text19.Text <= 89) Then
Text33.Text = "A"
ElseIf (Text19.Text >= 70 And Text19.Text <= 79) Then
Text33.Text = "B"
ElseIf (Text19.Text >= 60 And Text19.Text <= 69) Then
Text33.Text = "c"
ElseIf (Text19.Text >= 55 And Text19.Text <= 59) Then
Text33.Text = "D"
ElseIf (Text19.Text >= 50 And Text19.Text <= 54) Then
Text33.Text = "E"
ElseIf (Text19.Text <= 50) Then
Text33.Text = "F"
End If
Text22.Text = Val(Text20.Text) + Val(Text21.Text)
d = Text22.Text
If (Text22.Text >= 90 And Text22.Text <= 100) Then
Text34.Text = "s"
ElseIf (Text22.Text >= 80 And Text22.Text <= 89) Then
Text34.Text = "A"
ElseIf (Text22.Text >= 70 And Text22.Text <= 79) Then
Text34.Text = "B"
ElseIf (Text22.Text >= 60 And Text22.Text <= 69) Then
Text34.Text = "c"
ElseIf (Text22.Text >= 55 And Text22.Text <= 59) Then
Text34.Text = "D"
ElseIf (Text22.Text >= 50 And Text22.Text <= 54) Then
Text34.Text = "E"
ElseIf (Text22.Text <= 50) Then
Text34.Text = "F"
End If
Text25.Text = Val(Text23.Text) + Val(Text24.Text)
h = Text25.Text
If (Text25.Text >= 90 And Text25.Text <= 100) Then
Text35.Text = "s"
ElseIf (Text25.Text >= 80 And Text25.Text <= 89) Then
Text35.Text = "A"
ElseIf (Text25.Text >= 70 And Text25.Text <= 79) Then
Text35.Text = "B"
ElseIf (Text25.Text >= 60 And Text25.Text <= 69) Then
Text35.Text = "c"
ElseIf (Text25.Text >= 55 And Text25.Text <= 59) Then
Text35.Text = "D"
ElseIf (Text25.Text >= 50 And Text25.Text <= 54) Then
Text35.Text = "E"
ElseIf (Text25.Text <= 50) Then
Text35.Text = "F"
End If
c = Val(Text7.Text) + Val(Text10.Text) + Val(Text13.Text) + Val(Text16.Text) +
Val(Text19.Text) + Val(Text22.Text) + Val(Text25.Text)
Text28.Text = c
Label28.Caption = Val(Text28.Text)
avg = c / 7
Label30.Caption = avg
If p < 50 Or q < 50 Or r < 50 Or s < 50 Or u < 50 Or d < 50 Or h < 50 Then
Label29.Caption = "Fail"
Else
Label29.Caption = "Pass"
End If
Text19.Text = ""
Text20.Text = ""
Text21.Text = ""
Text22.Text = ""
Text23.Text = ""
Text24.Text = ""
Text25.Text = ""
Text26.Text = ""
Text27.Text = ""
Text28.Text = ""
Text29.Text = ""
Text30.Text = ""
Text31.Text = ""
Text32.Text = ""
Text33.Text = ""
Text34.Text = ""
Text35.Text = ""
Label28.Caption = ""
Label29.Caption = ""
Label30.Caption = ""
Label39.Caption = ""
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Timer1_Timer()
Label9.Caption = Time
Label10.Caption = Date
End Sub
Output :
Result : Thus a Visual Basic program to create a student database has been implemented and
executed successfully.
Procedure :
1. Start -> programs->Microsoft Visual Studio 6.0-> Microsoft Visual Basic
2. Select File->New->Standard.exe. Give project name and then choose empty project
button->finish->ok.
3. Design the form with 4 label boxes, 4 text boxes and 9 command buttons.
4. Display appropriate messages in the label boxes.
5. Write script in the Click events of the insert, edit, delete, save, exit, first, next, previous
and last command buttons and set the properties.
6. Stop.
Source Code :
Dim db As Database
Dim rs As Recordset
Dim rs1 As Recordset
Dim sql As String
Private Sub Command3_Click()
Set rs1 = db.OpenRecordset("select count(*) from student1 where Rollno=" & Val(Text1.Text))
If Text1.Text = "" Then
MsgBox "enter a valid roll number"
Exit Sub
End If
If rs1(0) = 0 Then
MsgBox ("there are no records with this roll number")
Exit Sub
End If
db.Execute ("delete from student1 where rollno=" &Val(Text1.Text))
MsgBox ("record deleted")
End Sub
Private Sub Command4_Click()
If Command1.Enabled = False Then
sql = " insert into student1 values(" &CInt(Text1.Text) & ",'" & Text2.Text & "','" & Text3.Text
& "'," &CDbl(Text4.Text) & ")"
MsgBoxsql
db.Execute (sql)
MsgBox ("record inserted")
Command1.Enabled = True
End If
If Command2.Enabled = False Then
sql = "update student1 set name='" & Text2.Text & " ',address='" & Text3.Text &
"',mobilenumber=" &CDbl(Text4.Text) & " where (RollNO= " &CInt(Txt_ROllNo.Text) & ")"
MsgBoxsql
db.Execute (sql)
MsgBox ("record updated")
Command2.Enabled = True
End If
End Sub
Private Sub Command6_Click()
rs.MoveFirst
Show_Data
End Sub
Private Sub Command7_Click()
rs.MoveNext
Show_Data
End Sub
Private Sub Command8_Click()
rs.MovePrevious
Show_Data
End Sub
Private Sub Command9_Click()
rs.MoveLast
Show_Data
End Sub
Private Sub Form_Load()
Set db = OpenDatabase("D:\aaa.mdb", True)
Set rs = db.OpenRecordset("student", dbOpenDynaset)
rs.MoveFirst
End Sub
Private Sub Show_Data()
If rs.EOF Then
rs.MoveLast
End If
If rs.BOF Then
rs.MoveFirst
End If
Text1.Text = rs(0)
Text2.Text = rs(1)
Text3.Text = rs(2)
Text4.Text = rs(3)
End Sub
Private Sub Clear_Controls()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Output :
Result : Thus the Visual Basic program to create a database using data control has been
implemented and executed successfully.
Cycle II
Visual C++
PALINDROME CHECKING
Ex. No: 14
Aim:
To implement a VC++ program to find whether a given string is a palindrome or not.
Procedure :
1. Start
2. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish.
3. Place the Static texts, edit boxes, command Buttons as shown in the form Layout.
4. On clicking the palindrome Button, display whether the given string is palindrome or not.
5. Stop.
Property Settings
Control
Button
Button
Name
button1
button2
Member Variables:
Control
Category
IDC_EDIT1
VALUE
Form Design :
Property
caption
caption
Value
Is Palindrome
Exit
Type
Cstring
Variable Name
m_edit1
Output :
Result : Thus a VC++ program to check whether a given string is a palindrome or not is
implemented and executed successfully.
Form Design :
Name
button1
button2
Property
caption
caption
Value
Compute
Exit
Category
Control
Type
CList
Variable Name
m_list1
str=" ";
for(j=1;j<=i;j++)
{
st.Format(("%d"),i);
str=str+st;
}
m_list1.AddString(str);
}
}
void prog14::OnButton2()
{
exit(0);
}
Output :
Result : Thus the VC++ program to print pattern numbers has been implemented and executed
successfully.
MINIPAINT APPLICATION
Ex. No: 16
Aim:
To implement a VC++ program to handle menus on a window.
Procedure:
1. Start
2. Create menus as follows.
Source code:
// CProg15View message handlers
int s,b,p;
void CProg15View::OnShapesEllipse()
{
s=1;
Invalidate();
}
void CProg15View::OnShapesLine()
{
s=2;
Invalidate();
}
void CProg15View::OnShapesRectangle()
{
s=3;
Invalidate();
}
void CProg15View::OnColorPenRed()
{
p=1;
Invalidate();
}
void CProg15View::OnColorPenGreen()
{
p=2;
Invalidate();
}
void CProg15View::OnColorPenBlue()
{
p=3;
Invalidate();
}
void CProg15View::OnColorBrushRed()
{
b=1;
Invalidate();
}
void CProg15View::OnColorBrushGreen()
{
b=2;
Invalidate(); }
void CProg15View::OnColorBrushBlue()
{
b=3;
Invalidate();
}
void CProg15View::OnPaint()
{
CPaintDC dc(this); // device context for painting
CPen P;
CBrush B;
switch(p)
{
case 1:
P.CreatePen(PS_SOLID,2,RGB(255,0,0));
break;
case 2:
P.CreatePen(PS_SOLID,2,RGB(0,255,0));
break;
case 3:
P.CreatePen(PS_SOLID,2,RGB(0,0,255));
break;
}
switch(b)
{
case 1:
B.CreateSolidBrush(RGB(255,0,0));
break;
case 2:
B.CreateSolidBrush(RGB(0,255,0));
break;
case 3:
B.CreateSolidBrush(RGB(0,0,255));
break;
}
dc.SelectObject(&P);
dc.SelectObject(&B);
switch(s)
{
case 1:
dc.MoveTo(100,100);
dc.LineTo(200,200);
break;
case 2:
case 3:
}
}
dc.Rectangle(80,80,160,160);
break;
dc.Ellipse(30,20,80,80);
break;
Output :
Result : Thus a Visual C++ program to handle menus in a window has been implemented and
executed successfully.
FILE OPERATIONS
Ex. No: 17
Aim:
To implement a Visual C++ program to copy files.
Procedure:
1. Start
2. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based -> Finish.
3. Place 2 label boxes, 2 edit boxes and 2 command buttons as shown in the form layout.
4. Display appropriate messages in the label boxes.
5. On clicking the copy command button, write code to copy the contents of source file to
destination file.
6. Write code for the exit command button.
7. Stop.
Property Settings
Control
Button
Button
Control
IDC_EDIT1
IDC_EDIT2
Form Design:
Name
button1
button2
Property
caption
caption
Value
Copy
Exit
Category
Value
Value
Type
CString
CString
Variable Name
m_edit1
m_edit2
Source Code:
// prog16 message handlers
void prog16::OnButton1()
{
char szbuffer[100];
UINT nACTUAL=0, pos=0;
CFile myfile, myfile1;
UpdateData(true);
myfile.Open(m_edit1,CFile::modeReadWrite);
myfile.Open(m_edit2,CFile::modeCreate|CFile::modeReadWrite);
while(1)
{
myfile.Seek(pos,CFile::begin);
nACTUAL=myfile.Read(szbuffer,100);
myfile.Write(szbuffer,100);
pos=pos+nACTUAL;
if(nACTUAL==0)
{
MessageBox("file copied");
exit(0);
}
}
}
void prog16::OnButton2()
{
exit(0);
}
Output :
Result : Thus a Visual C++ program to copy files has been implemented and executed
successfully.
MOUSE INTERFACE
Ex. No: 18
Aim:
To implement a VC++ program for mouse interface.
Procedure:
1. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based ->
Finish.
2. Place the edit box, Static Text and command buttons as shown in the form layout.
3. Write code to count the number of mouse clicks by counting the mouse events.
4. Stop
Control
Button
Name
button1
Property
Caption
Value
Exit
Events:
OnRButtonDown(), OnLButtonDown, OnLButtonDblClk(), OnRButtonDblClk().
SetDlgItemInt().
Form Design :
Source code :
int count1,count2;
void prog17::OnLButtonDblClk(UINT nFlags, CPoint point)
{
count1++;
SetDlgItemInt(IDC_EDIT1,count1);
CFormView::OnLButtonDblClk(nFlags, point);
}
void prog17::OnLButtonDown(UINT nFlags, CPoint point)
{
count1++;
SetDlgItemInt(IDC_EDIT1,count1);
CFormView::OnLButtonDown(nFlags, point);
}
void prog17::OnRButtonDblClk(UINT nFlags, CPoint point)
{
count2++;
SetDlgItemInt(IDC_EDIT2,count2);
CFormView::OnRButtonDblClk(nFlags, point);
}
void prog17::OnRButtonDown(UINT nFlags, CPoint point)
{
count2++;
SetDlgItemInt(IDC_EDIT2,count2);
CFormView::OnRButtonDown(nFlags, point);
}
void prog17::OnButton1()
{
exit(0);
}
Output :
Result : Thus a Visual C++ program for mouse interface has been implemented and executed
successfully.
ACTIVEX CONTROL
Ex. No: 19
Aim:
To implement a VC++ program to insert an ActiveX control in an application.
Procedure:
1. Start
2. Create a MFC application by selecting, File -> New -> MFC .exe -> Dialog Based ->
Finish.
3. Place the ActiveX object and buttons as shown in the form layout.
4. To insert the Active X Calendar, right Click on the form -> Insert Active X Control ->
Calendar Control 12.0.
5. On clicking the OK button, display a Message box.
6. Stop
Control
Button
Button
Events:
OnButton()
Form Design:
Name
button1
button2
Property
Caption
Caption
Value
Message
OK
Source code :
oid prog18::OnButton1()
{
MessageBox("ActiveX controls");
}
void prog18::OnButton2()
{
exit(0);
}
Output :
Result : Thus a Visual C++ program to insert an ActiveX control has been implemented and
executed successfully.
2. Create a WIN32 application by selecting, File -> New -> Win32 .exe -> Finish.
3. To include a new C File, file -> New -> C Source File.
4. Read the free Memory Available in the system.
5. Store it in a buffer.
6. Display the Message box.
7. Stop
Form Design :
Result : Thus the Visual C++ program to display a message box has been implemented and
executed successfully.
Function Declaration
CString
SayHello(CString strName)
4. In the File view tab on the workspace, open the Header file folder and double click on the
MyClass.h and add __declspec(dllexport) infront of all functions that are used for
external application
5. In the File view tab on the workspace, open the MyClass.cpp from source file folder and
type the code.
6. Compile & Build the project
To create a new application that use the DLL.
1. Create a project named TestDll from File->New , select the MFCAppwizard(exe) , select
Dialog based application and accept the default values for the next step and finish it.
2. A dialog will appear.Design the dialog window using necessary controls as follows
3. Open class wizard from the view menu, click member variable tab and choose
IDC_EDIT1 and click add member variable and type as follows.
Variable name
Type
Category
m_edit
Value
Cstring
4. Double click the OK button on the dialog window, then the OnOk function will be
generated.
5. In the file view tab on the work space window, open the TestDllDlg.h to include
MyClass.h and to declare object of that class and add the codes and include
#include ..\MyDll\MyClass.h
6. Select the Project->Settings->Link and in the Object/library modules enter a path to the
DLL library file as follows.
..\MyDll\Debug\MyDll.lib
7. Copy the MyDll.dll file from MyDll\Debug folder and paste it into the TestDll\Debug
folder.
8. Build and execute the project
Source code
//MyClass.hc
lass
CMyClass
{public:
__declspec(dl
lexport)CStrin
gSayHello(CS
tringstrName)
;
__declspec(dllexport)CMyClass();
__declspec(dllexport)virtual ~CMyClass();
};
//MyClass.cpp
CStringCMyClass::SayHello(CStringstrName)
{
}
TESTDLL
//TestDllDlg.h
#include
"..\MyDll\MyClass.h" class
CTestDllDlg : public CDialog
{public:
CMyClassobjMyClass;
CTestDllDlg(CWnd* pParent = NULL);
};
//TestDllDlg.cpp
voidCTestDllDlg::On
OK( ) {
UpdateData(true);
CStringstr=objMyClass.SayHello(m_strText);
AfxMessageBox(str);
CDialog::OnOK();
}
Output :
Result : Thus a Visual C++ program to create and use DLL has been implemented and
executed successfully.