If...Then...Else Statement
์ง์ ํ ์กฐ๊ฑด์ด True์ผ ๊ฒฝ์ฐ์๋ง ์คํํ ํ๋ ์ด์์ ๋ฌธ ๋ธ๋ก์ ์ง์ ํฉ๋๋ค.
๊ตฌ๋ฌธ:
If condition=true Then Statement block [ElseIf condition=true Then] Statement block [Else] Statement block EndIf
Instead of Else If you can write ElseIf, instead of End If you can write EndIf.
๋งค๊ฐ ๋ณ์:
If...Then ๋ฌธ์ ์ง์ ํ ์กฐ๊ฑด์ ๋ฐ๋ผ ํ๋ก๊ทธ๋จ ๋ธ๋ก์ ์คํํฉ๋๋ค. LibreOffice Basic์ If ๋ฌธ์ ๋ง๋ ๊ฒฝ์ฐ ์กฐ๊ฑด์ ํ ์คํธํฉ๋๋ค. ์กฐ๊ฑด์ด True์ด๋ฉด ๋ค์ Else ๋๋ ElseIf ๋ฌธ๊น์ง์ ๋ชจ๋ ํ์ ๋ฌธ์ด ์คํ๋ฉ๋๋ค. ์กฐ๊ฑด์ด False์ด๊ณ ElseIf ๋ฌธ์ด ๋ค์ ์ฌ ๊ฒฝ์ฐ LibreOffice Basic์ ๋ค์ ์กฐ๊ฑด์ ํ ์คํธํ์ฌ ํด๋น ์กฐ๊ฑด์ด True์ด๋ฉด ํ์ ๋ฌธ์ ์คํํฉ๋๋ค. ํด๋น ์กฐ๊ฑด์ด False์ผ ๊ฒฝ์ฐ์๋ ๋ค์ ElseIf ๋๋ Else ๋ฌธ์์ ํ๋ก๊ทธ๋จ์ด ๊ณ์๋ฉ๋๋ค. Else ๋ค์ ์ค๋ ๋ฌธ์ ์ด์ ์ ํ ์คํธํ ๋ชจ๋ ์กฐ๊ฑด์ด True๊ฐ ์๋ ๊ฒฝ์ฐ์๋ง ์คํ๋ฉ๋๋ค. ๋ชจ๋ ์กฐ๊ฑด์ด ํ๊ฐ๋๊ณ ํด๋น ๋ฌธ์ด ์คํ๋ ํ EndIf ๋ค์ ์ค๋ ๋ฌธ์์ ํ๋ก๊ทธ๋จ์ด ๊ณ์๋ฉ๋๋ค.
์ฌ๋ฌ If...Then ๋ฌธ์ ์ค์ฒฉํ ์ ์์ต๋๋ค.
Else ๋ฐ ElseIf ๋ฌธ์ ์ ํ ์ฌํญ์ ๋๋ค.
GoTo ๋ฐ GoSub๋ฅผ ์ฌ์ฉํ์ฌ If...Then ๋ธ๋ก ๋ฐ์ผ๋ก ๋๊ฐ ์๋ ์์ง๋ง If...Then ๊ตฌ์กฐ ์์ผ๋ก ๋ค์ด์ฌ ์๋ ์์ต๋๋ค.
๋ค์์ ์ ํ์ ๋ง๋ฃ์ผ์ ์ ๋ ฅํ ๋ค์ ๋ง๋ฃ์ผ์ด ๊ฒฝ๊ณผํ๋์ง ํ์ธํ๋ ์์ ๋๋ค.
์:
Sub ExampleIfThenDate
Dim sDate As String
Dim sToday As String
sDate = InputBox("Enter the expiration date (MM.DD.YYYY)")
sDate = Right$(sDate, 4) + Mid$(sDate, 4, 2) + Left$(sDate, 2)
sToday = Date$
sToday = Right$(sToday, 4)+ Mid$(sToday, 4, 2) + Left$(sToday, 2)
If sDate < sToday Then
MsgBox "The expiration date has passed"
ElseIf sDate > sToday Then
MsgBox "The expiration date has not yet passed"
Else
MsgBox "The expiration date is today"
End If
End Sub