21.08.2013 Views

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Branching 26<br />

The B = 2 assignment only occurs when value of variable A is greater than three. A<br />

variation of the If statement is the If/Else clause:<br />

If A > 3 Then<br />

B = 2<br />

Else<br />

B = 0<br />

End If<br />

In this example, the variable B is assigned the value of 2 when A is greater than 3,<br />

otherwise B is assigned the value of 0.<br />

For more complex statements, you can cascade the If statement, for example:<br />

If A = 0 Then<br />

B = 0<br />

ElseIf A < 3 Then<br />

B = 1<br />

Else<br />

B = 2<br />

End If<br />

If the value of variable A equals zero, B is assigned the value 0. If A is less than 3 (but not<br />

equal to zero), then B is assigned the value 1. In all other instances (that is, if A is greater<br />

than or equal to 3), B is assigned the value 2.<br />

Select. . . Case<br />

The Select...Case instruction is an alternative to the cascaded If statement and is used<br />

when you need to check a value against various conditions:<br />

Select Case DayOfWeek<br />

Case 1:<br />

NameOfWeekday = "Sunday"<br />

Case 2:<br />

NameOfWeekday = "Monday"<br />

Case 3:<br />

NameOfWeekday = "Tuesday"<br />

Case 4:<br />

NameOfWeekday = "Wednesday"<br />

Case 5:<br />

NameOfWeekday = "Thursday"<br />

Case 6:<br />

NameOfWeekday = "Friday"<br />

Case 7:<br />

NameOfWeekday = "Saturday"<br />

End Select

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!