Visual basic

  • 3,151 views
Uploaded on

programs for visual basic

programs for visual basic

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
3,151
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
424
Comments
1
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Practical File Workshop On Visual BasicSubmitted To: Submitted By:Prof Anil Sharma Alisha Korpal BCA 1
  • 2. INDEXSno Topic Page no1 Introduction to VB 32 Tool Box 43 Property 54 Description -- Properties 65 Description -- Controls 76 Application 1: Showing labels and text boxes 87 Description -- Command button 98 Application 2: To Perform Arithmetic Operations on two numbers 109 Description – Controls 1310 App 3 : Detail of any option click 1411 App 4 : Application Form 1712 Description -- control 2013 App 5: Traffic lights 2114 App 6: Getting marks of student and print result in another form 2415 App 7: Moving the list item across two different lists 2816 App 8: Formatting Text 3117 App 9: with the help of menus perform Arithmetic operation 3618 App 10: Print the series on form 3919 App 11: Puzzle 4120 App 12: Print table on the Form 4721 App 13: Getting a string input from user and move it along border 49 2
  • 3. Introduction to VBVisual basic is an event driven programming. In event driven programming, the interfacecomponents have the ability to recognize user events and then, if possible a response is givento the event occurred. The response of identical interface components to an event candifferent in different situations. In addition, an interface component may also respond tomultiple 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 anapplication 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 3
  • 4. Tool BoxThe toolbox is a collection of tools that act as a repository of controls you can place on aform. 4
  • 5. PropertiesEach property has a name so we can work with a particular property, and each property has avalue that either we or Visual Basic assigns. For example, Visual Basic always names thefirst command button we add to a project Command1. Therefore, the Name property for thefirst command button holds the value Command1 5
  • 6. Property DescriptionAlignment : Determines whether text on the control, such as a label or command button, is left-justified, centered, or right-justified on the control.BackColor : Specifies the color of the controls background, which you select from a palette of colors when you open the property drop- down list box of colors.BorderStyle : Determines whether the control has a border around it.Caption : Lists the text displayed on the control.Enabled : 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 : Displays a Font dialog box from which you can set various font properties, such as size and style, for a controls text.ForeColor : Specifies the color of the controls foreground, which you select from a palette of colors when we open the propertys drop-down list box of colors.Height : Specifies the number of twips high the control is.Left : Indicates the starting twip from the left edge of the form where the control appears.Mouse Pointer : Determines the shape of the mouse cursor when the user moves the mouse over the control at runtime.Name : Specifies the name of the control. As you saw in yesterdays lesson, the Properties window displays the .Tooltip Text : Holds the text that appears when the user rests the mouse Cursor over the control at runtime (similar to ScreenTips). 6
  • 7. 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 labels text through code. 3. The Text Box Control Use a text box control when we want the user to type something, such as an answer to a prompt, when we want to collect values, such as name and address information. Often, a default value is helpful for users, and Visual Basic program can supply an initial value. 7
  • 8. 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 . 8
  • 9. 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. 9
  • 10. Application 2: WAP to add, subtract, multiply and divide two numbers?Step 1:Create a form 10
  • 11. Step 2:Start the codingPrivate 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 SubPrivate Sub Form_Load()MsgBox (" Hello Welcome to perform operations")End Sub 11
  • 12. Step 3:Execute the program 12
  • 13. 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
  • 14. Application 3WAP to show the option button?Step 1:Make a form 14
  • 15. Step 2:Codingprivate 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 IfEnd Sub 15
  • 16. Step 3: Execute 16
  • 17. Application 4WAP to make an application Form? 17
  • 18. Step 2Private Sub Command1_Click()MsgBox (txtname.Text & Cmbqual.Text & ",your data has been submited")End SubPrivate Sub Command2_Click()txtname.Text = ""Me.Option1.Value = TrueCmbqual.Text = "B.A"chkmusic.Value = Falsechkpaint.Value = Falsechkread.Value = FalseEnd Sub 18
  • 19. Step 3:Execute 19
  • 20. 10. Timer: The timer control is an invisible control which is added to form if some task is to be repeated regular intervals11.Shapes The shape control is a graphical control that is used to display a rectangle, oval, circle or rounded square. 20
  • 21. Application 5:WAP to show the working of timer?Step2: 21
  • 22. CodingPrivate Sub Timer1_Timer()If Shape1.Visible Then Shape2.Visible = True Shape1.Visible = False Shape3.Visible = FalseElseIf Shape2.Visible Then Shape3.Visible = True Shape2.Visible = False Shape1.Visible = FalseElse Shape3.Visible Then Shape1.Visible = True Shape2.Visible = False Shape3.Visible = FalseEnd IfEnd Sub 22
  • 23. Step 3:Execute 23
  • 24. Application 6:Getting the particulars form the user and printing the result inanother frame? 24
  • 25. 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 = TrueElseIf 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 = TrueEnd IfEnd SubPrivate Sub cmdexit_Click()EndEnd SubPrivate Sub cmdres_Click()Me.lblname.Caption = "Name: " + Me.txtname.TextMe.lblroll.Caption = "Roll No.: " + Me.txtrollMe.lblstream.Caption = "Stream: " + Me.cmbstream.TextMe.lblm1.Caption = Me.lblsub1.Caption + ": " + Me.txtm1 25
  • 26. Me.lblm2.Caption = Me.lblsub2.Caption + ": " + Me.txtm2Me.lblm3.Caption = Me.lblsub3.Caption + ": " + Me.txtm3If ((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 IfMe.Width = 9500End SubPrivate Sub Form_Load()Me.lblsub1.Visible = FalseMe.lblsub2.Visible = FalseMe.lblsub3.Visible = FalseMe.txtm1.Visible = FalseMe.txtm2.Visible = FalseMe.txtm3.Visible = FalseMe.Width = 5000End Sub 26
  • 27. Execute 27
  • 28. Application 7:Moving the list item across two different lists. 28
  • 29. CodingPrivate Sub cmdexit_Click()EndEnd SubPrivate Sub Command1_Click()List2.AddItem (List1.Text)List1.RemoveItem (List1.ListIndex)End SubPrivate Sub Command2_Click()List1.AddItem (List2.Text)List2.RemoveItem (List2.ListIndex)End Sub 29
  • 30. Execute 30
  • 31. Application 8:Changing the text and applying font 31
  • 32. CodingPrivate Sub Check1_Click()If Check1.Value = 1 Then Text1.FontBold = TrueElse Text1.FontBold = FalseEnd IfEnd SubPrivate Sub Check2_Click()If Check2.Value = 1 Then Text1.FontItalic = TrueElse Text1.FontItalic = FalseEnd IfEnd SubPrivate Sub Check3_Click()If Check3.Value = 1 Then Text1.FontUnderline = TrueElse Text1.FontUnderline = FalseEnd IfEnd SubPrivate Sub Combo1_Click()If Combo1.ListIndex = 0 Then Text1.FontSize = Combo1.TextElseIf Combo1.ListIndex = 1 Then Text1.FontSize = Combo1.TextElseIf Combo1.ListIndex = 2 Then Text1.FontSize = Combo1.TextElseIf Combo1.ListIndex = 3 Then 32
  • 33. Text1.FontSize = Combo1.TextEnd IfEnd SubPrivate Sub Combo2_click()If Combo2.ListIndex = 0 Then Text1.FontName = Combo2.TextElseIf Combo2.ListIndex = 1 Then Text1.FontName = Combo2.TextElseIf Combo2.ListIndex = 2 Then Text1.FontName = Combo2.TextElseIf Combo2.ListIndex = 3 Then Text1.FontName = Combo2.TextEnd IfEnd SubPrivate Sub Form_Load()Combo2.AddItem "Times New Roman"Combo2.AddItem "Arial"Combo2.AddItem "Shruti"Combo2.AddItem "Monotype Corsiva"End SubPrivate Sub Option1_Click()If Option1.Value = True Then Text1.BackColor = vbCyanEnd IfEnd Sub 33
  • 34. Private Sub Option2_Click()If Option2.Value = True Then Text1.BackColor = vbBlackEnd IfEnd SubPrivate Sub Option3_Click()If Option3.Value = True Then Text1.BackColor = vbYellowEnd IfEnd Sub 34
  • 35. Execute 35
  • 36. Application 9:With the help of menus perform arithmetic operations 36
  • 37. CodingPrivate Sub add_Click()Me.answ.Text = Val(txtnum1.Text) + Val(txtnum2.Text)End SubPrivate Sub divi_Click()Me.answ.Text = Val(txtnum1.Text) / Val(txtnum2.Text)End SubPrivate Sub min_Click()Me.answ.Text = Val(txtnum1.Text) - Val(txtnum2.Text)End SubPrivate Sub mult_Click()Me.answ.Text = Val(txtnum1.Text) * Val(txtnum2.Text)End Sub 37
  • 38. Execute 38
  • 39. Application 10To print the series112123123412345CodingPrivate Sub Form_Click()For r = 1 To 5For c = 1 To rPrint c;NextPrintNextEnd Sub 39
  • 40. Execute 40
  • 41. Application 11To make a puzzler 41
  • 42. CodingPrivate Sub Command1_Click()If Command2.Caption = "" Then Command2.Caption = Command1.Caption Command1.Caption = ""ElseIf Command4.Caption = "" Then Command4.Caption = Command1.Caption Command1.Caption = ""End IfEnd SubPrivate 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 IfEnd SubPrivate Sub Command3_Click()If Command2.Caption = "" Then Command2.Caption = Command3.Caption Command3.Caption = ""ElseIf Command6.Caption = "" Then Command6.Caption = Command3.Caption Command3.Caption = ""End IfEnd Sub 42
  • 43. 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 IfEnd SubPrivate 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 IfEnd SubPrivate Sub Command6_Click()If Command3.Caption = "" Then Command3.Caption = Command6.Caption Command6.Caption = "" 43
  • 44. ElseIf Command5.Caption = "" Then Command5.Caption = Command6.Caption Command6.Caption = ""ElseIf Command9.Caption = "" Then Command9.Caption = Command6.Caption Command6.Caption = ""End IfEnd SubPrivate Sub Command7_Click()If Command4.Caption = "" Then Command4.Caption = Command7.Caption Command7.Caption = ""ElseIf Command8.Caption = "" Then Command8.Caption = Command7.Caption Command7.Caption = ""End IfEnd SubPrivate 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 IfEnd Sub 44
  • 45. 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 IfEnd SubExecute 45
  • 46. 46
  • 47. Application 12:Print a table on the form 47
  • 48. CodingPrivate Sub Command1_Click()For k = 1 To 10Print Val(Text1.Text) * kNextEnd SubExecute 48
  • 49. Application 13Getting a string input from user and move it along with the border 49
  • 50. CodingPrivate Sub cmdstart_Click()Me.Label1.Caption = Me.Text1.TextMe.Timer1.Enabled = TrueEnd SubPrivate Sub cmdstop_Click()Me.Timer1.Enabled = FalseMe.Timer2.Enabled = FalseEnd SubPrivate Sub cmdexit_Click()EndEnd SubPrivate Sub Form_Load()Me.Timer1.Enabled = FalseMe.Label1.Left = 0End SubPrivate Sub Text1_Click()Me.Text1.Text = ""Me.Text1.SetFocusEnd SubPrivate Sub Timer1_Timer()If Me.Label1.Left <= 6600 Then Me.Label1.Left = Me.Label1.Left + 10ElseIf Me.Label1.Top <= 6600 Then Me.Label1.Top = Me.Label1.Top + 10Else Timer1.Enabled = False 50
  • 51. Timer2.Enabled = TrueEnd IfEnd SubPrivate Sub Timer2_Timer()If Me.Label1.Left >= 0 Then Me.Label1.Left = Me.Label1.Left - 10ElseIf Me.Label1.Top >= 0 Then Me.Label1.Top = Me.Label1.Top - 10Else Timer1.Enabled = True Timer2.Enabled = FalseEnd IfEnd Sub 51
  • 52. Execute 52
  • 53. 53