Introduction to Visual Basic
Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and Running an Application Opening and Closing a Project
Intro to Visual Basic An application contains program code which are instructions that tell a computer how to perform a specific task Each line of code is called a statement Most programs you use contain millions of statements and are usually written by teams of programmers VB writes a lot of code for you! This code generates the initial form and sets the default properties of the form. Program Code
Intro to Visual Basic Program Code Cont’d Also, when you draw in a control object in the design window, such as a button, VB generates code automatically to create that object; the code for the object’s functionality is left to you You can get to the code window by using the Solution Explorer Window or by double clicking any object in the form, including the form itself
Intro to Visual Basic Visual Basic Facts BASIC is actually an acronym and stands for Beginner's All-purpose Symbolic Instruction Code BASIC is an old programming language; the “Visual” part has been added recently to make it easier to create powerful windows applications
Intro to Visual Basic Event-Driven Application A Visual Basic application is event driven An event occurs when the user interacts with the application. For example, when a user clicks a button, this is an event
Intro to Visual Basic Event Driven Application Con’t An event-driven application waits for an event to occur before executing code When an event occurs, only the code written to handle that event is run For example, in the simple program below, when the ‘Exit’ button is pressed, the code for that button is executed. If the code is properly written, pressing the button should close the program
Intro to Visual Basic Visual Basic Interface The Visual Basic interface consists of two parts: a graphical interface (“Visual”) and the program code (“BASIC”) graphical interface (“Visual”) program code (“BASIC”)
Becoming Familiar with Visual Basic.NET
Intro to Visual Basic Creating a New Project Click on File>New>Project to bring about the New Project Dialog Box as seen below
Intro to Visual Basic Properties Window The Design Window Toolbox Solution Explorer Window Design Window
Intro to Visual Basic The Design Window Con’t The Design window displays the application interface where objects are added, deleted, and sized The Toolbox contains controls that are used to create objects The Solution Explorer window is used to switch between the Design and Code windows The Properties window lists the properties of a selected object
Intro to Visual Basic The Windows Form A windows application uses at least one form A form is where you design your user interface and put controls such as buttons and textboxes A form can be resized by using the control handles A form has properties that define its appearance and behavior
Intro to Visual Basic Form Properties We can change the properties of our form by selecting the form (click on it) and changing whatever property we want in the Properties Window
Intro to Visual Basic Control Objects Control objects are objects that we can place on our form to create a user interface An user interface is a way of getting input from the user and providing output to the user Some control objects are meant to get user input such as a textbox; other objects are used for output such as labels
Intro to Visual Basic The Label Control Object The label control displays text that cannot be changed by the user The label control is used as an output to display messages to the user Label
Intro to Visual Basic Creating a Label Control Click on the Label control in the toolbox When you place the cursor over the form, the cursor changes Click and drag to draw the label The grid on the form is used to help you create your interface, but does not show up in the final program
Intro to Visual Basic Label Properties The label control has the properties Name identifies the label for you as the programmer; the user never sees this name Text is the message you wish to display to the user Font allows you to change the appearance and font settings of the message you display to the user TextAlign allows you to set the alignment of text in a label. For example, TopLeft, TopCenter…
Intro to Visual Basic Setting Label Properties
Intro to Visual Basic Just to Give You an Idea labels can be used in conjunction with textboxes to get input from the user
Intro to Visual Basic The MainMenu Control A Windows application usually includes menus that contain commands A menu is added to an interface by clicking the MainMenu control in the toolbox and then clicking on the form A menu is automatically added to the interface and a MainMenu component is added to the component tray at the bottom of the Design Window
Intro to Visual Basic Working with MainMenus Click where it says, “Type Here” on the menu in the form to enter commands such as ‘File’, ‘Edit’ When a command or menu name is typed, another box is automatically added to allow for more commands and menus Only the command and menu names that were typed by you will show up at run-time
Intro to Visual Basic MainMenu Properties Name identifies the menu and commands for you as the programmer; the user never sees this name Text is the menu or command name and is set by clicking on the ‘Type Here’ text on the menus in the design window
Intro to Visual Basic Saving and Running an Application Save your work often during development to avoid losing changes To run your program, which you should do often to test what you’ve done, click on the ‘Start’ button If your program has no errors, pressing this button should run your program. Now you can see and use your program as a user would see and use it. You can test its functionality by interacting with it the way you intend a user to interact with it
Intro to Visual Basic Saving and Running an Application Con’t To return to the design window to continue development, simple close the running program (click the ‘x’ in the top right corner of your application)
Intro to Visual Basic What is Really Happening? What really happens when you click the ‘Play’ button? First, the code that you, the programmer writes, is converted into a language that the computer understands in a process called compiling During the compiling process, your program code is checked for syntax errors If there are no syntax errors in your code, VB.NET then builds your application More on all this later…
Intro to Visual Basic Closing and Opening a Project To save your work, click File>Save.vb To close a project, click File>Close Solution To open a project, click File>Open>Project. Then Navigate to find your project in the Open Project Dialog Box.