William Rosener: Hello this is Dr. Bill, welcome back. In this video, you'll learn how to create a pity calculator using VB a Visual Basic for the applications and again will be using Microsoft Word.
William Rosener: Let's start by taking a look at what you learn how to create it and we'll go ahead and walk you through credit yourself here.
William Rosener: So I want to simply imagine you get this jar. This piggy bank and all it contains our pennies and you want to know if I take this amount
William Rosener: There's 274 pennies and if I hit calculate like to know how many dollars we could get. So I 274 pennies. I could get $2 two quarters two dimes and then they'd be for pennies leftover so we're going to display this information and then a string.
William Rosener: Kind of a concatenate all this information into one long string and then we'll get the clear button work as well.
William Rosener: Okay. All in the same area as you found a link to this video, you should also find this interface here. So let's save a little time, not having to drag out all the text boxes labels, etc. Let's start by taking a look
William Rosener: At what these things are called
William Rosener: Okay, so I've got txt so that's a text box.
William Rosener: This is LPL dollars. I'll be your quarters, dimes Nichols pennies. And down here is LBO answer and I'ma show you two different ways to do this. And maybe I'll do my about do
William Rosener: Up to guns and let you do the last couple there yourself though.
William Rosener: OK, so the very first step, there is
William Rosener: Actually like clicked on that are such a close that out. Double click on calculate again. And that's going to simply take me to. So this command button is called calculate
William Rosener: And when I click on it, it's going to execute the code between this private sub and inside the subverting here. OK. So the very first step I want to do is go ahead and I'm going to create a
William Rosener: variable called remainder
William Rosener: This is going to be a type integer. And as soon as you get to the point, but in this case is becoming a neat I empty, I can simply press the khaki to finish that off.
William Rosener: And I want to go ahead and make sure I get Option Explicit turn on this way. If I have any spelling mistakes. It's going to help solve this for me.
William Rosener: Okay so initially remainder is going to equal to the value in txt Kennedy's
William Rosener: So,
William Rosener: If I've got 274 here. I'm gonna assume initially. I've got 274 kind is my remainder and subtract the dollars. I'm a computer new remainder subtract the quarters computer new remainder, and so forth.
William Rosener: Okay, so the very first thing we want to do is compute the dollars.
William Rosener: And I can just simply take a remainder, and I'm going to put we're gonna have a little more work to do with this and divided by 100 something
William Rosener: To get dollars on the simply take the number of pennies. In this case, I'm about be using 274 divided by 100 again. And if we go ahead and run to a double click on one of these
William Rosener: Okay, if I now go ahead and put an upsell and we run it for 274 and I hit the calculate, I can see it's put in 2.7 $4 in there, but I just want to have it say the two. Well, how do we solve that we can just take the iron t the integer portion of that.
William Rosener: So I'm going to take, for example, 274 divided by hundred that's going to give me 2.74. I'm going to take just the energy portion to and place that in dollars. So now if I run that
William Rosener: I'm gonna get just the two. Okay, we now need to compute a new remainder
William Rosener: In remainder is going to be equal to what was in remainder
William Rosener: Minus
William Rosener: Dollars.
William Rosener: 100 may have put some numbers in here. So this makes sense. So let's imagine we got 274 I wanted to, I could put them kind of out here at the right. So I'm starting off with
William Rosener: I'm going to take to so it's going to put that value and remainder. So I'm going to take remainders 274 divided by 100 it's going to take the ninja portion that's going to give me $2 I'm now going to take what was in remainder. So in effect, I wanted to this would be
William Rosener: 274
William Rosener: Minus two times 100 so I'm going to take this gnosis is going to first of all with the parentheses here.
William Rosener: And I'm putting this but. So just so you kind of walk through here. So remainder initially was 274 somebody say 274 minus two times 100 and that's going to give me my in this case my new remainder would be 74. Okay. So, after having completed this line of now computed a new remainder
William Rosener: Okay, now what we need to do is with our remain in this case 74 cents. We're know how many quarters. Can we get
William Rosener: And I'm just going to do the exact same thing here. I'm gonna take remainder
William Rosener: This case divided by 25
William Rosener: And then I want to go ahead and compute a new remainder
William Rosener: Actually says quarters.
William Rosener: Yes, here.
William Rosener: In times 25
William Rosener: Okay, so I'm gonna first of all take out as many dollars as I can compute a new remainder with the new remainder. I'm divide that by 25 take the energy portion compute my quarters.
William Rosener: I'm not going to cook compute a new remainder. So I get to a dimes and they'll go and do that as well let you do the last two nickels and pennies there.
William Rosener: And this will be about 10
William Rosener: And I'm not gonna take this case dimes.
William Rosener: Hey, man. So now I've computed a new remainder some already to start working on Nichols. Let's go ahead and I run this just to make sure everything's working great here.
William Rosener: So I've got 274 I'm going to hit calculate
William Rosener: And sure enough, I would get to $2 two quarters and dimes. So if I change this to 275
William Rosener: Then I'm going to get $2 and we get three quarters and throw down. So everything looks like it's working perfectly right now. So I'm gonna let you work on these two bullets. Come on down here and start working on the string concatenation.
William Rosener: So I'm not going to come on down here and I'm going to say hello to the answer.
William Rosener: Is equal to
William Rosener: Say txt pennies concatenate it with
William Rosener: A nice can be traded for
William Rosener: A table. Let's just go ahead and run it.
William Rosener: So I'm gonna have this is a variable. So this is always going to be changing. But this is a static stretching. It's always going to remain the same pennies can be traded for something going to run this.
William Rosener: And I'm gonna get 275 pen aids can be traded for some, but again if I change this to some other value.
William Rosener: I'm not gonna say 274 pennies can be traded for then I want to take this information and display it as well.
William Rosener: OK. And I'm going to go ahead and again if you wanted to put this on one long string. And I'm going to do another concatenation. And I'm going to break it up. So I'm gonna put an underscore space before and after them. And I'm saying LB all dollars.
William Rosener: Needed with
William Rosener: Lawyers
William Rosener: And put a space. And now do we cannot stop at this point. Check it and that's why I would highly recommend that you do this, rather than trying to
William Rosener: Debug on long statements, much easier to kind of break this up, piece by piece. I got 274 pennies can be traded for $2 but we're good here so far.
William Rosener: It. I'm gonna go ahead and do another string concatenation. I'm gonna break this up but on the next line. Let's say LPL
William Rosener: Quarters
William Rosener: Let me go ahead and check this, and then I'll do it for the dimes.
William Rosener: For Pennies could trade for $2 two quarters.
William Rosener: string concatenation.
William Rosener: dimes.
William Rosener: Do. I'm gonna put a period here but you got it. Yeah, I'm gonna let you continue working with the nickels and pennies. But in my case I'm finished here. So I've got the underscore I'm continuing on the next slide. But now I'm finished here LPL times
William Rosener: So I'm gonna go ahead and run this.
William Rosener: And there we go. So let me go ahead and change this to 275
William Rosener: And I'll get to in a 75 pennies can be traded for $2 three quarters and zero times we came and again I'm gonna let you work with the nickels and pennies. Let's go ahead and get this a clear button to work and then we'll start on calculated
William Rosener: So I'm just going to set all of these
William Rosener: Dollars.
William Rosener: Quarters
William Rosener: So these are two different this is that text box at the top where the user can enter in the information this one it's going to be the bottom one, which is displaying the results. And then finally, there is LDL, sir.
William Rosener: And I think I've read those. All right, let me go ahead and check this out and hit the clear button. And sure enough, that's the Lena mom. Okay, now I'm gonna go ahead and show you another way to attack this problem.
William Rosener: Using the mod function there.
William Rosener: So I'm going to go ahead and start off here at the top. All of this is going to be the same here.
William Rosener: The first three lines there. I'm going to paste those
William Rosener: Somebody grab the information
William Rosener: From South declared a variable. I'm going to grab information from txt pennies placed in my variable. I'm going to divide that by hundred
William Rosener: Which in this case was turning 74 it's going to give me take the IoT portion which will be to place that in dollars. Now let's go ahead and take a look at the mod function. And let me just go ahead and tell you what, let's put this an answer to. So you can see
William Rosener: Just want to take
William Rosener: This product five mod
William Rosener: So this is going to do is I'm going to do a division and it's going to tell me the remainder. So five goes into five
William Rosener: One time, with no remainder. So when I typed in. When I press LBO answer. It's going to display a zero. So, but take a look at the calculate to put in a actually doesn't matter here on the top as far as but what I'm really looking at here was that zero
William Rosener: Okay, but what if I had put five months for this case for goes into five one time. There's remainder of one.
William Rosener: So now when I press on the design mode. Sure enough, it's been one. Let's do this one more time.
William Rosener: I'm going to take a five minute three so three goes into five one time and remainder of two
William Rosener: Okay.
William Rosener: Okay, so we're actually delete that.
William Rosener: Instead I'm gonna put the remainder
William Rosener: Is equal to
William Rosener: The remainder mod 100 so in this case.
William Rosener: Now, actually.
William Rosener: Let me rephrase that they're going to take yeah remainder mod 100 so that's going to tell me what the remainder is once I'm finished with that particular line there.
William Rosener: So,
William Rosener: If I took out if I did the mod A 274 I table this this to what we did earlier. So, question mark is equal to
William Rosener: 270 for Mon 100 and what's going to happen is it's going to take me 100 it's going to go there. Two times and there's going to be a remainder of 74 okay so hopefully that makes sense. Okay, so now we're gonna go ahead and take this information and more quarters.
William Rosener: Mom by 25
William Rosener: So I'm gonna let you do the last two
William Rosener: Okay and I'm just going to grab all of this information right here because I'm not going to have changed any of that. That's going to be the exactly Samsung simply take that information and paste it right here. So let's check this out. So now, whether I press on calculate one
William Rosener: Or
William Rosener: The other button.
William Rosener: Or calculate to actually getting the exact same answer. So in this case, I've got 274 pennies. I can get $2 two quarters two dimes and then I'm also displaying that in Lhasa. Tell you what, just like what 300 I can see, I'm going to get some nice. I'm going to get $3 000 if I put 375
William Rosener: I would be getting $3 three quarters and if I put on the one last time here 310
William Rosener: I would get $3 and one time. They're trying again what is taking a look. What was the maximum number of dollars. I can get for this and with remainder. What's the maximum of quarters, except for them.
William Rosener: And maybe take a look here at the code one last time. Again, we're in a VB Visual Basic for the applications. And we did this twice.
William Rosener: One time, the first time a little bit more involved. That was just simply doing multiplying the number of dollars times 100 doing the subtraction.
William Rosener: But the second time. In addition, new to the mod function which is going to tell us the remainder of a division operation. Okay, well hopefully on this video you learned
William Rosener: How to create a clear and again I'm what you do nickels and pennies and actually concatenate at all, but hopefully I get you started. Thanks.