Wednesday, March 5, 2008

How to use IF Statement of VB?

_____________________________________________

How to use IF Statement of VB?

_____________________________________________

greeting = IIf(age <>

' One line doesn't require "End If"
If age <>Then greeting = "What's up?"
If age <>Then greeting = "What's up?" Else greeting = "Hello"

' Use : to put two commands on same line
If x <> 100 And y <>Then x *= 5 : y *= 2

' Preferred
If x <> 100 And y <>Then
x *= 5
y *= 2
End If

' To break up any long single line use _
If whenYouHaveAReally < longLine And _
itNeedsToBeBrokenInto2 > Lines Then _
UseTheUnderscore(charToBreakItUp)

'If x > 5 Then
x *= y
ElseIf x = 5 Then
x += y
ElseIf x <>Then
x -= y
Else
x /= y
End If

Select Case color ' Must be a primitive data type
Case "pink", "red"
r += 1
Case "blue"
b += 1
Case "green"
g += 1
Case Else
other += 1
End Select

____________________________________________________________________

Note:Applicable for .net also asp.net.
____________________________________________________________________

No comments: