Objects, Instructions and Passing Data
-
Upload
september-barlow -
Category
Documents
-
view
41 -
download
0
description
Transcript of Objects, Instructions and Passing Data
What is Programming?Computer programming is about telling the
computer what it is we want it to do
We tell the computer what we want it to do by sending instructions to objects or passing
data to / between Objects
Computer ComponentsA computer is made up of many different bits of hardware
and computer technology. For example The Screen
The KeyboardThe MouseMemoryHard disc drivesDatabasesE Mail SystemsSound Cards
Why use Objects?Dealing directly with hardware can be very
complicated
We create things called objects which allow us to control the hardware without worrying about how the hardware works
An object is a way of representing computer technology in such a way so that we send it instructions and data
Types of ObjectWeb Forms and Controls
Used to create the interface on – screen
.NET Library ObjectsReady made objects allowing us to do things such a print
or send emails.
VariablesThese objects allow us to store data in the memory of
the computer
Custom ObjectsYou may create your own Objects to perform a whole
host of tasks
Send Password
We shall look at the code for “Send me my password” to see how objects may be used to control the hardware.
Consider the Hardware Involved!The userTypes their first name the keyboard & screenTypes their second name the keyboard & screenEnters their email address the keyboard &
screenPresses the send password button the mouse &
screen The systemSends an email to the user email message
& server
The Click Event
In design view double click the button to view the code for the click event
Add a Break Point
A break point forces the program to stop and wait so that we may see what is happening. To do this press F9. Now try and set up a new user.
Things to NoteHandles btnPassword.ClickSub – End SubComments
Block commentsIn-Line comments
Stepping Through the Code
The program will stop at your breakpoint and wait for further instructions. Press F10 to see how the code executes.
Assignment StatementNotice how the following section of code
works…
In this case a text box object sends data to a variable (object)
Sending an EMailPress F10 a few more times to see how the email is
sent using the email and smtp server objects…
Overview of Objects Covered so farControl objects e.g. txtFirstName
Used to control the interface
Variable objects e.g. FirstName
Used to control the RAM .NET Library objects e.g. MyEMail
Used to create an e mail message
Properties and MethodsPropertiesA property is used to control some setting of the object or
to find out something about the object.e.g. txtFirstName.text
MethodsA method is a command to an object to do somethingThe following lines of code contain a method…
SummaryComputer programming is about telling the computer what
it is we want it to do.
The problem with this computer technology is that there is a huge amount of complexity involved in directly programming them.
In order to get around this we use as programmers tools
called objects. An object is a way of representing computer
technology in such a way so that we send it instructions and data
QuestionsObjects can in theory be used to control any kind of
technology. In these questions imagine that we had objects to control a toaster or a light bulb.
1. Write in your own words a definition of the word “object”.
2. In the case of an object, a method is a task that
does something; a property tells us something about the state of the object. If we were to create an object to control a toaster via VB.NET what methods and properties might it have?
Questions 3. If a toaster object has a property called
“PowerOn”, write a line of code that might turn the power on.
4. What is the = sign called that is used to transfer
data around the program? 5. In the case of a light bulb object, what is wrong
with the following line of VB.NET code? True = MyLightBulb.On