Learn to Program with Visual Basic.NET

Learn to Program with Visual Basic.NET

4.6 6
by John Smiley
     
 

More than 100,000 people have learned how to program from Professor John Smiley. In this unique guide, the guru himself will teach you, in a classroom setting, how to program with Visual Basic.NET. Learn from more than 2000 questions and answers as well as real-world programming projects.See more details below

Overview

More than 100,000 people have learned how to program from Professor John Smiley. In this unique guide, the guru himself will teach you, in a classroom setting, how to program with Visual Basic.NET. Learn from more than 2000 questions and answers as well as real-world programming projects.

Product Details

ISBN-13:
9780072131772
Publisher:
McGraw-Hill Companies, The
Publication date:
01/11/2002
Series:
Learn to Program Series
Pages:
611
Product dimensions:
7.42(w) x 9.14(h) x 1.56(d)

Read an Excerpt

Chapter 2: What Is a Computer Program?

In this chapter, we follow my computer class as they learn what a computer program is and what it does. Along the way, you learn what happens when you turn your computer on and we demystify the behind-the-scenes workings of the computer. Why learn this, you might ask? Although you don't need an intimate knowledge of the inner workings of your computer to write Windows programs, the more you know, the better the programs you can write.

What Is a Computer?

At the conclusion of our last class, I warned my students that during this class meeting we'd need to discuss some of the nitty-gritty of computer hardware and software before we could get on with the fun part�looking at and learning Visual Basic.

"Can anyone give me a definition of a computer?" I asked my class. For whatever reason, everyone seemed a little reluctant to volunteer, so I gave my definition, as follows:

A computer is a machine, made primarily of metal and plastic. It has few moving parts and is mostly electrical in nature. It accepts data in some form of input with which it then performs calculations and other types of operations on the data with tremendous speed and accuracy. It then generates information in some form of output.

"We'll look at some of the terms I use here in a little more detail shortly," I said. I continued by explaining that a computer performs its calculations and operations through instructions provided by a human being. Collectively, these instructions are called a computer program, and the person who writes the program is called a programmer.

"You'll be doing exactly that," I said, "when you write programs in Visual Basic."

Data

Linda noted I used the word "data" in my definition of a computer. She asked me to clarify exactly what I meant by data. I thought for a moment, and said data is anything the computer uses to produce information. Data, for example, can be numbers, letters, symbols, names, addresses, student grades, pictures, or charts.

"But the computer doesn't understand the language of human beings," I said. "For that reason, data must first be translated into a language the computer does understand. Its native language is sometimes known as machine language and takes the form of ones and zeroes. It's also called binary language or binary code."

NOTE
It's not only data that must be translated into binary code. Programs submitted to the computer to run must also be translated.

Several students told me they recognized the word "binary." I asked if anyone could tell me exactly what binary meant.

"Two," Dave answered.

"Good," I said. "Binary means two, and both data and programs are represented in the computer by a series of ones and zeroes."

"Why only ones and zeroes?" Ward asked.

"The reason for this is the computer is electrical," I answered. "It's relatively easy for the computer to represent data and programs as a series of on or off switches, where on is a one, and off is a zero."

I said most of my students are overwhelmed at first by the notion that the computer uses ones and zeroes to represent data and programs, but it's absolutely true. Because of the miniaturized state of the electronic components in the computer, the computer can contain millions and millions of these on/off switches.

"Each one of these on/off switches has a special name�a bit," I said.

Bits
Nearly everyone told me they had heard the word "bit" somewhere.

"A bit sounds like something small and it is," I said. "A bit is the smallest unit of data in the computer. You can think of a bit as the light switch on your wall. It can either be on or off. When a computer bit is on, it has a value of 1. When a computer bit is off, it has a value of 0." I displayed the following sketch on the classroom projector:

"One bit can represent only two values: 1 or 0. Suppose we add a second bit. With two bits, we can represent four possible values."

  • Both bits can be off.
  • Both bits can be on.
  • The first bit can be on and the second bit can be off.
  • The first bit can be off and the second bit can be on.
I displayed the following sketch on the classroom projector...

"...With 3 bits, we can represent 8 possible values. With 4 bits, 16 values. With 5 bits, 32 values. With 6 bits, 64. With 7 bits, 128 values. And, with 8 bits, 256 values."

I displayed the following sketch of eight light switches on the classroom projector, with some of the switches set to on and some set to off...

"...This bit pattern, as it's called," I said, "is the binary form of the capital letter J."

"You're kidding," Ward said. "So my name could be represented in the computer by a pattern of these light switches�I mean ones and zeroes?"

Bytes
"Exactly right," I replied. "A unique bit pattern exists for every letter of the alphabet (both uppercase and lowercase), each number and each punctuation key on the computer's keyboard."

I asked the students to take a quick look at their keyboard. The keyboard has 26 letters.

Counting both lowercase and uppercase letters, there are 52. Count the numbers and we're up to 62. Now count the punctuation keys.

"On my keyboard, I count another 32," Rose said.

"That gives us a total of 94," Jack said.

I explained that to represent any one of those 94 characters on the keyboard requires 7 bits, because 7 bits can represent 128 characters. To represent the non-printable characters as well requires 8 bits.

"A collection of 8 bits is called a byte," I said, "and the standardized bit pattern is known as the ASCII code. ASCII stands for the American Standard Code for Information Interchange." "Where can we find the ASCII code?" Barbara asked.

"When we start up Visual Basic, you'll find the ASCII code can easily be found in Visual Basic's online help by searching for the keyword ASCII."

I told the class not to be intimidated by all this talk of bits and bytes because memorizing the ASCII code isn't necessary to be a good programmer. However, knowledge of what goes on behind the scenes can be invaluable.

"A Visual Basic programmer should be aware of binary," I said, "because Visual Basic, like all other programming languages, acts as a translator. The programmer writes in a language�in our case Visual Basic�which is similar to English. Then something known as the Visual Basic compiler converts this English-like writing to binary code which the machine can understand."

Memory

"OK," I said. "We've looked at the most basic form of data in the computer. Now let's examine how and where that data is stored in the computer."

I continued by saying that something that always seems to confuse students is the concept of computer memory. I reminded them of my definition of a computer: it accepts data, and performs calculations and other types of operations on that input to generate information.

"These calculations and operations are performed in the computer's memory," I said. "Computer memory is also called RAM, which is an acronym for random access memory. Bits and bytes are recorded electrically in the computer's RAM. The computer uses RAM just like you would use a piece of scratch paper. RAM holds not only data, but every program currently running."

I displayed the following sketch on the classroom projector...

"...Here's a sketch of RAM use in a typical computer," I said.

"Do we need to memorize this?" Rhonda asked.

"Goodness, no!" I exclaimed. "I'm not discussing RAM for that reason. What's important here is for you to understand how the computer uses it�that's what can make you a better programmer." I continued by explaining that RAM temporarily holds programs currently running and any data these programs require.

"How temporary is temporary?" Mary asked.

"A fraction of a second," I said. "The ones and zeroes stored in RAM are there only as long as the computer is on. When you turn your computer off, the contents of RAM, the bits and bytes, are lost."

"If you're using your computer," I said, "and a thunderstorm suddenly knocks your power out, the contents of RAM are lost in an instant. The term volatility is used to describe the temporary and fragile nature of RAM."

"What do KB and MB mean?" asked Rhonda.

"KB is an acronym for kilobyte, which is the term for approximately one thousand bytes. A megabyte�MB is its acronym�is approximately a million bytes," I replied. "We'll look more at these terms when we discuss computer storage."

"Something that confuses beginners," I said, "is the notion of RAM capacity and the speed at which data can be accessed from it. When you buy a computer, it comes with a certain amount or capacity of RAM, which is also rated with a length of time. The capacity tells you the total number of bytes the computer's RAM can hold and the rating indicates the time it takes the computer to get to or access a particular piece of data in RAM."

"I've taken a look inside my computer at home and I know I have 32MB of RAM and it's rated at 60 nanoseconds," Peter said.

"Thank you, Peter," I said. "A nanosecond is one billionth of a second. This means Peter's computer can access a particular piece of data in RAM in 60 billionths of a second."

I continued by saying that in addition to RAM, other devices in the computer also have ratings. For instance, floppy disks and hard disk drives are rated in the millisecond range. Because 1,000,000 nanoseconds are in a millisecond, accessing data from a floppy disk or hard disk drive takes a much longer time than accessing the same data from RAM.

"Relatively speaking then, RAM is very fast," Dave said. "Yes it is," I agreed.

"My computer has 4 gigabytes of RAM," Ward said proudly.

"Actually," I replied, "that'll be the storage capacity of your hard disk drive, which is also measured in bytes. Your hard drive has 4 billion bytes of storage space, as a gigabyte, whose acronym is GB, is approximately 1 billion bytes. I told you these terms could be confusing. Your computer has a certain amount of RAM and a certain amount of storage. We'll look at the concept of storage in a minute or so."

Linda observed that RAM capacity is always less than the capacity of the computer's hard drive. "Excellent observation, Linda," I said. "RAM, as I mentioned, uses electricity to store bits and bytes, and is much more expensive than disk drives, which use magnetism to permanently store bits and bytes. At home, my computer contains 32MB of RAM, while my hard disk drive contains 3.1GB. Therefore, the capacity of my disk drive is about 100 times as large as my RAM."

I displayed the following slide on the classroom projector:

To Summarize then, RAM:

  • Uses electricity to store ones and zeroes.
  • Holds programs and data for execution.
  • Is temporary in nature, sometimes called volatile.
  • Has less capacity than a hard disk drive.
  • Is faster than a hard disk drive.
  • Is more expensive than a hard disk drive....

Read More

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >