Chatmates
------------------------------------------------- Calling Event Procedures If you wish to perform a set of instructions in more than one location, you don’t have to duplicate the code. Write the instructions once, in an event procedure, and “call” the procedure from another procedure. When you call an event procedure, the entire procedure is executed and then execution returns to the statement following the call. The Call Statement (No Arguments) – General form [ Call ] ProcedureName | Notice that the keyword Call is optional and rarely used. The Call Statement – Examples Call cmdCalculate_Click cmdCalculate_Click ‘Equivalent to previous statement | In the programming example that follows, you will accumulate individual items for one customer. When that customer’s order is complete, you need to clear the entire order and begin an order for the next customer. Refer to the interface in Figure below; notice the two command buttons; Clear for Next Item and New Order. The command button for next item clears the text boxes on the screen. The command button for a new order must clear the screen text boxes and clear the subtotal fields. Rather than repeat the instruction to clear the individual screen text boxes, we can call the event procedure for cmdClear_Click from the ctmdNewOrder procedure. A form with command buttons that perform overlapping functions. The New Order button must do the same tasks as Clear for Next Item.
Private Sub cmdNewOrder_Click() ‘Clear the current item and the current order cmdClear_Click ‘Call the procedure for the click event of cmdClear . . . ‘Continue with statements to clear subtotals In the cmdNewOrder_Click() procedure, all the instructions in cmdClear_Click are executed. Then execution returns to the next statement following the call.