Visual Basic
E N D
Presentation Transcript
Visual Basic Week 1
What is Visual Basic? • Visual Basic is an easy to learn programming language • Can develop Windows based applications • Visual Basic is an easy yet powerful programming language
Advantages of VB • Simple • Popular = lots of resources • Many tools available on the Internet to save you some programming time
Disadvantages of VB • Not suitable for programming sophisticated games • Slower than other languages
Getting Started (continued) • Look at the form with the title bar Form1 • Everything you place on this form will appear in your program • To run your program click on the Play button on the toolbar
Getting Started (continued) • To stop the program click the form’s X button or select the Stop button on the tool bar
Properties • Every component/object of your program has properties that determine its look and function • For Example: Font, Fore Color, Icon, Text • To see the properties window, select View -> Properties Window from the menu bar
Changing Properties • Change the form’s Text property
Adding Controls • There are many control that can be added to your program • For example: buttons, text boxes, scroll bars and more • The controls are listed in the toolbox
Adding Controls • Double Click • Drag and Drop • Click and Locate
Changing Properties • Right-click on the control • Select the control from the properties window control box
Events • VB is an Event Driven language • Events are actions that are taken in the program • For example: keypress, mouseover, click and many more • Events are coded in the Code window
Form_Load Event • The form load event should look like this: Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load (The beginning of the Form_Load event)This is the code that belongs to the Form_Load eventEnd Sub (The end of the Form_Load event)
Add a Message Box • Adding a message box to the form load event • Add MsgBox(“Hello”) • Between the Private Sub and the End Sub statements • Run Program
More Events • Click the Drop-Down List that appears in the upper left corner of the code window to choose the object
More Events • Click the Drop-Down List that appears in the upper right corner of the code window to see the events
FormClosing Event • The FormClosing event occurs when the form is being unloaded when you click the form’s X button • Type MsgBox("Good Bye") between the Private Sub and the End Sub statements • Run the program • Close the program
Command Button’s Events • Double-click or right-click and select View Code to open the code window for the command button • Type MsgBox("You have Clicked on the button!") between the Private Sub and the End Sub statements • Run the program and click on the command button