VISUAL BASIC TIP

Problem Code VBTPATX005

Description

ALTERNATE WAY OF CALLING EVENT PROCEDURES.

VB Version Compati"ility

This solution works in VB4,VB5,VB6 & VBA (Visual Basic For Application).

THEORY

COMMAND BUTTON is one of the key Custom control used to develop any visual basic application. Generaly code written on click() event of COMMAND BUTTON is relates to FORM. Same code can also be called from key shortcut or context menu. to achieve this most programmers write a procedure and call from various places. Some directoly call event procedure as sub procedures. e.g, code written on COMMAND BUTTON named "Cmd1" can be called as cmd1_click. There is one more method of calling COMMAND BUTTON click() event procedure and that is to use VALUE property.

VALUE property can have TRUE or FALSE value. if you set value property TRUE it will activate the click() event of COMMAND BUTTON.

TIP
  1. Start a new visual basic project.
  2. Add two COMMAND BUTTON on the FORM.
  3. Write following code on the click() event of first COMMAND BUTTON.
  4. Private Sub Command1_Click()
    msgbox "Hi How Are You"
    End Sub
  5. Write following code on the click() event of second COMMAND BUTTON.
  6. Private Sub Command2_Click()
    command1.value = true
    End Sub
  7. Run the project.
  8. Click First COMMAND BUTTON, you will see message box.
  9. Now click on the second COMMAND BUTTON you will see the message box.

--------------------X-X-X-X-X-X-X-X--------------------

SPECIAL NOTE :- This tip is tested thoroughly. Use this tip is your own risk. Visual Code is not responsible for any damage caused directly or indirectly.

BACK

1