Okay, guys, so now we're going to have an example for the input box. so we can write input box, what is your name, and that is the prompt argument. And we could put the title as name. And then the default value could be Please enter your name. So this is going to be our input box. So if we run that, you can see here we've got the default value as Please enter your name.
So we're using it to guide the user on what to enter. If we press OK, or press cancel, nothing's going to happen. So I press cancel, nothing happened. Presto, okay, nothing happened, because we still not set up the input box to capture the value that the user inputs. So in order to capture the value that the user inputs, you could either put the value in a cell so say, range a one equals whether user inputs for example, or you could put it in a variable. So this In your name as string, so we're gonna make it a string because the input box actually outputs values as a string.
So this is why we're gonna make the datatype of the variable to be a string. Now we're going to set that variable to be equal to the input box. So your name is equal to input box. And because the input box now is on the right hand side of an assignment operator of the equal sign, we will get an error this way. So we need to put its arguments between brackets. So you can see here now we've got a variable called your name, that whatever the user typed into the input box is going to go into the user name variable, and then we can have a message box, hello, and then a space and concatenate that on to your name.
Okay, so let's try the input box. So if you run that, what is your name? I'm going to enter my name for example. All men, and then click OK. So it's going to display a message Hello, abdomen. Now if we run it as well, and instead of pressing OK, we press Cancel.
Pressing cancel gives us a blank value or puts a blank value into the variable basically. So when you press cancel, we get just hello and blank because when you press cancel, you just get a blank value. Okay, so let's see some examples about dealing with the different scenarios for the user input. So for example, what if the user presses okay with a default value as Please enter your name. So we could have an if statement here, if your name is equal to please enter your name, then we will display a message box invalid value received Please enter your name. Now what if the user enters a blank value or presses cancel, so we could have elsif, your name is equal to blank, then message box name is mandatory, please enter your name.
Okay, so now when we receive an invalid value or a blank value from the user, we are prompting him to enter his name. However, if you run the macro this way, we're going to go through the if statement if the user does not give us a proper value, but then we're going to have the message box Hello, and the improper value, right? So we need to do something to redirect the user to go back and enter his name. So let's run it and see what happens first. So here it says, Please enter your name. So let's say I'm going to press cancel.
So this way, I've given a blank value. So you can see here now that there's a message box that says name is mandatory, please enter your name. So if you're pressing Okay, it's gonna say hello and a blank value, right, because we've got the message box being executed here just after the if statement. So we need something to adjust the flow. So we could have a go to statement. So go to start, for example.
And we'd have this go to statement here as well, okay, and then we'd have a starting point here, start. So this way, the user would be going back to the input box that prompts him to enter his name. So if you run that, and then we would not enter a proper value. So here, if we press OK, so this way we've entered Please enter your name, which is not a proper value. So it says your invalid value received Please enter your name. And then we go back to the input box that says What is your name?
So this way if I enter a proper value mining for example here and we press OK. would go to the Hello, message box. Okay, so this is one way of dealing with improper values or improper inputs that are given by the user. So, thank you very much guys for watching this video and I'll see you on the next one.