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

Please support us!