8.1 Creating Multi-Factor Calculation Using Forms Part 2
8 hours 33 minutes
Okay, so this exercise are this example We're building form that will allow user to type.
They will have three fields for a B and H, and you will feel just two of them. You really leave the third blank.
You put the numbers which represent the lens offsides, whichever you want. They'd be Abie on or age
and ah, Then it will calculate the 3rd 1
it should avoid any errors or mistakes. And
ah, that's ah pretty much it.
ah, let's go to the form creation. So we have this.
There is a tool box and we have pretty much finished this form. It doesn't have to be any prettier. It can be
modified. You can you can add some some background. You can add pictures you can at whatever you want.
let's, uh, let's leave it like this because this is what we need
so far. And now we're going to create for codes that runs this form.
So it's ah,
save you code.
And now we see the cold for
He was a form,
it's nothing there because what we actually want
is to create cold
because whatever happens in this form will happen after you click on calculate button.
So we're going to click here your code, and we get this and he says, Private sub command button, one click
and, uh, here, we're going to create code for this.
with a look at the logic
first we have to check
if the numbers entered our numbers.
Second, we have to check if there are actually two fields
filled and not one or zero or three.
So we have to see if
empty or not empty.
And we also have to check give these are numbers and not something else.
based on rich fields, have bean
entered. So which wheels have numbers?
We're going to decide what is the third field field that we need to our textbooks that we need to fill with the result
and then to displayed so that it's clear that the result is there now,
my idea for this form is that result will be displayed within this form so we could use a message box and just put the result there.
But it would be nicer if the results would just pop up in the empty
textbooks or field.
let's, uh, let's start for from very beginning.
I'm not going to put any
Ah, numbers here in dimensions are dim. Statements.
Uh, I'm going to do that at the end, So I'll see what I will need off
are these numbers and then I'm just going toe
put the things at the end.
first of all, I would need some kind of counter
because I'm going to
check how many fields
to have numbers in it.
So I'm going to call it, see? And I say, OK, the beginning of this, it zero.
I'm going to check each field
if it's no Merrick or not. So I'm going to say
and then I'm going to use the function off. If you remember it from infra function is numeric
the value off the first textbooks is text
we're going to close the brackets
and if that is the case, then C equals C plus one.
So in that case we have,
we have added the count increased discounter by one.
Now let's ah, just copy Paste this
let's do it for textbooks to
and then let's do it for textbooks. Three.
So at this point,
we have created
that will tell us how many fields have been filled with numbers.
And, of course, now wait have done it. We have to
do dim see
so because it's not going to be any kind off,
Ah, decimal number is going to be just 123
this is enough. And so far we have
successfully started to do this. And we can test this by pressing by adding command line.
And this is what I suggest to you to do it in the beginning. So if you do something, just test your
and then see
and then this sub.
So let's save it
and let's close it.
And in next video,
you're going to see how we test it.
So we're going to create a link from this
form that we have just created