Beruflich Dokumente
Kultur Dokumente
Submitted To:
Prof Anil Sharma
Submitted By:
Alisha Korpal BCA
INDEX Sno
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Introduction to VB Tool Box Property Description -- Properties Description -- Controls Application 1: Showing labels and text boxes Description -- Command button Application 2: To Perform Arithmetic Operations on two numbers Description Controls App 3 : Detail of any option click App 4 : Application Form Description -- control App 5: Traffic lights App 6: Getting marks of student and print result in another form App 7: Moving the list item across two different lists App 8: Formatting Text App 9: with the help of menus perform Arithmetic operation App 10: Print the series on form App 11: Puzzle App 12: Print table on the Form App 13: Getting a string input from user and move it along border
Topic
Page no
3 4 5 6 7 8 9 10 13 14 17 20 21 24 28 31 36 39 41 47 49
Introduction to VB
Visual basic is an event driven programming. In event driven programming, the interface components have the ability to recognize user events and then, if possible a response is given to the event occurred. The response of identical interface components to an event can different in different situations. In addition, an interface component may also respond to multiple events. In event driven programming an application is built up as a series of response to user event. For instance, you may consider a calculator application, which is good example of an application that is event driven.
Featues
It is successor of BASIC language. VB supports event driven programming. Common Programming Platform VB provides a common programming platform across all MS Office applications. Quick Development VB offers many tools that provide a quick and easy way to develop applications. Wizards VB also provides many wizards that can automate tasks or even automate coding. Quick Error Detection /Correction The VB development environment provides tools for quick editing, testing and debugging
Tool Box
The toolbox is a collection of tools that act as a repository of controls you can place on a form.
Properties
Each property has a name so we can work with a particular property, and each property has a value that either we or Visual Basic assigns. For example, Visual Basic always names the first command button we add to a project Command1. Therefore, the Name property for the first command button holds the value Command1
Property Description
Alignment : Determines whether text on the control, such as a label or
command button, is left-justified, centered, or right-justified on the control.
BackColor
: Determines whether the control has a border around it. : Lists the text displayed on the control. : Set by a drop-down list box, this property is either True if we
want the control to respond to the user or False if we want the control not to respond to the user.
Font ForeColor
: Displays a Font dialog box from which you can set various font
properties, such as size and style, for a control's text.
: Specifies the number of twips high the control is. : Indicates the starting twip from the left edge of the form where
the control appears.
: Holds the text that appears when the user rests the mouse
Cursor over the control at runtime (similar to ScreenTips).
CONTROLS
1. Selection Pointer
Selection pointer is used to select the pointer control from the tool box.
2. Label
The label control displays text. Although your user cannot alter the text that appears on a label, you can, at runtime, change the label's text through code.
Application 1
Labels
NOTE : Here no coding will be done because we are simply putting the label, text box controls on the form so, there output will be like the above program .
4. Command Button
Command button is used to perform some kind of operations although other controls can also perform. This button is used to begin, interrupt or end a process.
Application 2:
WAP to add, subtract, multiply and divide two numbers?
10
Private Sub cmd_Click() Me.sum.Text = Val(txtnum1.Text) + Val(txtnum2.Text) Me.sub.Text = Val(txtnum1.Text) - Val(txtnum2.Text) Me.mul.Text = Val(txtnum1.Text) * Val(txtnum2.Text) Me.div.Text = Val(txtnum1.Text) / Val(txtnum2.Text) End Sub
Private Sub Form_Load() MsgBox (" Hello Welcome to perform operations") End Sub
11
12
5. Check Box
Check boxes are used to allow a user select multiple choices. For example a student can choose any five subjects out of available 7 subjects. Now the subject chosen the 5 subject he/she wants to choose they can.
6. Option Box
An option button also known as radio button is used to display an option that can be turned on or off. Usually option buttons are used for a group of options wherefrom user can select just one. For example a student can have option for choosing the medium either Hindi or English so the student has to choose the one option.
7. Frames
A frame control is used to separate different group of controls on form.
8. Combo Box
A combo box control combines the feature of a text box and a list box.
9. List Box
A list box control display a list of item from which the user can select one or more items
13
Application 3
WAP to show the option button?
Step 1: Make a form
14
Step 2: Coding
private Sub Command1_Click() If Option1.Value = True Then MsgBox (" An input device used to type and enter data") ElseIf Option2.Value = True Then MsgBox (" An input device used for clicking various things") ElseIf Option3.Value = True Then MsgBox (" An output device used to display data") ElseIf Option4.Value = True Then MsgBox (" An output device used to print data") End If End Sub
15
Step 3: Execute
16
Application 4
WAP to make an application Form?
17
Step 2 Private Sub Command1_Click() MsgBox (txtname.Text & Cmbqual.Text & ",your data has been submited") End Sub
Private Sub Command2_Click() txtname.Text = "" Me.Option1.Value = True Cmbqual.Text = "B.A" chkmusic.Value = False chkpaint.Value = False chkread.Value = False End Sub
18
Step 3: Execute
19
10. Timer:
The timer control is an invisible control which is added to form if some task is to be repeated regular intervals
11.Shapes
The shape control is a graphical control that is used to display a rectangle, oval, circle or rounded square.
20
Application 5:
21
Step2: Coding Private Sub Timer1_Timer() If Shape1.Visible Then Shape2.Visible = True Shape1.Visible = False Shape3.Visible = False ElseIf Shape2.Visible Then Shape3.Visible = True Shape2.Visible = False Shape1.Visible = False Else Shape3.Visible Then Shape1.Visible = True Shape2.Visible = False Shape3.Visible = False End If End Sub
22
Step 3: Execute
23
Application 6:
Getting the particulars form the user and printing the result in another frame?
24
Private Sub cmbstream_Click() If cmbstream.ListIndex = 0 Then Me.lblsub1.Caption = "Economics" Me.lblsub2.Caption = "Accounts" Me.lblsub3.Caption = "Law" Me.lblsub1.Visible = True Me.lblsub2.Visible = True Me.lblsub3.Visible = True Me.txtm1.Visible = True Me.txtm2.Visible = True Me.txtm3.Visible = True ElseIf cmbstream.ListIndex = 1 Then Me.lblsub1.Caption = "C" Me.lblsub2.Caption = "VB" Me.lblsub3.Caption = "Java" Me.lblsub1.Visible = True Me.lblsub2.Visible = True Me.lblsub3.Visible = True Me.txtm1.Visible = True Me.txtm2.Visible = True Me.txtm3.Visible = True End If End Sub
Private Sub cmdres_Click() Me.lblname.Caption = "Name: " + Me.txtname.Text Me.lblroll.Caption = "Roll No.: " + Me.txtroll Me.lblstream.Caption = "Stream: " + Me.cmbstream.Text Me.lblm1.Caption = Me.lblsub1.Caption + ": " + Me.txtm1
25
Me.lblm2.Caption = Me.lblsub2.Caption + ": " + Me.txtm2 Me.lblm3.Caption = Me.lblsub3.Caption + ": " + Me.txtm3 If ((Val(txtm1.Text)+Val(txtm2.Text)+Val(txtm3.Text)) / 3)>=40 Then Me.lblres.Caption = "Pass " & "(" & ((Val(txtm1.Text) + Val(txtm2.Text) + Val(txtm3.Text)) / 3) & "%)" Else Me.lblres.Caption = "Fail " & "(" & ((Val(txtm1.Text) + Val(txtm2.Text) + Val(txtm3.Text)) / 3) & "%)" End If Me.Width = 9500 End Sub
Private Sub Form_Load() Me.lblsub1.Visible = False Me.lblsub2.Visible = False Me.lblsub3.Visible = False Me.txtm1.Visible = False Me.txtm2.Visible = False Me.txtm3.Visible = False Me.Width = 5000 End Sub
26
Execute
27
Application 7:
Moving the list item across two different lists.
28
Coding
Private Sub cmdexit_Click() End End Sub
29
Execute
30
Application 8:
Changing the text and applying font
31
Coding
Private Sub Check1_Click() If Check1.Value = 1 Then Text1.FontBold = True Else Text1.FontBold = False End If End Sub
Private Sub Check2_Click() If Check2.Value = 1 Then Text1.FontItalic = True Else Text1.FontItalic = False End If End Sub
Private Sub Check3_Click() If Check3.Value = 1 Then Text1.FontUnderline = True Else Text1.FontUnderline = False End If End Sub
Private Sub Combo1_Click() If Combo1.ListIndex = 0 Then Text1.FontSize = Combo1.Text ElseIf Combo1.ListIndex = 1 Then Text1.FontSize = Combo1.Text ElseIf Combo1.ListIndex = 2 Then Text1.FontSize = Combo1.Text ElseIf Combo1.ListIndex = 3 Then
32
Private Sub Combo2_click() If Combo2.ListIndex = 0 Then Text1.FontName = Combo2.Text ElseIf Combo2.ListIndex = 1 Then Text1.FontName = Combo2.Text ElseIf Combo2.ListIndex = 2 Then Text1.FontName = Combo2.Text ElseIf Combo2.ListIndex = 3 Then Text1.FontName = Combo2.Text End If End Sub
Private Sub Form_Load() Combo2.AddItem "Times New Roman" Combo2.AddItem "Arial" Combo2.AddItem "Shruti" Combo2.AddItem "Monotype Corsiva" End Sub
Private Sub Option1_Click() If Option1.Value = True Then Text1.BackColor = vbCyan End If End Sub
33
Private Sub Option2_Click() If Option2.Value = True Then Text1.BackColor = vbBlack End If End Sub
Private Sub Option3_Click() If Option3.Value = True Then Text1.BackColor = vbYellow End If End Sub
34
Execute
35
Application 9:
With the help of menus perform arithmetic operations
36
Coding
37
Execute
38
Application 10
To print the series
1 12 123 1234 12345
Coding
Private Sub Form_Click() For r = 1 To 5 For c = 1 To r Print c; Next Print Next End Sub
39
Execute
40
Application 11
To make a puzzler
41
Coding
Private Sub Command1_Click() If Command2.Caption = "" Then Command2.Caption = Command1.Caption Command1.Caption = "" ElseIf Command4.Caption = "" Then Command4.Caption = Command1.Caption Command1.Caption = "" End If End Sub
Private Sub Command2_Click() If Command1.Caption = "" Then Command1.Caption = Command2.Caption Command2.Caption = "" ElseIf Command3.Caption = "" Then Command3.Caption = Command2.Caption Command2.Caption = "" ElseIf Command5.Caption = "" Then Command5.Caption = Command2.Caption Command2.Caption = "" End If End Sub
Private Sub Command3_Click() If Command2.Caption = "" Then Command2.Caption = Command3.Caption Command3.Caption = "" ElseIf Command6.Caption = "" Then Command6.Caption = Command3.Caption Command3.Caption = "" End If End Sub
42
Private Sub Command4_Click() If Command1.Caption = "" Then Command1.Caption = Command4.Caption Command4.Caption = "" ElseIf Command5.Caption = "" Then Command5.Caption = Command4.Caption Command4.Caption = "" ElseIf Command7.Caption = "" Then Command7.Caption = Command4.Caption Command4.Caption = "" End If End Sub
Private Sub Command5_Click() If Command2.Caption = "" Then Command2.Caption = Command5.Caption Command5.Caption = "" ElseIf Command4.Caption = "" Then Command4.Caption = Command5.Caption Command5.Caption = "" ElseIf Command6.Caption = "" Then Command6.Caption = Command5.Caption Command5.Caption = "" ElseIf Command8.Caption = "" Then Command8.Caption = Command5.Caption Command5.Caption = "" End If End Sub
Private Sub Command6_Click() If Command3.Caption = "" Then Command3.Caption = Command6.Caption Command6.Caption = ""
43
ElseIf Command5.Caption = "" Then Command5.Caption = Command6.Caption Command6.Caption = "" ElseIf Command9.Caption = "" Then Command9.Caption = Command6.Caption Command6.Caption = "" End If End Sub
Private Sub Command7_Click() If Command4.Caption = "" Then Command4.Caption = Command7.Caption Command7.Caption = "" ElseIf Command8.Caption = "" Then Command8.Caption = Command7.Caption Command7.Caption = "" End If End Sub
Private Sub Command8_Click() If Command5.Caption = "" Then Command5.Caption = Command8.Caption Command8.Caption = "" ElseIf Command7.Caption = "" Then Command7.Caption = Command8.Caption Command8.Caption = "" ElseIf Command9.Caption = "" Then Command9.Caption = Command8.Caption Command8.Caption = "" End If End Sub
44
Private Sub Command9_Click() If Command6.Caption = "" Then Command6.Caption = Command9.Caption Command9.Caption = "" ElseIf Command8.Caption = "" Then Command8.Caption = Command9.Caption Command9.Caption = "" End If End Sub
45
Execute
46
Application 12:
Print a table on the form
47
Coding
Private Sub Command1_Click()
End Sub
Execute
48
Application 13
Getting a string input from user and move it along with the border
49
Coding
Private Sub cmdstart_Click() Me.Label1.Caption = Me.Text1.Text Me.Timer1.Enabled = True End Sub
Private Sub Timer1_Timer() If Me.Label1.Left <= 6600 Then Me.Label1.Left = Me.Label1.Left + 10 ElseIf Me.Label1.Top <= 6600 Then Me.Label1.Top = Me.Label1.Top + 10 Else Timer1.Enabled = False
50
Private Sub Timer2_Timer() If Me.Label1.Left >= 0 Then Me.Label1.Left = Me.Label1.Left - 10 ElseIf Me.Label1.Top >= 0 Then Me.Label1.Top = Me.Label1.Top - 10 Else Timer1.Enabled = True Timer2.Enabled = False End If End Sub
51
Execute
52
53