VB RECORD Programs Forprint

Download as pdf or txt
Download as pdf or txt
You are on page 1of 57

SIMPLE APPLICATION

FORM DESIGN

SOURCE CODE

Private Sub Command1_Click()


Cls
Form1.BackColor = RGB(200, 400, 300)
Dim a As Integer
For a = 0 To 20 Step 2
Print a
Next a
End Sub

Private Sub Command2_Click()


Cls
Form1.BackColor = RGB(100, 150, 200)
Dim a As Integer
For a = 20 To 1 Step -2
Print a
Next a
Form1.ForeColor = RGB(200, 300, 400)
End Sub

Private Sub Command3_Click()


Cls
Form1.BackColor = RGB(200, 150, 100)
Dim a As Integer
For a = 1 To 20 Step 2
Print a
Next a
Form1.ForeColor = RGB(200, 300, 400)
End Sub

Private Sub Command4_Click()


Cls
Form1.BackColor = RGB(250, 150, 120)
Dim a As Integer
For a = 19 To 1 Step -2
Print a
Next a
Form1.ForeColor = RGB(250, 200, 200)
End Sub

Private Sub Command5_Click()


Cls
Dim a As Integer, i As Integer, fact As Double
a = InputBox("enter the nmber to find its factorial")
fact = 1
For i = 2 To a
fact = fact * i
Next i
MsgBox (a & " != " & fact)
End Sub

Private Sub Command6_Click()


Cls
Form1.BackColor = RGB(100, 120, 190)
Dim a As Integer, sum As Integer, i As Integer
i = InputBox("enter the upper limit")
For a = 1 To i
sum = sum + a
Print a
Next a
Form1.ForeColor = RGB(200, 150, 120)
MsgBox ("sum=" & sum)
End Sub

Private Sub Command7_Click()


Cls
End Sub

Private Sub Command8_Click()


End
End Sub

Private Sub Form_Load()


Form1.WindowState = 2
Form1.FontBold = True
Form1.ForeColor = RGB(250, 200, 500)
End Sub
OUTPUT
DISPLAY OF COLOURS USING SCROLL BAR

FORM DESIGN

SOURCE CODE

Private Sub hscroll1_Change()


lblpreview.BackColor = QBColor(hscroll1.Value)
lblqbc.Caption = hscroll1.Value
End Sub

Private Sub VScroll1_Change()


lblpreview.BackColor = RGB(VScroll1.Value, VScroll2.Value,
VScroll3.Value)
lblred = VScroll1.Value
End Sub

Private Sub VScroll2_Change()


lblpreview.BackColor = RGB(VScroll1.Value, VScroll2.Value,
VScroll3.Value)
lblgreen = VScroll2.Value
End Sub

Private Sub VScroll3_Change()


lblpreview.BackColor = RGB(VScroll1.Value, VScroll2.Value,
VScroll3.Value)
lblblue = VScroll3.Value
End Sub
OUTPUT
PASSWORD CHECKING USING VARIABLES

FORM DESIGN

SOURCE CODE
Dim password As String

Private Sub Command1_Click()


If Text2.Text = password Then
MsgBox ("Sucessfully logged in:" & Text1.Text)
Label3.Visible = True
Label4.Visible = True
Command2.Visible = True
Text3.Visible = True
Text4.Visible = True
Label1.Visible = False
Label2.Visible = False
Command1.Visible = False
Text1.Visible = False
Text2.Visible = False
Label5.Caption = "Hello" & " " & Text1.Text & " " &
"update the require details"
Command3.Visible = True
Else
Text2.Text = ""
Text2.SetFocus
MsgBox ("invalid password")
End If
End Sub

Private Sub Command2_Click()


MsgBox ("CHECK YOUR DATA...." & " " & Text1.Text & " " &
Text3.Text & " " & Text4.Text & " " & "are correct")
End Sub

Private Sub Command3_Click()


Text3.Text = ""
Text4.Text = ""
End Sub

Private Sub Form_Load()


Text2.Text = ""
password = "vb6"
Label3.Visible = False
Label4.Visible = False
Command2.Visible = False
Text3.Visible = False
Text4.Visible = False
Command3.Visible = False
End Sub

OUTPUT
DISPLAY DATE USING DIALOG BOXES
FORM DESIGN

SOURCE CODE
Dim result As String

Private Sub Command1_Click()


Dim message As String
Dim dialogtype As Integer
Dim title As String
message = "Welcome to Department of Computer Science"
dialogtype = vbOK + vbInformation
title = "DEMO OF DIALOG BOXES"
MsgBox message, dialogtype, title
End Sub

Private Sub Command2_Click()


Dim i, day, msg
i = InputBox("Enter a Date:", "Date Demo")
If Not IsDate(i) Then
MsgBox "invalid Date"
Exit Sub
End If
day = Format(i, "dddd")
msg = "Day of this Date is:" + day
MsgBox msg
MsgBox ("YOUR NAME IS: " & result & " " & "UR BIRTHDAY FALLS
ON :" & " " & day)
End Sub
Private Sub Command3_Click()
Dim i As String
i = InputBox("Enter your Name:", "Input Demo")
MsgBox "Your Name is:" &i
result = i
End Sub

Private Sub Command4_Click()


Dim message As String
Dim dialogtype As Integer
Dim title As String
Dim response As Integer
message = "Thank You,Visit again"
dialogtype = vbYesNo + vbInformation
title = "Good Bye"
response = MsgBox(message, dialogtype, title)
If response = vbYes Then
End If
End Sub

Private Sub Form_Load()


Label1.BackColor = vbCyan
Label1.ForeColor = vbRed
Form2.BackColor = RGB(250, 200, 500)
Command1.Caption = "WELCOME MESSAGE"
Command1.FontName = "arial"
Command2.Caption = "ENTER UR DOB TO CHECK THE DAY OF UR BIRTH"
Command2.FontName = "Times New Roman"
Command3.Caption = "ENTER YOUR NAME"
Command3.FontName = "Calibri"
Command4.Caption = "EXIT"
Command4.FontName = "Monotype Corsiva"
End Sub

Private Sub Timer1_Timer()


If (Label1.Left + Label1.Width) <= 0 Then
Label1.Left = Me.Width
End If
Label1.Left = Label1.Left - 25
End Sub
OUTPUT
STUDENT DETAILS USING CONTROLS WITH VALIDATIONS
FORM DESIGN

SOURCE CODE
Private Sub Command1_Click()
Dim str As String
str = Text6.Text
If str Like "[a-z a-z 0-9]*@[a-z A-z 0-9]*.[a-z A-z]*" Then
MsgBox "Email id is valid"
Else
MsgBox "Email id not valid"
End If
End Sub

Private Sub Command2_Click()


Dim s As String
If Option1.Value = True Then
s = "male"
End If
If Option2.Value = True Then
s = "female"
End If
If Check1.Value = 1 Then
List1.AddItem (Text1.Text) + "--" + Text2.Text + "--" + s
+ "--" + Text4.Text + "--" + Text5.Text
Else
List2.AddItem (Text1.Text) + "--" + Text2.Text + "--" + s
+ "--" + Text4.Text + "--" + Text5.Text
End If
End Sub
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Option1 = False
Option2 = False
Check1.Value = 0
Check2.Value = 0
End Sub

Private Sub Command4_Click()


End
End Sub

Private Sub Form_Load()


Text4.Enabled = True
Text5.Enabled = True
End Sub

Private Sub Text1_keypress(keyascii As Integer)


If (keyascii >= vbKey0) And (keyascii <= vbKey9) Then
Exit Sub
Else
keyascii = 0
End If
End Sub

Private Sub Text2_keypress(keyascii As Integer)


If (keyascii >= vbKeyA And vbKeyZ) Or (keyascii = 97 And
keyascii < 122) Or (keyascii <= vbkey) Then
Exit Sub
Else
keyascii = 0
End If
End Sub
OUTPUT
ELECTRICITY CHARGES CALCULATION USING CONDITIONALS
FORM DESIGN

SOURCE CODE
Private Sub Command1_Click()
Dim A, B As Integer
If Text1.Text = "" Then
MsgBox "bill no"
Text1.SetFocus
Exit Sub
End If
If Text2.Text = "" Then
MsgBox "name"
Text2.SetFocus
Exit Sub
End If
If Text3.Text = " " Then
MsgBox "enter the unit"
Text3.SetFocus
Exit Sub
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Option1 = False
Option2 = False
End Sub
Private Sub Option1_Click()
A = Val(Text3.Text)
B = Val(Text4.Text)
If A = "" Then
Text5.Text = ""
ElseIf (A > 1) And (A <= 100) Then
= "free"
End If
End Sub

Private Sub Option2_Click()


A = Val(Text3.Text)
B = Val(Text4.Text)
If (A > 1) And (A <= 100) Then
Text5.Text = A * 2.5 + B
ElseIf (A <= 200) Then
Text5.Text = A * 3 + B
ElseIf (A <= 500) Then
Text5.Text = A * 4.6 + B
ElseIf (A > 500) Then
Text5.Text = A * 6.6 + B
ElseIf (A <= 0) Then
Text5.Text = ""
End If
End Sub

Private Sub Text1_keypress(keyascii As Integer)


If (keyascii >= vbKey0) And (keyascii <= vbKey9) Then
ElseIf (A <= 0) Then
Text5.Text = ""
End If
End Sub

Private Sub Text2_keypress(ascii As Integer)


If (keyascii >= vbKeyA And keyascii <= vbKeyZ) Then
Exit Sub
Else
keyascii = 0
End If
End Sub

Private Sub Text3_Change()


A = Val(Text3.Text)
If (A > 1) And (A <= 100) Then
Text4.Text = "30"
ElseIf (A <= 200) Then
Text4.Text = "40"
ElseIf (A > 200) Then
Text4.Text = "50"
End If
End Sub
Private Sub timer1_timer()
lbldate.Caption = Date
End Sub
OUTPUT
PRIME NUMBER AND SECRET NUMBER USING CONDITIONAL
STATEMENT
FORM DESIGN

SOURCE CODE
Dim secret_number As Integer

Private Sub Command1_Click()


Label1.Visible = True
Dim your_number As Integer
your_number = InputBox("Enter a number between 1 and 6
inclusive")
Select Case your_number
Case Is < secret_number
MsgBox ("Your number is smaller then the secret
number,try again!")
Case Is > secret_number
MsgBox ("Your number is greater than the secret
number,try again!")
Case Else
Beep
MsgBox ("Your number is correct,CONGRATULATION!")
End Select
End Sub

Private Sub Form_Load()


Text1.Text = " "
Label1.Visible = False
secret_number = 1 + Int(6 * Rnd)
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)


If (KeyAscii <= 47 Or KeyAscii > 57) And (KeyAscii <> 8) And
(KeyAscii <> 13) Then
KeyAscii = 0
MsgBox "Enter only numbers"
Exit Sub
End If
If KeyAscii = 13 Then
If Text1.Text = " " Then
GoTo zz
End If
n = Val(Text1.Text)
If n <= 3 Then
GoTo ss
End If
i = 2
k = n / 2
For i = 2 To k
s = n Mod i
If s = 0 Then
GoTo aa
End If
Next i
ss:
MsgBox "The given number is prime", vbInformation
Text1.Text = " "
GoTo zz
aa:
MsgBox "The Given Number Is Not Prime", vbInformation
End If
Text1.Text = " "
zz: End Sub
OUTPUT
ENCRYPTION AND DECRYPTION USING LOOPS

FORM DESIGN

SOURCE CODE
Dim encryptval As String
Dim decryptval As String
Dim i As Integer
Dim mychar As String

Private Sub cmdclear_Click()


Text1.Text = ""
lblencrp.Caption = ""
lbldecrp.Caption = ""
Text1.SetFocus
cmdencrp.Enabled = True
cmddecrp.Enabled = False
End Sub

Private Sub cmddecrp_Click()


Dim mynewstring As String
mystring = lblencrp.Caption
mychar = " "
strlen = Len(mystring)
For i = 1 To strlen
mychar = Mid(mystring, i, 1)
Select Case Asc(mychar)
Case 192 To 217
mychar = Chr(Asc(mychar) - 127)
Case 218 To 243
mychar = Chr(Asc(mychar) - 121)
Case 244 To 253
mychar = Chr(Asc(mychar) - 196)
Case 32
mychar = Chr(32)
End Select
mynewstring = mynewstring + mychar
Next
decryptval = mynewstring
lbldecrp.Caption = decryptval
cmdencrp.Enabled = False
cmddecrp.Enabled = False
End Sub

Private Sub cmdencrp_Click()


Dim mynewstring As String
mystring = Text1.Text
mychar = " "
strlen = Len(mystring)
For i = 1 To strlen
mychar = Mid(mystring, i, 1)
Select Case Asc(mychar)
Case 65 To 90
mychar = Chr(Asc(mychar) + 127)
Case 97 To 122
mychar = Chr(Asc(mychar) + 121)
Case 48 To 57
mychar = Chr(Asc(mychar) + 196)
Case 32
mychar = Chr(32)
End Select
mynewstring = mynewstring + mychar
Next i
encryptval = mynewstring
lblencrp.Caption = encryptval
cmdencrp.Enabled = False
cmddecrp.Enabled = True
End Sub

Private Sub Form_Load()


Me.Caption = "Encryption and Decryption"
Text1.Text = " "
lblencrp.Caption = " "
lbldecrp.Caption = " "
cmdencrp.Enabled = True
cmddecrp.Enabled = False
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)


If (KeyAscii>= 97 And KeyAscii<= 122) Or (KeyAscii>= vbKeyA
And KeyAscii<= vbKeyZ) Or (KeyAscii>= vbKey0 And KeyAscii<=
vbKey9) Or KeyAscii = vbKeySpace Or KeyAscii = vbKeyBack Or
KeyAscii = 46 Then
Exit Sub
Else
KeyAscii = 0
End If
End Sub
OUTPUT
CALL BY VALUE AND CALL BY REFERENCE IN FUNCTIONS
FORM DESIGN

SOURCE CODE
Sub swap(x As Integer, y As Integer)
Dim t As Integer
t = x
x = y
y = t
Print "value of a inside subroutine =" & x
Print "value of b inside subroutine =" & y
End Sub

Private Sub Command1_Click()


Dim a As Integer, b As Integer
a = Val(InputBox("enter the value of a"))
Print "value of before swap using call by reference=" & a
b = Val(InputBox("enter the value of b"))
Print "value of before swap using call by reference=" & b
Call swap(a, b)
Print "value of a after swap using call by reference=" & a
Print "value of b after swap using call by reference=" & b
End Sub

Sub swap1(ByVal x As Integer, ByVal y As Integer)


Dim t As Integer
t = x
x = y
y = t
Print "value of a inside subroutine =" & x
Print "value of b inside subroutine =" & y
End Sub

Private Sub Command2_Click()


Dim a As Integer, b As Integer
a = Val(InputBox("enter the value of a"))
Print "value of before swap using call by value=" & a
b = Val(InputBox("enter the value of b"))
Print "value of before swap using call by value=" & b
Call swap1(a, b)
Print "value of a after swap using call by value=" & a
Print "value of b after swap using call by value=" & b
End Sub

Private Sub Command3_Click()


Me.Cls
End Sub

OUTPUT
SORTING AND SEARCHING IN LISTBOX USING ARRAYS
FORM DESIGN

SOURCE CODE
Dim arr(100), flag, n, s As String

Private Sub Command1_Click()


flag = 0
n = (InputBox("enter the no of elements in the array"))
For i = 1 To n
arr(i) = (InputBox("enter the elements"))
List1.AddItem (arr(i))
Next i
End Sub

Private Sub Command2_Click()


s = InputBox("enter the search element")
For i = 1 To n
If (arr(i) = s) Then
flag = 1
End If
Next i
If (flag = 1) Then
MsgBox ("name is found the list")
Else
MsgBox ("name not found")
End If
End Sub

Private Sub Command3_Click()


Dim i, n As Integer
n = List1.ListCount - 1
For i = 0 To n
arr(i) = List1.List(i)
Next i
For i = 0 To n
For j = 0 To n - i - 1
If arr(j) > arr(j + 1) Then
swap j, j + 1
End If
Next j
Next i
List1.Clear
For i = 0 To n
List1.AddItem arr(i)
Next i
End Sub

Private Sub Command4_Click()


List1.Clear
End Sub

Private Sub Command5_Click()


End
End Sub

Private Sub swap(ByVal x As Integer, ByVal y As Integer)


Dim t As String
t = arr(x)
arr(x) = arr(y)
arr(y) = t
End Sub

OUTPUT
SIMPLE CALCULATOR USING CONTROL ARRAY
FORM DESIGN

SOURCE CODE
Dim a, op, m

Private Sub Command1_Click(Index As Integer)


If Index >= 0 And Index <= 9 Or Index = 11 Then
If lbltext.Caption = "0" Then lbltext.Caption = Clear
lbltext.Caption = lbltext.Caption +
Command1(Index).Caption
ElseIf Index >= 10 And Index <= 13 Then
a = Val(lbltext.Caption)
op = Command1(Index).Caption
lbltext.Caption = Clear
ElseIf Index = 14 Then
Select Case op
Case "+"
lbltext.Caption = a + Val(lbltext.Caption)
Case "-"
lbltext.Caption = a - Val(lbltext.Caption)
Case "x"
lbltext.Caption = a * Val(lbltext.Caption)
Case "/"
lbltext.Caption = a / Val(lbltext.Caption)
End Select
ElseIf Index = 15 Then
lbltext.Caption = "0"
End If
End Sub

Private Sub Command2_Click()


End
End Sub
OUTPUT
DOCTORS DETAIL USING FLEXGRID CONTROL
FORM DESIGN

SOURCE CODE

Private Type doctor


dname As String
dno As Integer
dadd As String
dphone As Double
End Type
Dim d(10) As doctor
Dim i, j As Integer

Private Sub Command1_Click()


d(i).dno = Val(Text1.Text)
d(i).dname = Text2.Text
d(i).dadd = Text3.Text
d(i).dphone = Val(Text4.Text)
i = i + 1
MsgBox "Added Doctor details in array"
End Sub

Private Sub Command2_Click()


Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub

Private Sub Command3_Click()


End
End Sub
Private Sub Command4_Click()
MS1.Rows = i + 1
For j = 1 To i
MS1.Row = j
MS1.Col = 0
MS1.Text = d(j - 1).dno
MS1.Col = 1
MS1.Text = d(j - 1).dname
MS1.Col = 2
MS1.Text = d(j - 1).dadd
MS1.Col = 3
MS1.Text = d(j - 1).dphone

Next
End Sub

Private Sub Form_Load()


MS1.Cols = 4

MS1.Row = 0
MS1.Col = 0
MS1.Text = "Doctor no"
MS1.Col = 1
MS1.Text = "Doctor name"
MS1.Col = 2
MS1.Text = "Doctor address"
MS1.Col = 3
MS1.Text = "Phone no"
End Sub

OUTPUT
MENU WITH RICHTEXT BOX USING COMMON DIALOG
CONTROL
FORM DESIGN

SOURCE CODE
Private Sub editcopy_Click()
a = RTBOX.SelText
End Sub

Private Sub editcut_Click()


a = RTBOX.SelText
RTBOX.SelText = Clear
End Sub

Private Sub editpaste_Click()


RTBOX.SelText = a
End Sub

Private Sub exitm_Click()


End
End Sub

Private Sub fileclose_Click()


RTBOX.Visible = False
End Sub

Private Sub filenew_Click()


RTBOX.Visible = True
RTBOX = Clear
RTBOX.SetFocus
End Sub
Private Sub fileopen_Click()
CDLgbox.ShowOpen
RTBOX.FileName = CDLgbox.FileName
RTBOX.SetFocus
End Sub

Private Sub filesave_Click()


CDLgbox.ShowSave
RTBOX.SaveFile CDLgbox.FileName
RTBOX.SetFocus
End Sub

Private Sub Form_Load()


RTBOX.Height = Me.ScaleHeight
RTBOX.Width = Me.ScaleWidth
End Sub

Private Sub formatbold_Click()


RTBOX.SelBold = True
RTBOX.SetFocus
End Sub

Private Sub formatclear_Click()


Cls
End Sub

Private Sub formatcolor_Click()


CDLgbox.ShowColor
RTBOX.SelColor = CDLgbox.Color
RTBOX.SetFocus
End Sub

Private Sub formatitalics_Click()


RTBOX.SelItalic = True
RTBOX.SetFocus
End Sub

Private Sub windowmaximize_Click()


Me.WindowState = vbMaximized
End Sub

Private Sub windowminimize_Click()


Me.WindowState = vbMinimized
End Sub

Private Sub windownormal_Click()


e.WindowState = vbNormal
End Sub
OUTPUT
DATE FUNCTIONS USING MULTIPLE DOCUMENT INTERFACE
FORM DESIGN
MDI FORM

FORM1

SOURCE CODE
MDI Form Source Code:
Dim i
Dim myform As New Form1

Private Sub MDIForm_MouseUp(Button As Integer, Shift As Integer, X


As Single, Y As Single)
If Button = 2 Then
PopupMenu mwindow
End If
End Sub

Private Sub mnnew_Click()


i = i + 1
Set myform = New Form1
myform.Caption = " child form " & i
myform.Show
End Sub

Private Sub mnexit_Click()


Unload Me
End
End Sub

Private Sub mncascade_Click()


MDIForm1.Arrange vbCascade
End Sub

Private Sub mnhorizontal_Click()


MDIForm1.Arrange vbHorizontal
End Sub

Private Sub mnvertical_Click()


MDIForm1.Arrange vbVertical
End Sub

Form1 Source Code:

Private Sub Command1_Click()


MsgBox ("Hello!!!" & " " & Text1.Text & "" & Label1.Caption)
End Sub

Private Sub Command2_Click()


Text1.Text = " "
Label1.Caption = " "
Text1.SetFocus
End Sub
Private Sub Label1_click()
Label1.Caption = " current time is: " & " " & Now()
End Sub
Private Sub Label1_DblClick()
Label1.Caption = " Current month is: " & " " &
MonthName(Month(Now)) & " " & " Current year is :" & " " &
Year(Now)
End Sub
OUTPUT
SALES REPORT USING LINES AND BOXES

FORM DESIGN

SOURCE CODE

Dim sale1, sale2, sale3, sale4, sale5 As Integer


Private Sub Form_Load()
Picture1.Scale (0, 5000)-(5000, 0)
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
End Sub

Private Sub Command1_Click()


sale1 = Val(text_jan.Text)
sale2 = Val(text_feb.Text)
sale3 = Val(text_mar.Text)
sale4 = Val(text_apr.Text)
sale5 = Val(text_may.Text)
Label11.Visible = True
Label11.Caption = "month"
Label12.Visible = True
Label12.Caption = "sales volume"
Picture1.Line (100, 0)-(600, sale1 * 50), vbRed, BF
Label6.Visible = True
Label6.Caption = "Jan"
Picture1.Line (700, 0)-(1200, sale2 * 50), vbRed, BF
Label7.Visible = True
Label7.Caption = "feb"
Picture1.Line (1300, 0)-(1800, sale3 * 50), vbRed, BF
Label8.Visible = True
Label8.Caption = "mar"
Picture1.Line (1900, 0)-(2400, sale4 * 50), vbRed, BF
Label9.Visible = True
Label9.Caption = "apr"
Picture1.Line (2500, 0)-(3000, sale5 * 50), vbRed, BF
Label10.Visible = True
Label10.Caption = "may"
End Sub

Private Sub Command2_Click()


text_jan.Text = " "
text_feb.Text = " "
text_mar.Text = " "
text_apr.Text = " "
text_may.Text = " "
Label6.Visible = False
Label7.Visible = False
Label8.Visible = False
Label9.Visible = False
Label10.Visible = False
Label11.Visible = False
Label12.Visible = False
Picture1.Cls
End Sub

OUTPUT
ANIMATED DICE USING GRAPHICS

FORM DESIGN

SOURCE CODE
Dim x As Integer
Sub roll()
x = x + 10
Randomize Timer
n = Int(1 + Rnd * 6)
For i = 0 To 6
Shape2(i).Visible = False
Next
If n = 1 Then
Shape2(3).Visible = True
End If
If n = 2 Then
Shape2(2).Visible = True
Shape2(4).Visible = True
End If
If n = 3 Then
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
End If
If n = 4 Then
Shape2(0).Visible = True
Shape2(2).Visible = True
Shape2(4).Visible = True
Shape2(6).Visible = True
End If
If n = 5 Then
Shape2(0).Visible = True
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
Shape2(6).Visible = True
End If
If n = 6 Then
Shape2(0).Visible = True
Shape2(1).Visible = True
Shape2(2).Visible = True
Shape2(3).Visible = True
Shape2(4).Visible = True
Shape2(5).Visible = True
Shape2(6).Visible = True
End If
End Sub
Private Sub Command1_Click()
Timer1.Enabled = True
x = 0
End Sub
Private Sub Timer1_Timer()
If x < 1000 Then
roll
Else
Timer1.Enabled = False
End If
End Sub

OUTPUT
FREE STYLE DRAWING USING MOUSE EVENTS
FORM DESIGN

SOURCE CODE

Private Sub command1_Click()


Form1.Cls
End Sub

Private Sub Form_MouseDown(button As Integer, shift As Integer, x As


Single, y As Single)
Dim colo As Integer
Randomize
colo = Int(10 * rnd)
Select Case button
Case 1
FillStyle = 1
Circle (x, y), 100, QBColor(colo)
FillColor = red
Case 2
FillStyle = 0
FillColor = QBColor(colo)
Circle (x, y), 70
End Select
End Sub

Private Sub Form_MouseMove(button As Integer, shift As Integer, x As


Single, y As Single)
Dim colo As Integer
colo = Int(10 * rnd)
FillStyle = 1
FillColor = &HFFC0FF
Circle (x, y), 100, QBColor(colo)
End Sub

Private Sub Form_MouseUp(button As Integer, shift As Integer, x As


Single, y As Single)
Select Case button
Case 1
Print "Mouse left button released"
Case 2
Print "Mouse right button released"
End Select
End Sub

OUTPUT
GENERATING EXCEL CHART USING OLE

FORM DESIGN

SOURCE CODE

Private Excel AsExcel.Application


Private Sub command1_Click()
Dim oXL As Object
Dim oBook As Object
Dim oSheet As Object
Dim oChart As Object
Dim irow As Integer
Dim icol As Integer
ConstcNumcols = 7
ConstcNumrows = 5
ReDimatemp(1 To cNumrows, 1 To cNumcols)
Set oXL = CreateObject("Excel.application")
Set oBook = oXL.Workbooks.Add
Set oSheet = oBook.Worksheets.Item(1)
Randomize Now()
For irow = 1 TocNumrows
For icol = 1 TocNumcols
atemp(irow, icol) = Int(Rnd * 100) + 1
Next icol
Next irow
oSheet.Range("A1").Resize(cNumrows, cNumcols).Value = atemp
Set oChart = oSheet.ChartObjects.Add(50, 40, 300, 200).Chart
oChart.SetSourceData
Source:=oSheet.Range("A1").Resize(cNumrows, cNumcols)
oXL.Visible = True
oXL.UserControl = True
End Sub
Private Sub command2_Click()
End
End Sub
Private Sub Form_Load()
Set Excel = New Excel.Application
Set Workbook = Excel.Workbooks.Add
End Sub

OUTPUT
READ AND WRITE DATA USING SEQUENTIAL FILES
FORM DESIGN

SOURCE CODE
Dim filenum As Integer
Private Sub Command1_Click()
Text1.Text = " "
Text1.SetFocus
End Sub

Private Sub Command2_Click()


filenum = FreeFile
Open "d:\222\sample.txt" For Output As filenum
Write #filenum, Text1.Text
MsgBox "saved"
Close filenum
End Sub

Private Sub Command3_Click()


filenum = FreeFile
Open "d:\222\sample.txt" For Input As filenum
Do Until EOF(filenum)
Input #filenum, buff
Text1.Text = Text1.Text + buff
Loop
Close filenum
End Sub

Private Sub Command4_Click()


Text1.Text = " "
MsgBox "DATA DELETED"
End Sub

OUTPUT
PAYROLL PROCESSING USING DAO
FORM DESIGN

SOURCE CODE

Private Sub Command1_Click()


Data1.Recordset.AddNew
MsgBox "enter the employee details and press update "
Text1.SetFocus
End Sub

Private Sub Command2_Click()


Data1.Recordset.Delete
Data1.Recordset.MoveNext
MsgBox "Record Deleted"
End Sub

Private Sub Command3_Click()


MsgBox " ENTER THE DESIGNATION AND BASIC SALARY TO BE UPDATED"
Data1.Recordset.Edit
Text1.Enabled = False
Text2.Enabled = False
Text5.Enabled = False
Text6.Enabled = False
Text7.Enabled = False
Text8.Enabled = False
Text9.Enabled = False
End Sub

Private Sub Command4_Click()


Data1.Recordset.Update
MsgBox " RECORDED UPDATED"
End Sub

Private Sub Command5_Click()


Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
MsgBox "Record is clear"
End Sub

Private Sub Command6_Click()


Data1.Recordset.MoveLast
MsgBox Data1.Recordset.RecordCount
End Sub

Private Sub Command7_Click()


End
End Sub

Private Sub Text1_Change()


textval = Text1.Text
If IsNumeric(textval) Then
numval = textval
Else
Text1.Text = CStr(numval)
End If
End Sub

Private Sub Text2_KeyPress(KeyAscii As Integer)


Select Case KeyAscii
Case 32 To 64, 91 To 96, 123 To 126
MsgBox ("Must be a letter ! Please try again")
KeyAscii = 0
Exit Sub
End Select
End Sub

Private Sub Text3_KeyPress(KeyAscii As Integer)


Select Case KeyAscii
Case 32 To 64, 91 To 96, 123 To 126
MsgBox ("Must be a letter ! Please try again")
KeyAscii = 0
Exit Sub
End Select
End Sub

Private Sub Text4_Change()


textval = Text4.Text
If IsNumeric(textval) Then
numval = textval
Else
Text4.Text = CStr(numval)
End If
End Sub

Private Sub Text4_Lostfocus()


Text5.Text = Val(Text4.Text) * 0.1
Text6.Text = Val(Text4.Text) * 0.05
Text7.Text = Val(Text4.Text) * 0.02
Text8.Text = Val(Text4.Text) + Val(Text5.Text) +
Val(Text6.Text)
Text9.Text = Val(Text4.Text) + Val(Text5.Text) +
Val(Text6.Text) - Val(Text7.Text)
End Sub

OUTPUT
TELEPHONE DIRECTORY MAINTENANCE USING ADODB
FORM DESIGN

Form1

Form2

SOURCE CODE
Form1 Source Code:

Dim cn As New ADODB.Connection


Dim rs As New ADODB.Recordset
Dim n As Double, flg As Integer

Private Sub add_Click()


rs.AddNew
rs!custno = Val(cno)
rs!custname = cname
rs!doorno = Val(cdoor)
rs!street = cstreet
rs!city = ccity
rs!pincode = Val(cpincode)
rs!phoneno = Val(cphone)
rs!area = carea
rs.update
MsgBox "recorded added"
clear_record
End Sub

Private Sub clear_record()


cname.Text = " "
cno.Text = " "
cdoor.Text = " "
cstreet.Text = " "
ccity.Text = " "
cpincode.Text = " "
cphone.Text = " "
carea.Text = " "
cno.SetFocus
End Sub

Private Sub clear_Click()


clear_record
End Sub

Private Sub delete_Click()


n = Val(InputBox("Enter the customer number to delate"))
rs.MoveFirst
Do Until rs.EOF
If rs!custno = n Then
disp_record
rs.delete
MsgBox "Record Deleted"
clear_record
flg = 1
Exit Do
End If
rs.MoveNext
Loop
If flg = 0 Then
MsgBox "no record found"
End If
End Sub

Private Sub edit_Click()


n = Val(InputBox("Enter the customer number to edit"))
rs.MoveFirst
Do Until rs.EOF
If rs!custno = n Then
disp_record
flg = 1
Exit Do
End If
rs.MoveNext
Loop
If flg = 0 Then
MsgBox "no record found"
End If
update.Visible = True
End Sub

Private Sub exit_Click()


End
End Sub

Private Sub find_Click()


n = Val(InputBox("Enter the customer number to search"))
rs.MoveFirst
Do Until rs.EOF
If rs!custno = n Then
disp_record
flg = 1
Exit Do
End If
rs.MoveNext
Loop
If flg = 0 Then
MsgBox "no record found"
End If
End Sub

Private Sub Form_Load()


cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\telephone.mdb;Persist Security Info=False"
rs.Open " select * from customer", cn, 1, 2
MsgBox "database connected"
End Sub

Private Sub report_Click()


datareport1.Show
End Sub

Private Sub seachnamephone_Click()


Form1.Hide
Form2.Show
End Sub

Private Sub update_Click()


rs!custno = Val(cno)
rs!custname = cname
rs!doorno = Val(cdoor)
rs!street = cstreet
rs!city = ccity
rs!pincode = Val(cpincode)
rs!phoneno = cphone
rs!area = carea
MsgBox "Record Modified"
update.Visible = False
End Sub

Public Sub disp_record()


cname = rs!custname
cno = rs!custno
cdoor = rs!doorno
cstreet = rs!street
ccity = rs!city
cpincode = rs!pincode
cphone = rs!phoneno
carea = rs!area
End Sub

Form2 Source Code


Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim n As Double, flg As Integer

Private Sub Command1_Click()


Form2.Hide
Form1.Show
End Sub

Private Sub Command2_Click()


Dim pno As String
pno = Val(InputBox("Enter the phone number"))
If rs.State = 1 Then rs.Close
rs.Open "select * from customer where phoneno=" &pno& "
", cn, 1, 2
If rs.EOF = False Then
Text2 = rs!custname
Text3 = rs!doorno
Text4 = rs!street
Text5 = rs!city
Text6 = rs!pincode
Text1 = rs!phoneno
Else
MsgBox "Not found"
End If
End Sub

Private Sub Form_Load()


cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\telephone.mdb;Persist Security Info=False"
rs.Open "select * from customer ", cn, 1, 2
End Sub
OUTPUT
REPORT

You might also like