Equinox Online Help - Language Reference - A to Z
Block ... End Block |
|
---|---|
Applies to | |
Syntax | Block [LabelName]
[Local Variable Declarations]End Block [LabelName] Note that you can use EndBlock instead of End Block |
Action | [Statement] This construction defines the enclosed statements as an identifiable block. Another part of the method can refer to it using the block's name |
Scope | Usable anywhere |
Notes | Block statements provide an extremely simple and powerful way to control the flow of a method. You can make all other control-flow constructions using Block statements. There is no hidden test or loop. The argument LabelName defines the name of the block; you can then use LabelName to refer to the block, when required. Control passes through the Block statement, continues through the statements in the middle and passes through the End Block statement. If the Exit Block statement is encountered, control immediately passes to the line following End Block. If the Continue Block statement is encountered, then control passes back to the start of the block. Note that with both the Exit and Continue clauses, you may omit the keyword Block, if desired. You must still include LabelName, however. If you use this structure in conjunction with the If and Goto statements, you can construct complicated algorithms in a structured and well-documented manner. As with other control structures, you may nest Block statements. Note that you may create local variables at the beginning of a block, but you may only use them within the block itself. They may not share names with fields or variables in any other blocks within which they are contained (but they may have the same name as variables in unrelated blocks). |
Category | Flow Control |
See Also | BreakPressed, Continue, Execute, EnableInput, Exit, For...Next, Goto, If_Then, Repeat_Until, Return, Sleep, Subtable, Switch, While_EndWhile |
Example | This example validates a series of field values. Rather than give a lot of (possibly confusing) messages, one for each error, the validation is stopped as soon as one error is detected. Logical error The next example sets up three buttons marked A, B and C and then displays an Alert box containing a question and three possible answers. The user's answer is compared with the variable CorrectAnswer. The user is not allowed to press Escape; if that happens the question is repeated. BlockAlertButtons "A", "B", "C"end block Equinox Goto statements use named blocks as their destination point. Some authorities on programming style prohibit the use of Goto, but in certain cases, a clearer style can result. The next example shows how an insurance claim might be evaluated. Such systems have complicated inter-dependent conditions which must eventually lead to one of several possible actions. If ClaimType = "HOUSE" Then If TotalInsured < ClaimValue Then Goto HivalueClaim Else Goto HouseClaim End If Else If ClaimValue > 5000 Then Goto HivalueClaim Else Goto DefaultClaimProcedure End If Block HouseClaim ... | no more processing For this claim Exit Method End Block Block HivalueClaim ... End Block | "fall through" into the Default Procedure Block DefaultClaimProcedure ... Exit Method End BlockIn the final example, two Switch clauses have some common code. A block is used to avoid repetition. Switch VehicleTypecase "FOURWHEELDRIVE"end switch...case "JEEP" |