Page 226 - Excel Data Analysis
P. 226

11 537547 Ch10.qxd  3/4/03  12:03 PM  Page 212







                     EXCEL DATA ANALYSIS






                  VALIDATE INPUT FROM A DIALOG BOX



                       alidation ensures that the information that you  validation code in that routine, you use a conditional
                       receive for analysis is accurate and of the correct  statement, such as an If Then statement, to check the
                  V form. You must validate the values specified for  properties of each control. This ensures that they have the
                  controls in a dialog box before passing the values back to  appropriate values. For example, to ensure that the user
                  your procedure for two major reasons: First, you ensure that  typed a string in the Name text field of the dialog box, you
                  the user specifies a value for a control. If the user forgets to  can add the statement If TextBox1.Text = " " Then
                  select a control value, you can remind him or her   to your procedure. This statement checks the Text
                  immediately. Second, which is probably the most important  property for the specified TextBox control and ensures that
                  reason, you ensure that errors do not occur in your code  it contains a value. If the property is empty (nothing is in it),
                  because the wrong type of data passed to a procedure.  your VBA code can call the MsgBox function to display a
                                                                      message telling the user to input a value.
                  You can create code that checks the user input for any
                  event that occurs on a UserForm. The easiest place to do so  You also use the VBA validation functions to verify that a
                  is prior to closing the dialog box. For example, if you have a  control contains the appropriate data type. For example, If
                  CommandButton control, such as an OK button, that passes  Not IsNumeric(TextBox1.Value) Then ensures that
                  the values to global variables and closes the dialog box, this  the user typed a number in a TextBox control.
                  is an ideal place to validate your data. When you place the





                   VALIDATE INPUT FROM A DIALOG BOX


























                  ⁄ On the UserForm,        ■ Typically, an OK       ■ The code window opens
                  double-click the control for   command button is a good   with the cursor at the
                  which you want to validate   location for validating data   beginning of the Click
                  the data values.          values.                  procedure for the selected
                                                                     control.
                   212
   221   222   223   224   225   226   227   228   229   230   231