Welcome back to Introduction to Visual Basic. This is the second course in the sequence for computer programming with visual basic specialization. We're in the second module. In this module we're going to think about data types. We're going to think about how computers store data during the execution of our programs and how we can share information to the compiler and what data we're going to store. Let's drill and have some fun. Some learning objectives. By the time you're done with this module, I want you to be able to develop programs that utilize integers. You should also be able to develop programs that utilize decimal numbers, use simple strings, Boolean values. You should be able to convert between different data types. You should also be able to describe when a variable goes in and out of existence. In our first lesson, we're going to think about primitive data types. These are the built-in data types and then later on we're going to expand on this. There's lots of them. Basically, in front of you you see a table with four columns. The first column is the key word. This is what you're going to use in the visual basic programming language. The second column is the number of bytes. From our first course, remember one byte is eight bits. The third column is essentially the type, this fits to the underlying.NET. You can share programs between different languages. We've talked about this a little bit between C-sharp and visual basic and F sharp or other languages that are built in. So they have this type that goes across all these different languages. The last column is a description. For example, the first row here is a byte. It takes one byte and it stores a value from zero to 255, this is a numeric value. The next type is a signed byte, that's a second row, an Sbyte. Again, this takes one byte, but this has a sign and so it's going to be from negative 128 to positive 127. You can see that using a bit for the sign takes away some of the range in our positive numbers. Then we move on to short, an unsigned short or Ushort. These are essentially a two byte number, and so we get a range from negative 32,000 to positive 32,000 when it's signed or up to 65,535 for unsigned short. Then we get into our integers. These are four bytes. We have an integer, an unsigned integer, and you'll see we're now in the negative 2 million to positive 2 million or up to a billion for the unsigned. Let's stop here before I keep going and think about this a little bit. You want to use the smallest data type that you need, but you don't want to be too stringent. You don't want to ever overflow. We talked about overflowing in our first course. If you need a value that's 99 percent of the time between zero and 255, but sometimes they're larger, use two bytes. Use one of the shorter, unsigned short, depending if you need negative numbers or not. But you want to minimize the usage because we're very wasteful today. If you ever tried to look at how much Google Chrome or Firefox or Microsoft Edge or Safari use while they're browsing, it's ridiculous. It's using so much memory because we're so focused on adding new features and we're not spending time maximizing our software to be more efficient. What I want you to think about is choose the right data type. So far we've thought about numbers and we thought about one byte, two byte, and four byte numbers. Most numbers you're ever going to represent are going to be someplace in that range. But we also have a long which is an eight byte number and you'll see the huge range we see here. We have an unsigned long. Again, an eight byte number, but here we go from zero to some huge number. Now we move into decimal numbers, single, double. Now, these are scientific notation. You probably learn scientific notation one time in your past. Scientific notation is great for some of the sciences where we need to have a lot of decimal positions, but we don't need exactness. The number of decimal positions is more important, so we have approximations. Don't ever use a single or double for currency value because you'll get some rounding errors. They tend to be very small but the right data type is a decimal, which is the fourth row in front of you. This is designed to store things like currencies where it doesn't have the same number of decimal precision but is more exact. They use a lot more bytes though. You'll see, so for every decimal we're using 16 bytes. Then the last two here are character and Boolean. A character is designed to store a Unicode character. A Unicode character is from zero to 65535 different characters. In the old days we had one byte characters, but they can only represent Latin-based languages. The Eastern languages have more characters in their alphabet than 256. So we move to this two-byte idea and this concept of Unicode, where Unicode has 65,000 different characters. The last, this Boolean which is either true or false. Don't we want to think about how we declare a variable and we tell it the data type. Syntax is essentially we say Dim, the variable name and then anything in brackets here is optional. I'm going to say As Type. If I don't tell it the type, visual basic is going to try to figure it out. I might as well tell it if I know it, it's going to make the efficiency better, and then I can initialize it with an expression. I've got two examples in front of you. I create a variable called mycounter, and I make it an integer. Remember, an integer is going to be four bytes and it's going to store both positive and negative numbers. Remember the slides are up in the readings, so you can go back to the slides if you want to have that up while I'm talking about this, or you can pause and go back to see those ranges. The next variable I have my example here is mylcounter. This is a long, it's a four byte and I'm going to initialize it to the value 2,000.