20
Introduction to Programming Creating a Visual Basic Application

Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Introduction to Programming

Creating a Visual Basic Application

Page 2: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Getting Started

• We will be using Visual Basic 2010 Express. It can be found in the Business & Computer Studies folder on the desktop

• This software is also available for free from the Microsoft Website.

Page 3: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Some Definitions

• An object is a structure that contains data and methods that manipulate the data.

• Almost everything that you do in Visual Basic is associated with objects.

• If you are new to object-oriented programming, the following terms and concepts will help you get started.

Page 4: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Classes and Objects

• The words "class" and "object" are used so much in object-oriented programming that it is easy to confuse the terms.

• A class is an abstract representation of something, whereas an object is a usable example of the thing the class represents.

Page 5: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Fields, Properties, Methods and Events

• Classes consist of fields, properties, methods, and events.

• Fields and properties represent information that an object contains.

• Fields are like variables because they can be read or set directly. For example, if you have an object named "Car" you could store its color in a field named "Color."

Page 6: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Methods

• Methods represent actions that an object can perform. For example, a "Car" object could have "StartEngine," "Drive," and "Stop" methods. You define methods by adding procedures, either Sub routines or functions, to your class. (we will see much later in this unit)

Page 7: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Events

• Events are notifications an object receives from, or transmits to, other objects or applications.

• Events enable objects to perform actions whenever a specific occurrence occurs. An example of an event for the "Car" class would be a "Check_Engine" event.

– Because Microsoft Windows is an event-driven operating system, events can come from other objects, applications, or user input such as mouse clicks or key presses.

Page 8: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Create a Project with VB

• Once you have Visual Basic open:

• Click File and then New Project in the toolbar.

• In the window that appears, select Windows Form Application

Page 9: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

• One of the great things about Visual Basic is the ease of placing new objects into your program.

• Using the Toolbar, add a textbox, label, and 3 buttons.

• You will notice that these objects come with default values.

Page 10: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can
Page 11: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Properties of Objects

• Everything you add to a form is called an Object.

• The things you can change or modify are called Properties.

• Proper techniques when programming allow for you to easily remember what the objects do and the use of your variables in your program.

Page 12: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Naming Objects

• When naming objects in your code, you should always use a short form of the object type followed by a brief name that give you a sense of its purpose.

• For example,

– A button object would be named bChangeColour, the b is for the button object and ChangeColour is what it will do.

Page 13: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

• Now change the name of your buttons in your form.

• Change them to bColourForm, bColourFont, bChangeText

• To do so, simply select them on your form, than go change the (Name) property of the button. You can change the Text property as well at this time.

Page 14: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

• Now go and change the names of you textbox and your label.

• As you can see, there are several properties that can be changed for each object, and the properties are different for each type of object as well.

• Now change some of the default property values for your objects. Look at the form properties as well.

Page 15: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

Coding Your Buttons

• For this first project, we will use the buttons to change the properties of the objects on your form (and the form itself).

• Begin by double-clicking on your first button.

• This will open your source code view of the project.

Page 16: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

• Now change the value of the BackColor for the form.

• To do this, your must type the object you want to modify, in this case Form1, unless you changed its name.

• Then you use the . to access its properties.

• Notice that Visual Basic automatically gives you a list of possible choices.

Page 17: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

• Start typing BackColor and it will come up automatically before you finish typing it.

• At anytime, you may hit the spacebar to select the selected term in the list.

• Now to set a property, we use the = symbol.

• Again, VB will give you a set of options for the colour. Select any one you want. I recommend you select something other than black.

Page 18: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

• Because we are only using one form in this project, you will have to change the start of you code to use Me instead of Form1, because VB does like you referring to a form when you are coding in it.

Page 19: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

• Run your application.

• This can be done by hitting F5.

• Now complete the code for the other two buttons. These buttons will make changes to the label object.

• Create New buttons (3) to undo the actions of the previous buttons.

Page 20: Introduction to Programming - Weeblyfon10.weebly.com/uploads/1/3/4/7/13472506/ics2o_2_1... · 2019. 8. 24. · Getting Started •We will be using Visual Basic 2010 Express. It can

• For an extra challenge, add a button that changes the label to the info you have typed in your textbox.

• Once complete, send a screen shot of your completed, running application and a copy of your source code.

• Save your work as john_s_2_1_start (where john_s is replaced by your name) under the appropriate folder for your class in the DropOff folder on the X: drive