Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Friday, May 27, 2011

VB-13 : Set Focus(If-Then-Elseif-Endif)


Elseif clause is a variation of IF..THEN.....ELSE statement.By using this , we can control program flow.

Here, let be a field in the table as "age". Let the value in age cannot be less than 10 and greater than 60.So the code do check the value in the text box control named text1 is can be placed in the lost focus event of the text1 control.

A)   Property :
Textbox


B)   Attaching Code to the Object :
Private Sub Text1_LostFocus()
If Val(Text1.Text) < 10 Then
MsgBox "age cannot be less than 10"
Text1.SetFocus
ElseIf Val(Text1.Text) > 60 Then
MsgBox "age cannot be greater than 60"
Text1.SetFocus
Else
MsgBox "age entered correctly"
End If
End Sub

You can add any number of ElseIF clauses as you need to provide alternative choices.A better way to choose between several alternatives is the Select Case statement as in example VB-14 : Making decision with Select Case


               VB-11 : Set Focus(If-Then-Endif)
               VB-12 : Set Focus(If-Then-Else-Endif)




=========================================================================
Back to Home   &  VB

No comments: