+========================+ | Chapter 4 | |Decisions And Conditions| +========================+ 1. If statements ------------- ->If statement is the powerful asset which can be used to make decisions and to make decisions based on certain conditions. ->Syntax: If(condition) Then ........ ...(Action taken)..... End If ->Example: If curPRice>100 then MsgBox "Price exceeds" End If If ...Then..Else statements --------------------------- ->Here in an If statement,when the condition is true,only the Then clause is executed.When the condition is false,only the Else slause ,if present,is ececuted. ->Syntax: If(condition) Then ........ ...statements..... [ElseIf (condition) Then ........ ...statements.....] [Else statements] End If ->Note: A block If..Then..Else must always conclude with End If.Here Then ----- must appear on the smae line as the If with nothing following Then(except remark).End If and Else(if used) must appear alone on a line. The statements under the Then and Else clauses are indented for readability and clarity. ->Key note: The Keyword ElseIF is one word but End If are two words. --------- ->If statement works with six relational operators shown below. Symbol Relation Tested ------- --------------- > Greater Than < Less than = Equal to <> not equal to >= greater than or equal to <= less than or equal to ->Conditions to be tested can be formed with numeric variables and constants, string variables and constants,object properties,and arithmetic expressions. ->Note: Comparisons must be made of similiar types.i.e; string can be compared only to the other strings,and numeric values can be compared only to other other numeric values,etc. Comparing Strings ----------------- ->Here string varibales can be compared to other string variables or literals enclosed in quotation marks. ->Here the comparison begins with the left-most character and proceeds one character at a time from left to right. ->As soon as character in one string is not equal to the corresponding charcter in another string,the comparison is terminated,and the string with lower-ranking character is judged less than the other. ->The determination of which character is less than the another is based on the ASCII code. ---------- ->Shortcuts can be used when testing for True or False. Eg: If blnSuccessfulOperation =True Then. . . if equivalent to If blnSuccessfulOperation Then..... Boolean variables takes following values Value NAme ------ ----- 0 False -1 True +--------------------------------------------------------------------------+ |Important: While working with the Text Property of Text Box be careful.The| |========== Text Property behaves like a variant.That means when you use it| | as String ,it acts like a String;but if you use it like number,| | it acts like a number. | +--------------------------------------------------------------------------+ Examples: txtFirst.txt txtSecond.txt txtFirst.txt> Val(txtFirst.txt)> ------------ ------------- txtSecond.txt Val(txtSecond.txt) ------------- ------------------ 1 +1 True False 2 100 True False +100 -100 False True 0 (blank) True False Comparing Uppercase and LowerCase Characters -------------------------------------------- ->VB uses two built in functions UCase() and LCase() which returns the uppercase or lowercase equivalent of a string,respectively. ->Syntax: UCase(string) LCase(String) ->Examples: txtOne.Text UCase(txtOne.Text) LCase(txtOne.Text) =========== ================== ================== Robert Jones ROBERT JONES robert jones Hello HELLO hello