Thursday, February 4, 2010

How do you structure an 'If false Statement' In visual basic.?

Yeah. I just started V.B and I would like to make an if statement that relies on something being false, rather than ture. How do I structure this?How do you structure an 'If false Statement' In visual basic.?
If Form1.width = ';482'; Then


msgbox ';Form width is 482'; ,vbOkOnly, ';Yes!';


Else


msgbox ';Form width is not 482'; ,vbOkOnly, ';No...';


else


end ifHow do you structure an 'If false Statement' In visual basic.?
You can use the NOT modifier ... Not inverts a boolean to make in the opposite value.





For example TRUE = NOT ( FLASE)





You can use NOT anywhere you would use a Boolean data type





In an IF statement where you were testing for a true condition such as


(X%26lt;5) you can now check for the false condition NOT(X%26lt;5).





IF NOT(X%26lt;5) Then


'X is equal to or greater than 5


End if





Another technique is to expand the conditional statement in an IF statement to include an additional comparison to an expected boolean result.





(X%26lt;5) is a comparison of X to 5 using a less than sign. This comparison evaluates to a Tue/False result based on the value of X.


You can compare that result to either a True or False Boolean condition.





If (X%26lt;5) = False then





or





If (X%26lt;5) = True then
If Condition = False Then


'Do this


End If





More info on if else conditional statement, check out the link below.
Usually for true case:


If condition Then


statement


End If





for false case:


If Not condition Then


statement


End If
IF (SOMETHING IS NOT EQUAL TO 100)


=


OR


=


IF (SOMETHING NOT TRUE)


- - -


If [SOMETHING %26lt;%26gt; 100]


Your code here


Else


Your code Here


End If

No comments:

Post a Comment