|
||
---|---|---|
PowerPoint tips, hints and tutorials that will change your presentations for ever! | ||
Jigsaws |
Input Boxes Inputboxes are used to get information from the user. Here is a simple example:
It opens an InputBox with the heading "Type your name"and sets the variable strRespose to whatever the user types in. Then it gives a message using the data. This is fine and should never crash. It's important to know that the response is always a String not a number. If your code EXPECTS a number PowerPoint will usually do some background conversion and come up with a sensible answer. NOTE - "USUALLY". Look at this code:
Because you have declared iResponse as an Integer PowerPoint will convert the response to a whole number IF IT CAN. This is fine for 12 and 12.7 but what if the user types "12 years 5 Months"? Yep it crashes - there's no sensible way for a PC to convert a sentence to a number. ALWAYS set the response to a String type and it will never crash. Once you have the answer you can test it. NOTE There are other ways to fix this error but this is fairly easy.
This code takes the response as a String which will always work and then tests to see if it IsNumeric and only if it is uses the Integer variable. Note also the use of 'TEST as a comment. Comments begin with ' and show in GREEN. They just remind you what the code actually does. Comments never run as code they are ignored by PowerPoint vba.
Next Lesson If >> Then statements |
|
Articles on your favourite sport Free Microsoft PowerPoint Advice, help and tutorials, Template Links |