168 CHAPTER 6 (Submit web site) MAKING DECISIONS WITH CONDITIONAL
168 CHAPTER 6 MAKING DECISIONS WITH CONDITIONAL LOGIC The problem with the previous example is this: if the user selected the first RadioButton control, REALbasic is still required to process the second If Then block, even though it is not selected. Rather than creating multiple If Then blocks, as was done in the previous example, you can set things up to be more efficient using the Else statement to set up an If Then Else block as the following shows. If rbnYellow.Value = True Then Window1.BackColor = &cFFFF80 Else Window1.BackColor = &cC0C0C0 End If As you can see, this example is one line shorter than the previous example, yet it performs exactly the same thing, while simplifying the code so REALbasic only has to perform one conditional test. The If Then ElseIf Blocks REALbasic also provides you with the capability to set up If Then ElseIf blocks, which test for any number of possible conditions and execute the code statements associated with the first matching condition. For example, you could add an additional RadioButton control to the previous example, and then modify the code statements assigned to the PushButton control, as the following shows. If rbnYellow.Value = True Then Window1.BackColor = &cFFFF80 ElseIf rbnGrey.Value = True Then Window1.BackColor = &cC0C0C0 ElseIf rbnWhite.Value = True Then Window1.BackColor = &cFFFFFF End If In this example, three separate conditions are tested and, whichever one proves True, is executed, while the others are skipped. Nesting If Then Blocks REALbasic also enables you to embed, or nest, If Then blocks within one another. In doing so, you can create complex conditional tests that begin by testing for one condition, and then perform further testing when required, as the following example shows. If blnGameOver = True Then If intNoOfPoints <= 1000 Then MsgBox("Continue your training my young padewan learner.") End If
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.