Sie sind auf Seite 1von 51

Page |1

Message Box

Private Sub Command1_Click()


Unload Me
End Sub

Private Sub Command2_Click()


Dim textmsg As Integer
textmsg = MsgBox("CLICK TO TEST", 1, "TEXT MESSAGE")
If textmsg = 1 Then
Label1.Caption = "TESTING SUCCESSFUL"
Else
Label1.Caption = "TESTING FAIL"
End If
End Sub

Private Sub Command3_Click()


Dim textmsg2 As Integer
textmsg2 = MsgBox("CLICK TO TEST", vbYesNoCancel + vbExclamation, "TEXT
MESSAGE")
If textmsg2 = 6 Then
Label1.Caption = "TESTING SUCCESSFUL"
ElseIf textmsg2 = 7 Then
Page |2

Label1.Caption = "ARE U SURE"


Else
Label1.Caption = "TESTING FAIL"
End If
End Sub
Page |3
Page |4

Input Box

Private Sub Command1_Click()


Dim usermsg As String
usermsg = InputBox("WHAT IS YOUR MESSAGE?", "MESSAGE ENTRY FORM",
"500", "700")
If usermsg <> "" Then
Text1.Text = usermsg
Else
Text1.Text = "NO MESSAGE"
End If
End Sub
Page |5
Page |6

Calculator

Dim OP As String
Dim FIRST As Double

Private Sub Command1_Click(INDEX As Integer)


Text1.Text = Text1.Text + Command1(INDEX).Caption
End Sub

Private Sub Command2_Click(INDEX As Integer)


FIRST = Val(Text1.Text)
OP = Command2(INDEX).Caption
Text1.Text = ""
End Sub

Private Sub Command3_Click()


Select Case (OP)
Case "+"
Text1.Text = FIRST + Val(Text1.Text)
Case "-"
Text1.Text = FIRST - Val(Text1.Text)
Case "*"
Text1.Text = FIRST * Val(Text1.Text)
Page |7

Case "/"
Text1.Text = FIRST / Val(Text1.Text)
End Select
End Sub

Private Sub Command4_Click()


Text1.Text = Sqr(Val(Text1.Text))
End Sub

Private Sub Command5_Click()


Text1.Text = ""
OP = ""
End Sub
Page |8

Traffic Light using Timer

Private Sub command1_click()


'Timer1.Enabled = True
End Sub

Private Sub command2_click()


'If Timer1.Enabled = False Then
'Else
'Timer1.Enabled = True
'End If
End Sub

Private Sub timer1_timer()


If Image1.Visible = True Then
Image1.Visible = flase
Image2.Visible = True
Page |9

ElseIf Image2.Visible = True Then


Image2.Visible = False
Image3.Visible = True
ElseIf Image3.Visible = True Then
Image3.Visible = False
Image1.Visible = True
End If
End Sub
P a g e | 10

Application to Display Circle, Line, and Pset

Private Sub CIRCLE_Click()


Dim I As Integer
For I = 100 To 10000 Step 100
Form1.Circle (I, I), I, RGB(255, 0, 0)
Next I
End Sub

Private Sub CLOSE_Click()


End
End Sub

Private Sub CLS_Click()


Form1.CLS
End Sub
P a g e | 11

Private Sub HIDE_Click()


Form1.HIDE
End Sub

Private Sub LINE_Click()


Dim I As Integer
ScaleMode = 3
For I = 10 To 250 Step 3
Form1.Line (10, I)-(250, I), RGB(0, 0, 255)
Form1.Line (I, 10)-(I, 250), RGB(255, 0, 255)
DoEvents
Next I
End Sub

Private Sub MOVE_Click()


Form1.Left = 1000
Form1.Top = 2000
End Sub

Private Sub PSET_Click()


Dim I As Integer, J As Integer
Dim RED As Integer, GREEN As Integer, BLUE As Integer
ScaleMode = 3
For I = 1 To 200
For J = 1 To 200
RED = CInt(Rnd * 255)
BLUE = CInt(Rnd * 255)
GREEN = CInt(Rnd * 255)
Form1.PSet (I, J), RGB(RED, GREEN, BLUE)
Next J
Next I
End Sub

Private Sub REFRESH_Click()


Form1.REFRESH
End Sub

Private Sub RESIZE_Click()


Form1.Width = 5000
End Sub

Private Sub SHOW_Click()


Form1.SHOW
End Sub
P a g e | 12
P a g e | 13

Notepad

Private Sub cmdpaste_Click()


Textnpad.SelText = Clipboard.GetText
End Sub

Private Sub cmdselectall_Click()


Text$ = Textnpad.Text
Textnpad.SelStart = 0
Textnpad.SelLength = Len(Text$)
Textnpad.SetFocus
End Sub

Private Sub cmdcopy_Click()


Clipboard.SetText Textnpad.SelText
cmdpaste.Enabled = True
End Sub

Private Sub cmdcut_Click()


Clipboard.SetText Textnpad.SelText
Textnpad.SelText = " "
cmdpaste.Enabled = True
End Sub
P a g e | 14
P a g e | 15

Stimulate Dice Rolling

Private Sub command1_click()


Dim dice

Randomize
dice = Int((6 * Rnd) + 1)

Select Case dice

Case 1
Shape2(0).FillStyle = 1
Shape2(1).FillStyle = 1
Shape2(2).FillStyle = 1
Shape2(3).FillStyle = 1
Shape2(4).FillStyle = 1
Shape2(5).FillStyle = 1
Shape2(6).FillStyle = 0

Case 2
Shape2(0).FillStyle = 1
Shape2(1).FillStyle = 1
Shape2(2).FillStyle = 0
Shape2(3).FillStyle = 0
Shape2(4).FillStyle = 1
Shape2(5).FillStyle = 1
P a g e | 16

Shape2(6).FillStyle = 1

Case 3
Shape2(0).FillStyle = 0
Shape2(1).FillStyle = 1
Shape2(2).FillStyle = 1
Shape2(3).FillStyle = 1
Shape2(4).FillStyle = 1
Shape2(5).FillStyle = 0
Shape2(6).FillStyle = 0

Case 4
Shape2(0).FillStyle = 0
Shape2(1).FillStyle = 0
Shape2(2).FillStyle = 1
Shape2(3).FillStyle = 1
Shape2(4).FillStyle = 0
Shape2(5).FillStyle = 0
Shape2(6).FillStyle = 1

Case 5
Shape2(0).FillStyle = 0
Shape2(1).FillStyle = 0
Shape2(2).FillStyle = 1
Shape2(3).FillStyle = 1
Shape2(4).FillStyle = 0
Shape2(5).FillStyle = 0
Shape2(6).FillStyle = 0

Case 6
Shape2(0).FillStyle = 0
Shape2(1).FillStyle = 0
Shape2(2).FillStyle = 0
Shape2(3).FillStyle = 0
Shape2(4).FillStyle = 0
Shape2(5).FillStyle = 0
Shape2(6).FillStyle = 1
End Select
End Sub
P a g e | 17
P a g e | 18

Generate All Library Functions

Private Sub ASCII_Click()


Dim A As String
A = InputBox("ENTER A STRING")
MsgBox ("ASCII CODE IS:" & Asc(A))
End Sub

Private Sub CASE_Click()


Dim A As String
A = InputBox("ENTER STRING IN LOWER CASE:")
MsgBox ("STRING IN UPPER CASE IS:" & UCase(A))
Dim B As String
B = InputBox("ENTER STRING IN UPPER CASE:")
MsgBox ("STRING IN LOWER CASE IS:" & LCase(B))
End Sub

Private Sub CHARACTER_Click()


Dim A As String
A = InputBox("ENTER ANY VALUE")
MsgBox ("CHARACTER CODE IS:" & Chr(A))
End Sub

Private Sub DATE_TIME_Click()


MsgBox ("DATE IS:" & Date)
MsgBox ("TIME IS:" & Time())
P a g e | 19

End Sub

Private Sub INSTRING_Click()


Dim A As String
A = InputBox("ENTER A STRING")
Dim B As String
B = InputBox("ENTER A CHARACTER YOU WANT TO SEARCH FROM THE
STRING")
MsgBox (InStr(A, B))
End Sub

Private Sub LEFT_RIGHT_Click()


Dim A As String
A = InputBox("ENTER A STRING TO EXTRACT CHARACTERS")
Dim I As Integer
I = InputBox("ENTER NO.OF CHARACTERS YOU WANT TO EXTRACT")
MsgBox ("STRING USING LEFT FUNCTION:" & Left(A, I))
MsgBox ("STRING USING RIGHT FUNCTION:" & Right(A, I))
End Sub

Private Sub LENGTH_Click()


Dim A As String
A = InputBox("ENTER A STRING TO CALCULATE ITS LENGTH")
Dim R As Integer
R = Len(A)
MsgBox ("LENGTH OF STRING IS:" & Val(R))
End Sub

Private Sub MID1_Click()


Dim A As String
Dim I As Integer, J As Integer
A = InputBox("ENTER A STRING")
I = InputBox("ENTER THE STARTING POSITION")
J = InputBox("ENTER THE NO.OF CHARACTERS")
MsgBox ("USE OF MID:" & MID(A, I, J))
End Sub

Private Sub REVERSE_Click()


Dim A As String
A = InputBox("ENTER ANY STRING")
MsgBox ("REVERSE OF TRING IS:" & StrReverse(A))
End Sub

Private Sub TRIMMING_Click()


Dim A As String
A = InputBox("ENTER A STRING WITH LEADING ANT TRAILING SPACES")
MsgBox ("STRING USING LTRIM:" & LTrim(A))
MsgBox ("STRING USING TRIM:" & Trim(A))
MsgBox ("STRING USING RTRIM:" & RTrim(A))
End Sub
P a g e | 20
P a g e | 21

MDI (Multiple Document Interface) Form


P a g e | 22

Adding Menu Editor


P a g e | 23
P a g e | 24

Database in SQL Using ADO connection


P a g e | 25

create table student


(
sname char(20),
roll number(4),
sid number(4),
gender char(3),
dob date,
marks number(5)
)
table created.

SQL>insert into student values(‘&sname’,&roll,&sid,‘&gender’,‘&dob’,&marks);


Enter value for sname: richard
Enter value for roll: 01
Enter value for sid: 2012
Enter value for gender: m
Enter value for dob: 12-jun-1989
Enter value for marks: 76
old 1: insert into student values(‘&name’,&roll,&sid,‘&gender’,‘&dob’,&marks);
new 1: insert into student values(‘richard’,01,2012,‘m’,‘12-jun-1989’,76)

1 row created.

SQL>/
Enter value for sname: bentley
Enter value for roll: 02
Enter value for sid: 2607
Enter value for gender: m
Enter value for dob: 28-jul-1989
Enter value for marks: 70
old 1: insert into student values(‘&name’,&roll,&sid,‘&gender’,‘&dob’,&marks);
new 1: insert into student values(‘bentley’,02,2607,‘m’,‘28-jul-1989’,70)

1 row created.

SQL>/
Enter value for sname: ana
Enter value for roll: 03
Enter value for sid: 2609
Enter value for gender: f
Enter value for dob: 12-dec-1989
Enter value for marks: 80
old 1: insert into student values(‘&name’,&roll,&sid,‘&gender’,‘&dob’,&marks);
new 1: insert into student values(‘ana’,03,2609,‘m’,‘12-dec-1989’,80)

1 row created.
SQL>/
Enter value for sname: julie
Enter value for roll: 04
Enter value for sid: 2621
P a g e | 26

Enter value for gender: f


Enter value for dob: 25-jan-1989
Enter value for marks: 88
old 1: insert into student values(‘&name’,&roll,&sid,‘&gender’,‘&dob’,&marks);
new 1: insert into student values(‘julie’,04,2621,‘f’,‘25-jan-1989’,88)

1 row created.

SQL>/
Enter value for sname: mary
Enter value for roll: 05
Enter value for sid: 2633
Enter value for gender: f
Enter value for dob: 19-aug-1989
Enter value for marks: 64
old 1: insert into student values(‘&name’,&roll,&sid,‘&gender’,‘&dob’,&marks);
new 1: insert into student values(‘mary’,05,2633,‘f’,‘19-aug-1989’,64)

1 row created.
P a g e | 27
P a g e | 28

Data Grid
P a g e | 29

Creating MS Access Database


P a g e | 30
P a g e | 31

Enter the fields


P a g e | 32

Click on close button in add field dialog box and click on the Build The table button
P a g e | 33

Creating the connectivity of MS Access Database with ADODC

previous
Next Record

Adodc1
(ActiveX Data Object Data Control)
P a g e | 34

Dim comm As New ADODB.Connection


Dim Rs As New ADODB.Recordset

Private Sub cmdadd_Click()


Rs.AddNew
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
cmdadd.Visible = False
cmdupdate.Enabled = False
cmdexit.Enabled = False
cmdnext.Enabled = False
cmdlast.Enabled = False
cmdprevious.Enabled = False
cmddelete.Enabled = False
cmdfirst.Enabled = False
End Sub

Private Sub cmddelete_Click()


cmdadd.Visible = False
cmdupdate.Enabled = False
cmdexit.Enabled = False
cmdnext.Enabled = False
cmdlast.Enabled = False
cmdprevious.Enabled = False
cmddelete.Enabled = False
cmdfirst.Enabled = False
Dim ans As String, str As String
ans = MsgBox("do you really want to delete the current record ? ", vbExclamation +
vbYesNo)
If ans = vbYes Then
comm.Execute ("delete from lib where book_id=" & Text1.Text)
MsgBox ("record has been deleted successfully")
Set Rs = Nothing
str = "select * from lib"
Rs.Open str, comm, adOpenDynamic, adLockPessimistic
Rs.MoveFirst
Text1.Text = Rs(0)
Text2.Text = Rs(1)
Text3.Text = Rs(2)
Text4.Text = Rs(3)
End If
cmdadd.Enabled = True
cmdupdate.Enabled = True
cmdexit.Enabled = True
cmdprevious.Enabled = True
cmdnext.Enabled = True
cmdlast.Enabled = True
cmdfirst.Enabled = True
P a g e | 35

End Sub
Private Sub cmdexit_Click()
Unload Me
End Sub

Private Sub cmdfirst_Click()


Rs.MoveFirst
Text1.Text = Rs(0)
Text2.Text = Rs(1)
Text3.Text = Rs(2)
Text4.Text = Rs(3)
End Sub

Private Sub cmdlast_Click()


Rs.MoveLast
Text1.Text = Rs(0)
Text2.Text = Rs(1)
Text3.Text = Rs(2)
Text4.Text = Rs(3)
End Sub

Private Sub cmdnext_Click()


Rs.MoveNext
If Rs.EOF = True Then
MsgBox " this is last record ", vbExclamation
Rs.MoveLast
End If
Text1.Text = Rs(0)
Text2.Text = Rs(1)
Text3.Text = Rs(2)
Text4.Text = Rs(3)
End Sub

Private Sub cmdprevious_Click()


Rs.MovePrevious
If Rs.BOF = True Then
MsgBox "this is the first record", vbExclamation
Rs.MoveFirst
End If
Text1.Text = Rs(0)
Text2.Text = Rs(1)
Text3.Text = Rs(2)
Text4.Text = Rs(3)
End Sub
P a g e | 36

Private Sub cmdsave_click()


Rs(0) = Text1.Text
Rs(1) = Text2.Text
Rs(2) = Text3.Text
Rs(3) = Text4.Text
Rs.Update
MsgBox "the record has been saved successfully"
cmdadd.Visible = True
cmdupdate.Enabled = True
cmdexit.Enabled = True
cmdprevious.Enabled = True
cmdnext.Enabled = True
cmdlast.Enabled = True
cmdfirst.Enabled = True
cmddelete.Enabled = True
End Sub

Private Sub cmdupdate_Click()


cmdupdate.Enabled = False
cmdadd.Visible = False
cmdexit.Enabled = False
cmddelete.Enabled = False
Dim ans As String
ans = MsgBox("do you really want to modify the current record ? ", vbExclamation +
vbYesNo)
If ans = vbtes Then
Rs.Update
Else
cmdupdate.Enabled = True
cmdadd.Enabled = True
cmdexit.Enabled = True
End If
End Sub

Private Sub Cmdsearch1_Click()


If Text5.Text = vbNullString Then Exit Sub
findStr = "select * from lib where book_id = " & Text5.Text
Set RsSearch = New ADODB.Recordset
RsSearch.Open findStr, comm, adOpenDynamic
If RsSearch.EOF And RsSearch.BOF Then
MsgBox "Search Could not find any matching data", vbInformation, "Invalid Search
Criteria"
GoTo CloseRsSearch:
End If
Text1.Text = RsSearch!book_id
Text2.Text = RsSearch!bookname
Text3.Text = RsSearch!author
Text4.Text = RsSearch!edition
CloseRsSearch:
RsSearch.Close: Set RsSearch = Nothing
P a g e | 37

End Sub
Private Sub Form_Load()
Dim str As String
Me.Caption = "library system"
Set comm = Nothing
comm.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=library.mdb;Persist
Security Info=False"
str = "select * from lib"
Rs.Open str, comm, adOpenDynamic, adLockPessimistic
Rs.MoveFirst
Text1.Text = Rs(0)
Text2.Text = Rs(1)
Text3.Text = Rs(2)
Text4.Text = Rs(3)
End Sub

Private Sub Form_Unload(cancel As Integer)


Rs.Close: Set Rs = Nothing
comm.Close: Set comm = Nothing
End Sub
P a g e | 38

Data environment and Data


Report
P a g e | 39
P a g e | 40
P a g e | 41

Select Table From List

Click on it

This dialog box


will appear

Select The Database


P a g e | 42

Select The
Required Table
P a g e | 43

The list of fields


will appear
P a g e | 44

Drag n Drop
P a g e | 45
P a g e | 46
P a g e | 47

Creating Help File

Write IDH_FILE after file and Hide It from font dialog box,,

Save the file in RTF(Rich Text Format)

Open Help Workshop

Create a New Document

Select help project and click OK

Save the file with extinction .hpj

Click on the file and add the Rich Text Format File that You have prepared
P a g e | 48
P a g e | 49

Open VB and Drag and drop the Microsoft Dialog Common Control 6.0

Create A command button

Write The Code on command button

Private Sub Command1_Click()


cd.HelpFile = "E:\sem3\vb file\help1.hlp"
cd.HelpCommand = cdlHelpContents
cd.ShowHelp
End Sub
P a g e | 50
P a g e | 51

Das könnte Ihnen auch gefallen