I want that when user press cancel button this valid event shouldn't fire.The easiest thing to do is to set the Cancel property of the cancel button to true. This means that pressing escape key and clicking the button are functionally equivalent. Then in your valid, you can put code like this:
IF LASTKEY() = 27
KEYBOARD '{MOUSE}'
ELSE
ENDIF