Learn to Program in Visual Basic with Visual Studio | Louis Irwin | Skillshare

Playback Speed


  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Learn to Program in Visual Basic with Visual Studio

teacher avatar Louis Irwin

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

19 Lessons (1h 25m)
    • 1. Introduction Video

      1:12
    • 2. Installing Visual Studio

      1:51
    • 3. Introduction to Visual Basic

      6:05
    • 4. Comments

      1:29
    • 5. Operators

      2:50
    • 6. If Statements

      5:48
    • 7. Activity 1

      3:23
    • 8. Activity 1 Solution

      3:08
    • 9. Subroutines and Functions

      7:27
    • 10. Variables by Reference and by Value

      3:09
    • 11. Loops

      4:47
    • 12. Activity 2

      4:47
    • 13. Activity 2 Solution

      7:09
    • 14. Arrays

      8:05
    • 15. Multi Dimensional Arrays

      8:20
    • 16. Lists

      8:02
    • 17. Custom Data Types

      5:43
    • 18. Final Project

      1:12
    • 19. Next Steps

      0:54
  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

377

Students

--

Projects

About This Class

With this class, you can learn to be a master of the visual basic programming language! Not to be underestimated, visual basic is an entry level to professional level programming language designed and maintained by Microsoft.

In this class, you'll become proficient in the basics of both visual basic and the IDE visual studio, with little to no experience with programming assumed.

This class is focused on using console applications to teach the basic principals of programming and visual basic.

Meet Your Teacher

Teacher Profile Image

Louis Irwin

Teacher

Hello, I'm Louis.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
    0%
  • Yes
    0%
  • Somewhat
    0%
  • Not really
    0%
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Introduction Video: Hello, Mining low and I hope to be able to join me. My course Learning visual basic visual Basic is a great first programming language to learn . I want to show you how to do it. This is all the content that we're gonna be covering the course. A whole load of stuff I worked really down. I don't want a boy and it will all be done using Microsoft's visual studio with best about went viral visual basic throughout this course your girl of all these key skills as well as be tested on them with program exercises. The Waldo, ranging from beginning introduction exercise a whale to make it in time tables get these we made using the skills that you pick up on this course. So who is this course aimed at this course is aimed at three groups of people. Firstly, beginners looking for a good program visual base, his super simple and really easy to pick up, which makes it an ideal program. Developers with prior experience looking Teoh learn visual basic for first time. You already know the programming fundamentals and that's cool. Cohen joining us alone visual basic Finally, developers who had experience with visual raising before. They're just looking for a refresher course on the basics off. Visual basic. That's a brief overview. This course I really hope you can join me for it. Thanks for watching on. What are you waiting for? I'll see you in there. 2. Installing Visual Studio: Okay, So in this video, we'll look at how to download and install visual studio. Visual Studio is the idea in tripped development environment that will be using to develop visual basic the first time. Go do it's hop over to www dot dot visual studio dot com. Just hit download for Windows with community. Because visual basic is Mike's product will have to be worked. No Windows it won't work with now that I'm going to click on it to run It wanted to be administrator to store Monty. Okay, so here we go. Now that's finished Way. Get taken to the video of Studio Installed On what? We're going to want to click his .net about me to see their visual basic. That's what we want. No, that's so now we're months quite large. Insel. It's 3 25 gigabytes. Okay, so about five minutes from store May After you do that, you need to recycle. Okay, so now that we've rebuilt in visual studio is being sold from, we can see that right then Recently added. So I'm gonna go ahead stuff now. He's gonna ask us assigning You don't have to, but I think it definitely helps. I'm gonna go ahead and sign it. Okay, so now there was signed it. It's just gonna go on, set up everything it needs to settle. It shouldn't take long. Here we go. Start paid off. Visual studio now. Visual studio is great. Editor. We can use a text editor debug and load wanting more about those next figure. Now that we've got listen stalled, Feel free to go ahead to the next video Self Kony and visual basic. 3. Introduction to Visual Basic: way left off last time having just installed visual studio. Now let's jump in and use it to create our first visual basic. This is stop age individuals, CDF units. While your projects will be like, stop new projects like you, This gives us a what? Types of projects that can create at the main to refocus I'm focusing on is windows, former on console windows, former aides, something like you might see a file explorer that will be a windows former. When it comes a lot, something might see such a commander. So just start up. We're gonna use a council. We will call it my This is our visual studio. Takes us from just great New Project six. You've been given a black module on a blank of module just away. Quite a warrior code together in one place on this main subroutine hair is your main billet code that will run a soon if you stopped. This is the program that we're gonna be creating today. Rather simple. It just actually what is your name says hello. You're right. So to go about that first gonna declare a variable to represent the name of these. Now we do not video, right? So I'm gonna declared a variable name has a strength. Now the variable can be thought of as a place to store a bit of information. In this case, we're gonna story on the A string tells me to wait. You wanna store that has a string of characters? There were a few basic dates times you know about this interview which doors numbers, string guage stores, characters through In which the truth, folks. Then you've got double and single which start floating point numbers such as 2.5 or three and 3/4 as well as of the visual basic. Find one such a date. You can also create your own, which will be doing This is a good time to introduce visual studio's real time syntax. And this means as you're typing visual wakes, crying, interpreted code and see if it makes sense. Receipts. Flexible warning on the very name underlying greens tell me is that we have not used yet. That's okay, because we haven't yet, but we plan to in a minute under the type of errors that people if you miss Phelps, for example, in this vote, string underlines in red Red means an error on your program. Work. We're on it. You got any helper over that? It's houses type. Spring isn't defined, right? We just need to be back on the end. The next thing that we want a program to do it, ask me. Use it. Bad night. Now, the way we do this is by interacting with consul console in the command prompt time. So to access to console console and got on. This brings up a whole looks of things you can do with the consul. In this case, we want to write a line Priceline commend in brackets poked whenever we want on the council . This case is name number. These has been asked what the name is. We need to pride away to get their ankle back into the system. Now we want to store what their name is in our variable name. So tough start by typing name equals. And then we want to import whatever the user types into the console. So again, with threats console this time we'll need a line. Now. Name will contain whatever the user has typed into the council. Next, we need to display hello such do this again told Dr Salon at this time it's in just talking out straight with Time Spice and then add on whatever the user said that their names now give this a run at what will be a problem. It disappears. Stray away. That's because visual basic will execute everything in this domain, but when it gets to the end of the program will close. So print it out. And then a moment later, the program replies to make it so easy can see what what's been written out to console the console. This will wait for the uses. Press enter before closing. Let's give this a try. Helen. Both pretence to close it. That's your first visual racing program. Visual studio provides a lot of helpful tools we can use to further understand program. One of these is the brake point. Not want to stop that program at some stage and see what's in a lot of Abel's. But great points. We can do this if we go over the line on a side street. Impressed on comes hold up right line, Great points. What So some rights in this video with blood how to create our first visual basic project within visual studio. Also love what a module is wet put code that we want to execute, Soothe program Start as well as what a variable is on the various different data types of variable base. Interview. Spread Divorces start to work with some basic console. Command Search is really like on Brighton line on exports with development features of visual studio Such a great point in real time syntax analysis. Next time we'll have a look of what's so routines are and how it can use functions within a program. 4. Comments: whenever you're coding visual basic, it's important that other developers can read and understand your code so helpless. There's something called comments. Common isn't actually run by the computer. It's just there to make the code more readable. In visual basic, you start coming with an apostrophe, and then you can take whatever you like after. That's so I've got loaded up our first program, one which asked your name and then from that Hello, your name that it's good practice to make sure the developers could understand that. So, for example, you might have a current after declaring this to tell someone else what it's for. Very May. Another useful comments is stopping code executed. So if you knew there was a problem in, for example, this line, you could stop executing by putting a comment. Now these two lines won't execute. We can see that as we run the program, and it just says, What is your name whenever you want toe just straight? That regard visual studio contains features easier to comment. Okay, so, for example, if you wanted to comment about these two lines, just press this button, and then if you wanted to oncoming them, you press the next. So that's a brief introduction about how to use comments in visual basic 5. Operators: in this video, take a quick look. Operators in visual Basic an operator is something that compared to values. So let's take a look at this with an example, kind of great. That might be something such as equal. So one equals one that would return true because one does indeed equal. We can shave that they sold right, which will write the result of this operation I read underneath so you can see the result way run that we can see that hasn't the return trade for one possible Now there are many different types of operators, and we can use the equals not equals, which is my look of a last time. I'm great. One does not equal one that's folks. We can also use the great that operator example. 10 is great. The want to return trip the last time operates Penans. Last one should return folks as well as the less than or equal to greater than or equal symbols. We can combine multiple operators by using Boolean operators, Bruin operators and Andi or or not. So let's take a look at no free right, not in front of our statement. What it will do is they'll evaluate this statement and then take the inverse off it. Let's use an easel. One equals one that one equals. Want you to return trade. It said that in verse It should get folks okay. And indeed, we have another 1,000,000,000 up his hand. For example. Have one performed on one. What? This one will do it. It will evaluate that it will evaluate that on only return trip. Both of these things evaluated, outstripped to In this case, this will evaluators true. This will evaluators falls. The whole statement will evaluate that again. I didn't need a house. He knows he used the upright or will return true if either one of these statements is true . So in our case, this one is true. This one is false. So overall, this will return. We can see We can use these kind of operators when we do it while loops If statements. So that statements on many of the things this video should have given you a basic introduction to operate visual 6. If Statements: in this video, we're going to take a look at statements. An if statement, the statement that will only excuse a certain conviction is true. Let's have a look at this. So first of all, I'm going to create a program where you enter a testicle and then it will tell you with that pass or fail based on SE Festival. Let's tell the use of water a day, I think, actually the variable to store that scoring. So let's call that school way to read in school, whatever you like. Council. But don't forget we're going to have to turn us into store it to me. Okay? And I'm way bottoms pauses in the in a statement. Since that's like this condition, Ben way ended and it's like chicken. And then our condition that lets him pass grade for this test was 75. So condition is school is greater 75. Then on a visual basic. Now the code that goes in here will only execute if scores great 75 right? They now we can have a look at what happens if we score isn't great. In 75 there were failed. So that's it. And then we're gonna want to changes to less than don't fall into the trap of just doing it last time. That way, if the user to go score off 75 program when you tell him it's given us a rock, protests fall. So that center one that fails from a failed well again and protest school now having to if statements is a very visual basic has an else functionality within this if they waking time else and then anything that says types hair will execute that condition isn't. Instead of having the second saying, we can just place this in the condition, get rid of this was still working exactly the same way demonstrate had Bean fail 80. So what if we wanted to have a special case where the user got a distinction? Maybe if they got at 100% when they got I tried another condition instead of typing else here, wouldn't type and then another condition school. Now, this isn't gonna work, because if score is greater than 75 they score of 100 this is gonna execute straight away. But it's not gonna pay any attention to the people. So that's what we around so that our program works better. If scores 100 right? If it's no 100 but its grave in 75 then let's tell them about the past. If it's no 100 it's not great in the 75 then that's a tail. Let's give this a text. He's a distinction Now. There is another way to approach is without using statements. It's commonly used when you've got a lot of conditions. So maybe you're grading them a start you don't want to write out else. If score is great to that, seven or eight times get all the great for that. We use a select state use this way first type select and then the variable that we're going to be comparing. So in this case school select case depressed New line, little putting this loco slipping. Now this here is where we put our condition. So our first condition is one. Then you want elements of distinction. Now it can add another case. That case is that it is great Center five. Then let's tell him it's a past, and then NPL happens within it, being a little being great. Then we need to tell you that everything. Let's check this. What? So Ryan text for Haiti That's test for off 10. That's a quick introduction to select statements on if statements in visual basic. 7. Activity 1: So at this point in the series, you should have a good, basic understanding of visual, basic and visual shooting. Let's now put this to the test with coding challenge. So the program that I want you to make his next the application actually input to numbers. Let's with 10 20 for example, after you input the two numbers, it would tell you which of them is larger. So in this case, twenties, larger intensive told us the second number is larger and then tell you some of the two numbers. Then ask you if you want to go again. If you press yes, program should repeat, so let's try. This time you go around 2010 tells the first number is larger. And if we put two numbers, which are equal to the 11 it tells us the numbers are equal on every time, giving some two numbers. Now when you press no, the application should close. If you feel confident doing this already, then go for it. The rest is video. Provide some basic tips and tricks for how to get started. The rest of this video, right with a few helpful resource, is if you're struggling with how to complete activity. First of all, let's have a look at the basic process that our program needs to go through to complete. Represent this as a flow chart so you can see we start overhead. We need to import to numbers and then decide which number is bigger. And then I found a message based on the result of that comparison. And then after that, they must walk the out of that comparison out. So and then ask use if they want to repeat. And if they do, we will be program. If no way, let's take a look at each of these steps bit by bit. The first thing that you might want to code is Luke. If you're struggling with house remember loops, take a look at our video lecture on loops in that we come into the three different types of loops, try and decide which was more appropriate for this situation and give ago. The next thing your program will have to do is take two numbers as an import. If you can't remember how to do this, take a look of that first lecture, an introduction to visual basic and also be especially careful about data types. Are you going? If you're going to be a string of an interview, how is it gonna be input to the system? We need to do any conversions. The next part of processes the comparison between the two numbers users in there to video elections which might be used Teoh one on if statements and the one on operators take a look at those If you stuck section and then finally we're gonna want to output sub recovered a bit. This in the introduction to visual basic video. Don't get carefully. Consider your dates type. And also remember that your grand have combined both the string saying the summits on the variable which will be an interesting off the actual. So remember how to do it. And if you can't remember, go back to the old video, make sure all your code is commented so that other developers could read it and understand that if you can't remember how to comment in visual basic ever I can have a look at the comments. Video lecture. Finally remember, there's more than one solutions. If your solution doesn't exactly much my solution, don't worry about it as long as it works, and it's commented that it's all good. So now poses colts and go and have a go great in this program. The next video. We'll walk through how I created a solution to this problem. 8. Activity 1 Solution: Now that you've had to go itself in that coding problem, let's have a look at how I chose to sell. Remember, this isn't the absolute definite solution. And if yours works and that's great, let's get right into it. So, first of all, I've added a little comment up here. To explain to a little was the purpose of this program. It's firms take two numbers, an important print with Allessandro. Great, too each other and then print out. So set in my main to routine. The first have done is I've declared a variable, which holds whether the program is running or not. This allowing me to then create do wildly at Luke every time the program was running. And then at the end of the loop, I date the ruling variable. If the user says they want toe, keep growing moronic or not. So the first thing that Luke does is it disclosed to more variables this time as an interview, the first number on second. We then use a console that right line to tell these what's going on to ask them to import first number on, then a re line to actually put that number into the very now something that might put you out here is having to convert this console. Don't read line, which returns a string into the interview that we want to that variable today. Of course, we do that with the keyword with brackets around my console. Don't worry. This is an just copy and paste and accept announced a second number number two before moving on to the comparison station. This is where it compares to see which number is bigger and then output appropriate response. So the first thing it checks for is if the numbers are equal and if it if they are, then right out these numbers are equal. Then it used an elf else. If to check. If number one is bigger than number two, what's an appropriate response? And then we used the else keyword to check for anything else, which would be that Number two is great to the number one. I would point out that response that the next thing wanted a program to do with print up some of the two numbers eso. First off, we declare a variable as an integer to hold the sum of the two numbers they were actually worked out by doing some equals noble one plus number take and then we do it comes hold up right line to print out some of the two numbers equals and then also. But don't forget, we had to convert this to a string to make sure that we could join up with this. Others drink on. The last thing that we want to do was ask the use if they want to repeat the process. So again, I wrote something out. You want to do this again? Yes or no? Declared a variable to hold their response. Read that responses from the console on. Then if their response was no, I said the running variable from a pair to folks. So when this looped around, running was no longer tree, so it dropped out on the program. Hold it. The code for this is a well if you download. If you want to have a look at it, well done. If you got a working solution by no means that is this the absolutely correct solution, so fuels work just as well, then that's brilliant. Now let's move on and learn more stuff in visual. Basic 9. Subroutines and Functions: in this video, we're gonna take a lot that's so routines on functions. Now, subroutines and functions are blocks of code which perform a particular task. This task is one that might have to be done again and again. And you don't want toe right out the same code again against my code in eight. So fruity eso this video, we're going to make a little program that takes a simple deep with on the hunt off a rectangle on will tell you it's area and we're gonna do this using subroutines. Start with on then using functions. So just staff. I'm gonna create a new console. Okay, on The first thing we're gonna do is we're going to create a new subroutine to calculate the area of a rectangle given a wit under height, a new subroutine on in visual basic. We used the key word. So as we've seen before a pair with we don't need to talk to the name of us of routine, so I'm gonna get it right area than in brackets. Any imports that we want to This so pretty. So I'm gonna want to import, um, and if I get to the end of it. Presento in that And so for me that now we don't want people to be able to pass in. Anything other than numbers has a width and height. So to make sure that's the case into your after this makes sure that width and height will always be a number. So we're not gonna run into any problems like Iran. So maybe take a moment now to cause this video to see if you can work out for yourself What we should write in the calculate areas. Okay, welcome back. Because the video the way that I'm going to go about this is our goats, Claire. Very local area. I'm then going to set area people to the with hunt, and then I'm going to console right Flying. Yeah, is I don't see any area that now this line head is going to run into a problem when we run because this here is a string that there is an insurgent Visual racing doesn't know how to add a strength and an incident. So we're gonna have to convert this into a strength. We do that. I'm doing it. New line just said that courses it when we get that yet? So now, in my main subroutine, I'm just gonna test this out. See if it works the way you court is, you type its name. So in this area, and then in brackets, you put your So let's get really 10 by 20 rectangle. Now we will mess. Let's see what it does. Okay, So his work is giving me The area is 200 backwards from 20 times. So we know that our subroutines working Now let's work on this. Remain so that we can get the user input. Their own values way we're gonna do that is very similar to in the previous year. Wait, I'm going to class very and then under head. I'm gonna ask the user for input right blind, and then I'm going to read that contains the wit. Very now, a problem that will remain to here is that the console the read line will return a string will return what they times. Why wait? There's an interview. So we're going to have to convert this into an industry before it could be stored it. And to do that, we surrounded with from the brackets that will convert what and using these brackets into an insurgent on that story and with his commanders to copy and paste, it's that same for okay, So when the computer gets to this point in the program will have the enters with on the entered height, variable width and height, respectively. We now want to call it calculates areas of routine to calculate the area. Oh, wait assessed and see if you work. Okay, so I'm gonna away all too my height for or expected to come out with an area of four times . Two, that's asked. So that's all well and good, but that's using a superteam. Now let's try and do this using a function. The difference between a function subroutine is that while a subroutine will just execute the code, a function will execute code and then return a value at the end of it. So this is perfect for what was about. So instead of the calculate area so routine being responsible for writing out the console, let's make it pass back the area to the main part of program, and then we could do whatever we want to in that in this case will right out to the way you return a value from within a function You think key would then whatever value you want to return in this case area now, visual basic still thinks that this is a subroutine. So it's furnace and error that to fix up, we need to change this into a function on the way we do that just so, into a function starts a nexus. That visual studio changed it down here as well. Now the code is gonna get to this point. Get to this point on, then it's gonna jump back to where we called it. So we this is in effect, is going to become area. We want Teoh Store that somewhere and variable. Yeah. Then we can set area equal to the result of calling this function. Now we've got the area in a variable waken Just steal this on user, right? Comes with a right like the area is plus our area from up here. A reliable man. Let's test that, See if it works people under these, it does so in this video. We've looked at subroutines and functions the differences between them and also how it can implement them in visual basic. The next video we'll take a look at the two ways that we capacity parameters into subroutines and functions 10. Variables by Reference and by Value: the last time we left off with this program. Which capital is the area of a rectangle given a whit Sunday heights, Putting two unfortunate will output the area as a did. This demonstrates of routines on functions. This time we'll take a closer look, a passing in the parameters so we can see here that we're passing in. Whatever the uses imported as now, they're ready to waste passing granted so routine by value or by reference the difference from too subtle but crucial to your understanding of visual basic. By default, he's passed by volume that is equivalent asked by while in front eat to the parameters. What was means is that save these reported six. The number six is copied over with. Wait becomes six, that's what. Well, good at one is by difference. Now what by reference does is instead of putting that number six over, it passes over variable that that was used when told function. So it passes over that very what sort of a copy that variable? That means whatever changes we make toe width within the celebrity also effect with yeah, now we can demonstrate that that put him back. Teoh five on in this function. Let's for some reason I want to wait do that way, using great points we can see exactly. Program is free passage at 24 See that with his take and then one is added to it and it becomes three on. We followed through. Go back to our original program with pay. It is still take. Hasn't had that one, however, now changes. Five. We rode through program again. Did you see that? It is. It's now three. Get back up. The original code with has been changed to three. It's possible use for this will be passing back more than one value from a function. So in this video, with two ways you can pass a variable until 17 0 function by value on Bayrak. We've also looked at the way he would implement that visual basic raising keywords Bayrak on by 11. Loops: so in this video will be taken. Look at how we can use loops with visual basic. Now, Loop is just a piece of code to repeat over and over again, either forever or until so in case his Mets let's jump right in with the new council called The first type of you could do is an infinitely This will just look forever until you manually killed program to do one of these type. Okay, then enter and see visual. She knows auto actually point down there anything between these really forever. So, for example, let's put a Dr Klein thanks That then, eh consoled up we'd line. That would just make it said that it causes and wait for the user to press enter if we give this around. See, this is a loop, President. This is a week carry on going until you manually. That's another type of leap. Is the wild like this will keep anything every time That statement a shame to trade. For example, let's make a program that will run until the user influence the word exit. So to do that first, we're gonna need a variable to contain what the user has responded with response string. Now, if you don't want to tell the user walk today, Black Press E Now we're gonna want to do our leap. So we look at this time I'm gonna add on the wild today on set back to when the response doesn't people. Now, the less than great to sign their means doesn't equal what exit. So whatever code that we put hair loot while the response isn't fax it, So Wow, Well, I think we want to read in What the users typing. We live. Okay, now let's give this again. So first we declare your variable to hold the users response, and we're telling them what program does. And then we'll lose pain while ever there explosives isn't exit. And in that live, we're gonna read in the user's response. Let's get this. You see, we can type whatever we want, I assume forever. Jim, pop that lead on hold program. Now what? If you want your program to lose a set number of times with 10 or 20 you'd achieve that with a four syntax of four. It's like that for counter equals. And then whatever you want to start, start with zero, and then whatever you want to end up, let's go press anti conceive visual. She is putting that next for us. Now this creates a new variable called Counter, and every time there's loot runs increments countered by war up until you encounter equals 10. Then jump demonstrate this by variable counter on, then head so it pulls so you can see the outflow. So what we expect to happen is for counter to be Derek. First of all prints out zero and that loops countries 123 all the way up to 10 and then it causes so we can read it until we get so we've outwitted zero through now. Sometimes you don't want county to be implemented by one. You might want to go in twos or threes or fours. For that, we use to step the number after step. It's however much the counter in credited each time. So let's go up to you. Say is outfitted with two times table for us. Another common thing you want to date is countdown, so to count, from 10 to 0, Lewites infected like that have a step off minus one. Since we go to 10 but also tracked 19876 all the way down here summarized in this video, we went about three types of like doing do while they're on the floor. 12. Activity 2: by now, you should have a good understanding of how to use the basic from sheltie of visual basic. Let's test that with a second coding exercise. Why I'd like you to produce is a Times Tables game. Let's take a look at an example. So this is one I've made it says Welcome to Timetables Game, and then it gives you three options. You can either play the game, few the scores or quit the game so the user interacts by typing something coastal. I'm pressing. Enter now. I've got an arrow check on there for any invalid responses, so I'll ask the user to slate choice again. They selected choice. They can't or enter any valid character. Let's have a look at playing the game so actually can see l picked two random numbers and then ask the user what those two random numbers mortified together in this case aren't since 48 So we got it right. The game keeps getting five times four is 20. As you're going along, it keeps a running score. So far, I've got two points. If I get this one wrong, that's the game over and it will tell me how many points I got. I got to write. I've got two point until which presented to return to the main. I can now use the second option to do my scores, and we can see that I just got if I was to play the game again, uh, to get a higher score three that would have paid that as well. And the third choice is, of course, to quit the game when these oppressive that the application should close. If you feel like you've got the skills, you need to go do this now, then go for it. If not the rest. This video find a basic outline of one way that you could approach this problem. The rest of this video provide a brief overview of one way you could approach. We can't like everyone type programs do with a simple flow chart. I've broken down the flow chart into three main subroutines we can implement, using a newfound knowledge on subroutines and functions. The algorithm starts overhead and then it displays the menu. This function would output the user's choice, and if they chose to play the game, we'll go to the play game that subroutine once they've completed that get back to start display that my new again. If these trees except it would end. And if the user choose to display the scores, it would call the display schools suffering team and then go back to the start to display the Let's have a closer look at the display menus. So in this subroutine, we first physically print out the menu to the screen. So auction by option something will have to consider. Here is how is the user going toe import that choice? Might it be numbers like I did? Or maybe it's a different approach you like to try. Is that gonna probably use it for their input and then check that they provided a valid in ? So in my program, I check that they haven't put something like five or hate or any other invite character. If they have, then I'd out for them in every message, asked Teoh type what they want to again. This will go on and on until they eventually provided a valid response. This was once would then be returned to the main sobriety. Now let's say they chose to play the game. Let's have a look into that briefing. First of all, it would pick to random numbers. Then it would ask the user for the product to those two random numbers on, then see if these have provided the correct response. If they had, we add one to the school and repeat the process. If not with output score, tell the game was over and then return at the you score to the main. So pretty if these air chose to miss that, display the scores. This a routine look, something like this. So without a head of state scores, and then loop for each score that we've got output score on that wants that Looper completed. Waive fees to press, enter and then return to the main menu where they could then choose exit if they wanted to . Something that you'll have to consider is how you're going to keep track of scores. What kind of data structure will use it? Could be an array. It could be a list. Have a look over previous videos to see what you think is the most appropriate structure I command. That you might find useful is that console Dark Clay Command. This command will clear all the output from the console. It's useful for Clement screen after the user's played game or after they feed some schools . Also, don't forget to comment your code. You can have it back over the comments. Video Electric. You have to do that. Finally, remember that there is no one solution. If you got a working solution that doesn't quite match mine, then good for you could look the next video in this series. We want explaining how I solve this particular problem. 13. Activity 2 Solution: it's a I've started out by splitting the problem into three separate sub routines. First of all, we got so routine Teoh display scores, second Garcia routine or, in this case, a function to play the game on and finally function to display the world. These will access from the main subroutine. So first, first off, we declare a new list of scores toe hold. The use of schools chose the laced because it could be expanded. AZM articles are added on. If we needed the ability to remove scores, that would be possible. A thing got variable toe hold. Whatever the uses chosen. Next up, we start a wild that limped every time the user chooses something over. Three. Now three of the auction to quit Tony The House chosen three. Drop out late on program. Within this late, we first display the welcome screen. We danced the functions by Welcome Tree, and this will return whatever the user has chosen that's stored in user choice. We now use a select case on the use of choice. I chose a select case because it's easy to add more caters to function in First case through, the user has chosen to play the game, so I declare a very well to hold that school and then set that score equal to whatever the play game for curator's. When this play game function is called, these plays the game and then it returns the skull starting score and then added to the list scores, which we declared after that's done, get the end of the loop. Users just want countries have displayed again. That's what they want to wait, get back to this like, if now they instead, they wanted to display this cause. Then we just called in this place course routine with the school's list. Now let's take a look at each of these routines in a bit more detail. First of routine that the usual come across is the display welcome screen. This displays almost of how to work, then asks the use of what they want to do, making sure that they put in a value response before I continue and then return to the response as an interview to Maine. First off, all these council lines up there are two display, many to screen, so first we clear screen. Then we write our little title card and then you line. That would give him three possible options. On the end of I think of two variables down one of the MR Store, whether uses provided a valid response. Initially, this is false because they used, hasn't had supplied any responses can be about next is extreme to store whatever uses type . Now I got a little loop settle, which will loot while ever they haven't responded in a violent way within Nutley will ask him to slice a choice. They will select choice, and then I got f statement. So if response anyone of possible options, it's 12 or three. That's fine. But if it isn't so, in this case, what response isn't one under response isn't so that then they'll get given an invalid response. Warning. I'm and that, of course, this lead to leap again. Asked upset. Another choice. If our they have provided a volatile and violent response will be set to treat. Jump out of this loop on will hit this return in response. Since we know that responses either 12 or three we can use into converted into an internship that and then return that to our main. So next routine I mentioned is the play game so pretty. So this has quite a few variables and stuff. At 1st 1 it's toe hold, whether the user still playing the game. So this will get set to folks when that they triggered game. The next one is the hole that score. We're starting now on zero. They got two numbers that we more flying together. So these we may be random numbers on the variable toe. Hold the product of those two numbers to check with the use. It has entered the right answer. Finally, we got a valuable to store whatever these responded. So again, we got no, they do wildly while I got the uses play. First off, we run the minds around number generators to make sure it generates a different random number each time. If you want more details on this, check out one of the previous videos where we use this. Uh, then we generate to run numbers between one and 10 so the random country would turn a value between zero and one by multiplying that by 10 we get value between zero. We don't work out what the correct answer would be story invariable. Next don't need to get the users response to a question. So we console. Ask them what is a number time. Another number being careful to convert these introduced to string before trying to combine with these other metro strength. We then read the answer from the console read month, making sure to convert that into an interview store. In answer Now, they got their response. We need to check whether it's right or not. So if answered calls problem, which is that correct? Then we know they got it right. Please tell them they got it right and I want to. That school Hatton program loops again. However, they haven't got it right. We tell him that that game's over something what's called big up when we tell them to press enter to return to the main menu. And then we had a little console. Don't read line in there so they have to press Enter. The program will continue playing two foes pat the late on return. Whatever score they got to the main final routine is that displaced calls rooty. This does what it says on the tin will display board scores from a given list of introduced that has passed into sobriety. First off, we create the console, then we write out recent scores is headed. Then we look over each score in the lest of scores. When we write that out, comes home. After that, we tell them 2% to return to menu and then use the read line trick to make present before the program carry on and come back into the. As I said before, this is just one possible solution. If you got the solution that works well done, well done. This will be available to download. If you want to have a look at it, see how it works. If not, then let's carry on with learning visual basic. 14. Arrays: So the last few videos with Vote a lot with variables. Now we're going to work with something called a raise. And Ray is simply a collection off variables. Let's take a closer look at this by jumping into a new console. So, Honore, very much so, how you declare a variable, right? And then you're raining my right. Prevent in brackets, you say how you want your right? If you want to store 10 items, you would pop nine. That might be confusing. What you put nine. Because arrays are indexed from zero I, you would have zero wanting. 3456789 10 items on. Then you can still, for example. So this will create 10 spaces in memory that we can store different values. Now to demonstrate use for this, Let's go back to our very first program where you inputted your name on their outwitted Hello? And then you right that program something like this. I'm so fine. So so right line. I really like to make it called the answer. Let's test that, See if it works. Oh, my God. Okay, so, using what we've learned about subroutines, let's first take this out, put it inside its subroutine. Well on, then called duty. Now, what if we didn't want it to say hello? Every single time that severity was called where she wanted to say different things. Now we're gonna have to store what we wanted to say. We'll get a store. Lots of different ways of saying we do this using it. Right. Let's create a function what we're going to say to you, Okay, Now, within this function, let's stop all the possible responses of tight. We're gonna start that handle, right? What? Just give it three things. Pull things now to put something into an array. You can do it one of two ways you can. I say would. All right. And then zero element. Ally. Oh, we can assign a value to the entire right. All right. What right? People's and then curly brackets. Each value separates black site in this example. Let's carried the first way. So hello in that we need one element. This second element, third element. Let's fully so with things to say. Okay, so let's pull to this functional on the break point so we could see exactly what. So when the program first starts. We're gonna call, I think. Thank you. Come down here like the right. And then let's get back it its head break point with homegrown word. Right? You can see it's got four on in here. We've got Hello. How you welcome on your working Well so far now. Wouldn't want this function to do is pick a random one of these and then return it into the welcome users. So taken random one leads with gonna need a random number next, and then we can sign around way right Number equals R and D random function that will return a number between 01 to make it between 03 times out by three. Now, this is gonna be a decimal to put viable 3.75 And because we told official basis, this is an end ships, they should always cut off anything after that. That's my point. Now, out of this function, the word all right position to summarize what you do is it should populate the array with possible options, the client rounding them, but then take a round number between 03 and then return the word at that random position. Let's test that sigh. This should become extremely one of these. That's right around that. Now, to test it in these wrongs. Done, let's suit comes. See how it okay so you can see it is picking. Run the ones. Now let's head back, get rule and then implement a new function instead of this instead of a way that I'm not work. So let's keep that sex room. What is your name? I love this time said No. Welcome again. Over the next. It's still saying, Well, every time to fix that, we need to randomize the way the visual basic to do that American spoke with this will make sure it takes a different random number. Each time we were on the program, give us again how you go on the next time we run it. Welcome. Okay, so that is a quick introduction to a race to summarize. We declare an array in the same way we declare a variable, except we aren't how long we want our right to be. We've also got to be careful to remember that arrays start at zero. If you declare it a three in there, then they'll actually before items in your right. We also learned how to generate a random number as well as how to return the value from right. Do that by typing the name with the right and then in brackets the position that we will. 15. Multi Dimensional Arrays: So in this series. So far, we've already looked a raise. If you remember what Ray was, an array was just a collection off variables. Now the rays we've looked at so far I've only been one dimensional. That is, when we were recording how long we wanted them to say we should put in, one would want to be 10 long. Today we'll have a look of two dimensional raise now to damage has raped where it's not only long, it's also why. So you might have a 10 by two array, which would contain 20 elements. Let's explores in more detail with a program, so I'll start up a new console application. A. Let's use a two dimensional array to store all the sales data for an employee working for a business. So you can imagine if we want our array to be. However, many employees there are white, and then, however many sales the employees a great talk, So you might have employed one, which has made three sales employees to which has made three Cell three. So the way we would do that in visual basic, there's just room to Clara Normal, right? So sames Yeah, not to be an inch now wants is doing normal, right? We'll just pop a number four to say three employees, two in there, Of course, remembering that arrays are zero index as they start from zero. And not to turn this into a three dimensional right. We just had a comma and then add another dimension. So this has now created a three by three great in memory, the weekend store, any data or any interviews that we wanted. So the way that we store something in this two by two grid is like that, right? Sales brackets and then the kind of coordinates of whatever we want. If you want the first employees first sale, would you zero common era. I usually equal sign and they would put for example, 10 in there, say that the zeroth employees zero sale had a value of £10 and now we could go down filling in oldest to I to write that I copied paces on my keyboard. So if you want to pause this video and copy that down, then go for it. Basically, what we've done that is this is the first employee head zeroth employees, and they've made three sales of £10.15 pounds, £5 on. There we go another employee there with more sales employees with more sales. Now that's a console doctor line. Hey, and then just break point on that so we can see how this looks in memory. So the computers don't lessons populate our to write to array, and we can hover over and see that three by three array we can hover over and we could see this got length of night. That makes sense because a three by three grid would have nine boxes in it. And then we go in. We can see all the different coordinates in our great 00 10 01 15 that always just fine. Now let's work on application where we actually use this data. They say, For example, I wanted to calculate the average of all the employees sales. We're gonna have more than one average because we've got more than one and play. So let's solve this in a one dimensional right. What? Each element in the array represents that employees average. Let's pull that every we know because we've got three employees, it's gonna be three long. So to in that. And we also know that this is probably going to be a decimal point number. So let's start as a double now. What we're gonna have to do is taken average off values in this three by three. All right for that, we're gonna need to use loops because we know that there are always going to be threatening . We can just use a fallen for this. So next time four and then first we want to live over each employee, so I'll call this very long and starting at zero going. Take now for each employee wants it right over each sale that they made. So that's creating another, like for sale people's. We know that started there. Okay, so now we're going to it. Rate down the rows and then across the colors like So let's just test this by doing a console. That right line right line. We can access out sales data by talking sales, identify, and then we want whatever employees, And then what if it's saying wrong? And if we run that that we see that is printed out exactly why all the employees and all the different sales. Now it's uses takes its a couch like that average. So to calculate, on average, we're going to need a variable to keep a running total. So if we some if we focus on just one employee, some all their sales and then divided by the amount of sales are we'll get the average for the employees we commend. Store that in the averages array at that point for that person. So let's great unknown variable total, which will store total as we add up all the employees that's gonna be into, uh and then for each employee, we want to set total back to zero. So why not take into account? That's a total here and here, where we're looping through the employees sales goto together, all of the employees total, allowing it to use the most schools operate. What this does is it will take total and then just add on whatever we put after the operators in this case, I'm going to put sales on that. We want specific for you on a specific site, so they should adult all the sales for that employees. Now we can get rid of this council, right, And after we've added up all these different totals want divided by the number of sales that they had on the story back in this averages. All right, So I had to do Total Divided by three because we know that there are three sales. Said this should work out the average story in total. We then stroll that back in a averages right averages and then the position we want to store tap is given by which employees currently counting. Let's submission fully populated averages. Right now it's just right Quick routine. Teoh output that averages. All right, the console. So again, we're going to want toe loop over each employee pace flatly and then, yeah, coverage pounds as well as average ease for that. Not forgetting to convert too strict. Okay, let's give us a go on, see if it works. Andrea love. It has indeed worked. So what we do is we calculated the average for all of these sales on stored in that averages array access that averages array on printed it out to the screen with consul dot right life. This gives you a brief overview of how to use two dimensional raise how they differ from one dimensional rights and how it can transform a two dimensional in a one dimensional right in a case like that's why we wanted to have you on average. 16. Lists: we've only looked better. A raise in visual basic. Now take a look at similar structure laced. While supposed these structures are ways of collecting variables together, the way they work is finally different magic. Remember, Honore is a collection of variables that may be, for example, head along. You would have 10 different variables he could start. This is different to how list works, the less convey resized to fit as many elements as you want. Your start with an empty last elements. Remove elements as you are. Let's take a look at this with an example, so I don't want to create a program which will write a shopping list for the user. I can declare my list in a similar way. How we clarify typing then in the 19 Baruchel shopping list. But this time as Let's that in brackets entirely off you are meant whatever dates type we like less debate. In this case. I'll go with spring if you wanted to add an item to shop type shocking docked, and they would put a whole list of things that we can do with this list. In this case, we want to add something brackets with type of fighting that would like Toa. Let's maybe thanks. Now visual basic is for owners of Panera here saying that very well shopping list has been used before its assigned a value. So the way Lister declared is slightly different. How we declare a variable we need Teoh type in head Qiwei, before Lex is basically tells visual basic that we want, the less we want our list ready to be written. So now that we've done this at this point in the program, we should have a shopping list with one item it takes. So let's put a break point in there. See if that's the case. Hover shopping list way. See that got one item in that that is indeed eggs. Now it's working a program which asks the user for multiple things and then puts it in a less full. To do this, we're gonna want toe loop until the users run out of things to say, so it can use a wildly I do while and then whatever the uses said, That's cool. That is not on. Then so keywords the user. Can Saito exit here with press enter now? We haven't declared the response very well. So let's do that. And then in this performance, Lee, we're gonna want to tell the use of what's going on right? And so exit. Now, within this list, we're gonna want to update the response. Very pools. And then if the user hasn't type exit, we want to add to that shopping list, whatever they have time. So for that we're going to use. And if so, if statements were recovered in more detail in the likes of video, it's a type spot, and then we use that is not people to operate. That's it way. Want France to the shopping list? We could borrow flying from down instead of eggs. Wrong response. What's new? That break point that on. See if it works. It ends on some sort. Your shopping express exits and exit Brett. So because he was triggered this great point down here, if we cover over a shopping list, got eggs pop right on down milk in that now it's to a similar thing with a list of introducing. So I'm going to stop my program. Change that, and then let's do this instead of a shopping list. Let's do it as a list of scores that some students got in a test call. It course. And students schools exit to exit. Now, the only thing that could be issue down here is that we're tryingto add the string into a list of interviews. So see, if you remember how to turn this strength into an inter, Okay, if you didn't money to do that the correct answer board by typing in front. Okay, let's give this again. Say maybe after you've got 75 2030. Stop. Now you see that scores list at 75 2030. Now he can We've got this place we can do some operations on. So the person putting schools might want to know what the highest score. Boss. Let's try and quote with an algorithm to determine. First, we're gonna need a very to store the highest school school. That's gonna be initially we want this to equal the first item in the West weaken Type on some on any brackets. Sarah, this is how we access a specific element off. So if we want zero element type scores, the item and then in brackets is there. Okay, so now we've got our first item in the highest score. Babel. We're going to want to look through each of the items in the lace and see if it's higher or lower than what we've got in the highest score. It's high it that we can update highest score without new value. By the end of the loop, we should have the highest school in high school variable. So to live through each element, the less we can use the four each time said to use that type before. Let's call it element. This is a new very well. It'll be quite fully department that in last night, each time this loop loops element is going to be the first element in the second and third and fourth. So So we want to compare element with high. It's Scots can use a never save for that again element school. Then we want to update our high school without to the end of this liquid, have the highest score in the very high school. Let's print that out for the soul right school I waken see let's get this test and see if it works. Enter shooting scores 5 2030 Exit on way should come out with a variable with number 75 is our highest, which indeed that gives you a brief introduction to using voice in visual bites. 17. Custom Data Types: over the course of these videos, we've used a lot of data types of programs with strings introduced, doubles billions. But what if we wanted to create our own dates? That's what we'll be looking at in this video because, although introduces strings of good for story things like interviews and strength, what if you want to store information about something more at real world? What about something like on sales of employees on information about that? So, using that as an example, let's jump in and see how we can create our in data structures in visual basic. So the first thing we need to define our own data structure used the key word on. Then we type the name of our structures. In this clay case, I'm going to be modeling some sales employees, then a new line. I'm visual studio's also people in that end structure for us that no, in here goes a list of different variables that we want direct to represents an attributes this employees have, you know the strength way might have their sales, and now, from within our way could a classic new variable, uh, and using the as keyword, but instead of putting like string into your 1,000,000,000. We now use our previously defy structure and 48 now employees. One is a variable off type employees. This is somewhat less, however, where we have to include a new word in front of the dates time. Now that we've got a variable we can start to assign values to. So if you wanted to change the name of employees type warm docked and then here we can see a list of all the different. Actually, we've got We've got name and we've got saved. Three time dot name. We can change, too. We can also populate this sales variable. So let's great us Yes place. Thank you. Now you can add his sales data. Teoh this. Let's my list. God, £10 £15 And then we can put this my list in tow. Employees one structure. So one don't sales close my list. Now he's put break point in and see how that looks in memory. If we hover over employees, we can see these two attributes his name and sales, which is a list of two. Get further into sales and C 05 to 10 from the first item is 50. That's what Well, something we can also do with structure is defined out subroutines and functions within that structure. So, for example, if I wanted to calculate an average of all Bob Sables, we could do that by declaring a function within this structure. Hold that calculate. So using this function, we can write some code in here and then down here, our main program we call employees. I don't complete coverage, and that will return the value that we calculate in out front. So let's quickly wrap this functional. The first thing we need to do on calculating the average is have a variable toe, hold the running total and then at the end will divide that running total by the number of items in a average. So let's create that new variable. And then, for each sale, you sail and sail. We're going to want that equals, operates ahead on that at the end, would go towards returning the average. The average is going to be the total divided by sales don't. So that's the running total of all of its sales. On that is the number of sales so that would be returned down here. Then we can display that with unsold doc, right? Ah, now that's changes to some numbers. We can easily calculate the average in a head to check that it works. So 10 20 the average of that should be 50 templates. Twenties 30. Divide by two to get 50. Let's see if that works like a down here so we can see at what was before program closes. Okay said. That's what that's giving us 50. This has been a brief introduction on how to create your own data structures in visual basic. 18. Final Project: well done. You've watched all the videos in this video, Siri's and should now be much more confident using visual basic with visual studio. Now it's put those newfound skills to test with the summer activity. I'll give you a brief on why I want you to create, and then you go away and create and let's see what you can do. Let's say I'm a manager, a company which makes sales. Let's say car sales. And I need a system to manage all myself people and see how that before me. So within my system, I want to be able to add new employees on remove employees whenever I need to. A swell as import sales data for each Ryan, please finally run reports of age. My plays. This report should include things like average sales for an employee, largest of smaller cells for an employee, as well as overall reports such as the best performing sales person and total sales. As always, don't forget to comment. Your coach. You can have a look at the comments video lecture if you forgot how to do this. This is important so that other developers know exactly what's going on. Your coach if they needed to maintain it or support it in the future. Good. Look, let's see what you can make. 19. Next Steps: well done on completing this course on visual. Basic Hope you enjoyed your time. Have you blown along by now, You should have produced at employee management system my car sales business. So just take a look back over the functionality and see if it meets the original special and your new boys in basic room before he's really kind of reports that we wanted to run on system. If you can't then welder, that's an amazing job. It's not what's missing. You go back to what is my videos that maybe didn't pay much attention to see if he really nailed the final points again. Well done for picking up this new program. Langley Visual Basic on Visual Studio Not used that before keeping an eye out for the upcoming courses on visual basic, more advanced courses I see next time. Thanks a lot