Vous êtes sur la page 1sur 48

VISUAL PROGRAMMING

PRACTICAL FILE

SUBMITTED BY:
Mukesh Kumar
ROLL NO. : - 11003148

Mukesh Kumar

11003148

INDEX
1. LOAN CALCULATOR
2. STOP WATCH
3. NOTEPAD
4. STUDENTS LETTER GRADE
5. COLLECTIONS
6. THE USE OF FILE CONTROLS
7. MATHEMATICS CALCULATOR
8. TO DRAW DIRECTLY ON A FORM
9. TILLING PICTURE
10. GENERIC CONTROL
11. MDI
12. DATA PROJECT

Mukesh Kumar

11003148

LOAN CALCULATOR
Dim P As Single
Dim R As Single
Dim T As Single
Private Sub Command1_ Click ()
P = Val(Text1.Text)
R = Val(Text2.Text)
T = Val(Text3.Text)
Text4.Text = (P * R * T) / 100
Text5.Text = P + ((P * R * T) / 100)
End Sub
Private Sub Command2_ Click ()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""

Text5.Text = ""
End Sub
Private Sub Command3_ Click ()
Unload Me
End Sub

DESIGN TIME

Mukesh Kumar

RUN TIME

11003148

Mukesh Kumar

11003148

STOP WATCH
Dim M As Integer
Dim S As Integer
Dim T As Integer
Private Sub Command1_Click()
If Command1.Caption = "STOP" Then
Command1.Caption = "START"
Timer1.Enabled = False
Else
Command1.Caption = "STOP"
Timer1.Enabled = True
End If
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
Command1.Caption = "START"
Text4.Text = Text4.Text & Text1.Text & ":" & Text2.Text & ":" & Text3.Text & vbCrLf
T=0
M=0
S=0
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Timer1_Timer()
T=T+1
If T = 99 Then
S=S+1
T=0
End If

Mukesh Kumar
If S = 59 Then
M=M+1
S=0
End If
Text1.Text = M
Text2.Text = S
Text3.Text = T
End Sub

DESIGN TIME

11003148

Mukesh Kumar

RUN TIME

11003148

Mukesh Kumar

11003148

NOTEPAD

Mukesh Kumar

FORM 1
Private Sub COLOURMENU_Click()
CMD.ShowColor
Text1.SelColor = CMD.Color
End Sub

Private Sub COPYMENU_Click()


Clipboard.SetText Text1.SelText
PASTEMENU.Enabled = True
End Sub
Private Sub CUTMENU_Click()
Clipboard.SetText Text1.SelText
Text1.SelText = ""
PASTEMENU.Enabled = True
End Sub
Private Sub EXITMENU_Click()
Unload Me
End Sub
Private Sub FINDMENU_Click()
Form2.Show
End Sub

Private Sub FONTMENU_Click()


CMD.Flags = cdlCFScreenFonts
CMD.ShowFont
Text1.SelFontName = CMD.FontName
Text1.SelFontSize = CMD.FontSize
Text1.SelBold = CMD.FontBold
Text1.SelItalic = CMD.FontItalic

11003148

Mukesh Kumar
End Sub

Private Sub Form_Resize()


Text1.Height = Form1.Height
Text1.Width = Form1.Width
End Sub
Private Sub NEWMENU_Click()
Text1.Text = ""
End Sub
Private Sub OPENMENU_Click()
CMD.Filter = "TEXT FILES (*.txt)|*.txt"
CMD.ShowOpen
Dim IFILE As Integer
IFILE = FreeFile
Open CMD.FileName For Input As #IFILE
Text1.Text = Input(LOF(IFILE), #IFILE)
End Sub
Private Sub PASTEMENU_Click()
Text1.SelText = Clipboard.GetText
Clipboard.Clear
PASTEMENU.Enabled = False
End Sub
Private Sub SAVEMENU_Click()
CMD.Filter = "TEXT FILES (*.txt)|*.txt"
CMD.ShowSave
Dim IFILE As Integer
IFILE = FreeFile
Open CMD.FileName For Output As #IFILE
Print #IFILE, Text1.Text
End Sub

11003148

Mukesh Kumar

11003148

Private Sub SELECTMENU_Click()


Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
Private Sub TIMEMENU_Click()
Text1.SelText = Now
End Sub

FORM 2
Dim START As Integer
Private Sub Command1_Click(Index As Integer)
START = Form1.Text1.SelStart + Form1.Text1.SelLength + 1
Form1.Text1.SelStart = InStr(START, Form1.Text1.Text, Form2.Text1.Text) - 1
If Form1.Text1.SelStart = -1 Then
MsgBox "NOT FOUND"
End If
Form1.Text1.SelLength = Len(Form2.Text1)
Form1.Text1.SetFocus
End Sub
Private Sub Command2_Click(Index As Integer)
Form1.Text1.SelText = Text2.Text
End Sub
Private Sub DONE_Click(Index As Integer)
Form1.SetFocus
Unload Me
End Sub
Private Sub Form_Activate()
Text1.SetFocus
End Sub
Private Sub Form_Load()

Mukesh Kumar
START = 1
End Sub

DESIGN TIME ( FORM 1 )

11003148

Mukesh Kumar

DESIGN TIME ( FORM 2 )

11003148

Mukesh Kumar

RUN TIME

11003148

Mukesh Kumar

11003148

Mukesh Kumar

11003148

Mukesh Kumar

11003148

STUDENT'S LETTER GRADE (USING SELECT CASE)


Dim A As Single
Private Sub Command1_Click()
A = Text1.Text
Select Case A
Case 91 To 100
Label3.Caption = "A+ GRADE"
Case 81 To 90
Label3.Caption = "A GRADE"
Case 71 To 80
Label3.Caption = "B+ GRADE"
Case 61 To 70
Label3.Caption = "B GRADE"
Case 51 To 60
Label3.Caption = "C GRADE"
Case 40 To 50
Label3.Caption = "D GRADE"
Case Else
Label3.Caption = "FAIL"
End Select
End Sub

DESIGN TIME

Mukesh Kumar

11003148

RUNTIME

COLLECTIONS

Mukesh Kumar

Dim S As String
Dim TEMP As New Collection
Dim A As Integer
Private Sub Command1_Click()
On Error GoTo NOTFOUND:
S = InputBox("ENTER THE CITY ")
A = TEMP.Item(S)
MsgBox " THE TEMPERATURE OF THE CITY ENTERED IS" & A
Exit Sub
NOTFOUND:
MsgBox " CITY NOT FOUND"
End Sub
Private Sub Command2_Click()
For Each CITY In TEMP
TOTAL = TOTAL + CITY
Next
AVERAGE = TOTAL / TEMP.Count
MsgBox ("THE AVERAGE TEMPERATURE IS" & AVERAGE)
End Sub
Private Sub Form_Load()
TEMP.Add 34, "DELHI"
TEMP.Add 39, "KOKATTA"
TEMP.Add 30, "MUMBAI"
TEMP.Add 27, "CHENNAI"
End Sub

DESIGN TIME

11003148

Mukesh Kumar

RUNTIME

11003148

Mukesh Kumar

11003148

WINDOWS APPLICATION DEMONSTRATING THE


USE OF FILE CONTROLS

Private Sub Dir1_Change()


File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()


Dir1.Path = Drive1.Drive
End Sub

DESIGN TIME

Mukesh Kumar

RUNTIME

11003148

Mukesh Kumar

MATHEMATICS CALCULATOR
Dim A As Single
Dim B As Single
Dim OP As String
Private Sub Command1_Click(Index As Integer)
Text1.Text = Text1.Text & Command1(Index).Caption
End Sub
Private Sub Command2_Click(Index As Integer)
Text1.SelStart = Text1.MaxLength - 2
Text1.SelLength = Len("1")
Text1.SetFocus
Text1.SelText = ""
End Sub
Private Sub Command3_Click(Index As Integer)
A = Val(Text1.Text)
OP = Command3(Index).Caption
Text1.Text = ""
End Sub
Private Sub Command4_Click(Index As Integer)
B = Val(Text1.Text)
If OP = "+" Then Text1.Text = A + B
If OP = "-" Then Text1.Text = A - B
If OP = "*" Then Text1.Text = A * B
If OP = "/" Then
If B = 0 Then
Text1.Text = "CANT DEVIDE BY0"
Exit Sub
End If
Text1.Text = A / B

11003148

Mukesh Kumar
End If
End Sub
Private Sub Command5_Click(Index As Integer)
If InStr(Text1.Text, ".") Then
Exit Sub
Else
Text1.Text = Text1.Text & "."
End If
End Sub
Private Sub Command6_Click(Index As Integer)
A=0
B=0
Text1.Text = ""
End Sub
Private Sub Text1_Change()
Text1.MaxLength = Len(Text1.Text) + 1
End Sub

DESIGN TIME

11003148

Mukesh Kumar

RUNTIME

11003148

Mukesh Kumar

11003148

WINDOWS APPLICATION THAT USES GRAPHICAL


METHODS TO DRAW DIRECTLY ON A FORM
Dim X1 As Single
Dim Y1 As Single
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y
As Single)
Form1.MousePointer = 2
X1 = X
Y1 = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y
As Single)
If Option3.Value = True Then
Line (X1, Y1)-(X, Y)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As
Single)
If Option2.Value = True Then
Circle (X1, Y1), Abs(X - X1)
End If
If Option1.Value = True Then
Line (X1, Y1)-(X, Y)
End If
If Option6.Value = True Then
Form1.DrawMode = 13
Line (X1, Y1)-(X, Y), , B
End If
If Option5.Value = True Then
Circle (X1, Y1), Abs(X - X1), , , , 0.75

Mukesh Kumar
End If
Form1.MousePointer = 0
End Sub
Private Sub Option4_Click()
If Option4.Value = True Then
Form1.Cls
End If
End Sub

DESIGN TIME

11003148

Mukesh Kumar

RUN TIME

11003148

Mukesh Kumar

11003148

WINDOWS APPLICATION THAT TILES A PICTURE


ACROSS A FORM'S BACKGROUND AT RUNTIME
Dim W As Double, H As Double
Dim I As Integer, J As Integer
Private Sub Form_Paint()
W = Form1.Width / Picture1.Width
H = Form1.Height / Picture1.Height
For I = O To W
For J = 0 To H
Form1.PaintPicture Picture1.Picture, Picture1.Width * I, J * Picture1.Height
Next J,Next I
End Sub

DESIGN TIME

Mukesh Kumar

RUN TIME

11003148

Mukesh Kumar

GENERIC CONTROLS
CODING
1.FORM
Private Sub Command1_Click()
UserControl11.title = "fdnfkdfjdsfk"
End Sub

2.USER CONTROL
Private m_title As String
Const m_def_title = "genric control"

Public Property Get title() As String


title = m_title
End Property
Public Property Let title(ByVal vnewvalue As
String)
m_title = vnewvalue
PropertyChanged "title"
UserControl_Paint
End Property

Private Sub Command1_Click()

11003148

Mukesh Kumar

11003148

title = "dfsds"
End Sub
Private Sub UserControl_Initialize()
m_title = m_def_title
End Sub

Private Sub UserControl_Paint()


UserControl.CurrentX = 0
UserControl.CurrentY = 0
UserControl.Print m_title
End Sub
Private Sub UserControl_ReadProperties(PropBag
As PropertyBag)
m_title = PropBag.ReadProperty("title",
m_def_title)
End Sub

Private Sub
UserControl_WriteProperties(PropBag As
PropertyBag)
Call PropBag.WriteProperty("title", m_title,
m_def_title)
End Sub

Mukesh Kumar

DESIGN
1.FORM

11003148

Mukesh Kumar

2. USERCONTROL

11003148

Mukesh Kumar

RUNTIME

11003148

Mukesh Kumar

11003148

M.D.I FORM
CODING
1.FORM 1
Dim i As Integer
Private Sub Command1_Click()
Load Form2
Form2.Show
End Sub

2.FORM2
Private Sub Form_Load()
Load Form3
Form3.Show
End Sub

Mukesh Kumar

DESIGN
FORM1

11003148

Mukesh Kumar

FORM2

11003148

Mukesh Kumar

M.D.I FORM 1

RUNTIME

11003148

Mukesh Kumar

11003148

DATA PROJECT

Mukesh Kumar

11003148

CODING
Private Sub Command1_Click()
Data1.Recordset.MoveFirst
End Sub

Private Sub Command10_Click()


DataEnvironment1.rsCommand1.MovePrevious
If DataEnvironment1.rsCommand1.BOF Then
MsgBox "first record"
DataEnvironment1.rsCommand1.MoveLast
End If
End Sub

Private Sub Command11_Click()


DataEnvironment1.rsCommand1.MoveNext
If DataEnvironment1.rsCommand1.BOF Then
MsgBox "first record"
DataEnvironment1.rsCommand1.MoveFirst
End If
End Sub

Private Sub Command12_Click()

Mukesh Kumar

DataEnvironment1.rsCommand1.MoveLast
End Sub

Private Sub Command14_Click()


DataReport1.Show
End Sub

Private Sub Command15_Click()


Data1.Recordset.AddNew

End Sub

Private Sub Command16_Click()


Data1.Recordset.Update

End Sub

Private Sub Command17_Click()


Data1.Recordset.Delete
Data1.RECORDSSET.MoveNext

End Sub

11003148

Mukesh Kumar

Private Sub Command18_Click()


Adodc1.Recordset.Update

End Sub

Private Sub Command19_Click()


Adodc1.Recordset.AddNew

End Sub

Private Sub Command2_Click()


Data1.Recordset.MoveLast
End Sub

Private Sub Command20_Click()


Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
End Sub

Private Sub Command22_Click()


Dim A As New ADODB.Connection

11003148

Mukesh Kumar

11003148

Dim B As New ADODB.Recordset


A.Provider = "Microsoft.Jet.OLEDB.3.51"
B.Open
"C:\Users\harmandeep\Documents\harmandeep.
mdb"
B.Open "COLLEGE", A
For Each f In B.Fields

Print f.Name
Next
End Sub

Private Sub Command3_Click()


Data1.Recordset.MoveNext
If Data1.Recordset.EOF Then
MsgBox "last record"
Data1.Recordset.MoveFirst
End If
End Sub

Private Sub Command4_Click()


Data1.Recordset.MovePrevious
If Data1.Recordset.BOF Then

Mukesh Kumar

MsgBox "first record"


Data1.Recordset.MoveLast
End If
End Sub

Private Sub Command5_Click()


Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
MsgBox "first record"
Adodc1.Recordset.MoveLast
End If
End Sub

Private Sub Command6_Click()


Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
MsgBox "last record"
Adodc1.Recordset.MoveFirst
End If
End Sub

Private Sub Command7_Click()

11003148

Mukesh Kumar

Adodc1.Recordset.MoveLast
End Sub

Private Sub Command8_Click()


Adodc1.Recordset.MoveFirst
End Sub

Private Sub Command9_Click()


DataEnvironment1.rsCommand1.MoveFirst
End Sub

DESIGN

11003148

Mukesh Kumar

RUNTIME

11003148

Mukesh Kumar

11003148