API Basic With ko - LIHACHTETAN/ClassicUO-BadNewbie-BasicIDE GitHub Wiki
With / End With
ClassicUO โข Basic
With๋ ์ ์ฅํ ํ๋์ ๊ฐ์ฒด์ ๋ํ ์์ ์ ๋ฌถ์ต๋๋ค. ์ด๋ฆ ์์ ์ ์ ๊ทธ ๊ฐ์ฒด์ ๋ฉค๋ฒ๋ฅผ ๋ปํฉ๋๋ค. With UO์ With moduleName์ ์ด๋ฆ ๊ณต๊ฐ์ ๋ช ์์ ์ผ๋ก ์ ํํ๋ Basic ํ์ฅ ํ์์ ๋๋ค.
์ ํํ ๊ตฌ๋ฌธ
With objectExpression
.Method(arguments)
statements
End With
With UO
.Command(arguments)
End With
With moduleName
.field = expression
.Procedure(arguments)
End With
๋งค๊ฐ๋ณ์
objectExpression / UO / moduleNameโ ๋์์ ํ์์ด๋ฉฐ List(), Dictionary() ๊ฐ์ ๋ค์ดํฐ๋ธ ๊ฐ์ฒด, ๊ฐ์ฒด๋ฅผ ๊ฐ์ง ๋ณ์ ๋๋ ๊ฐ์ฒด๋ฅผ ๋ฐํํ๋ ํจ์์ ๋๋ค. ์์ ์ง์ ํ ๋ ํ ๋ฒ๋ง ํ๊ฐํ๋ฉฐ ๋ณธ๋ฌธ์ด ๋น์ด ์์ด๋ ํ๊ฐํฉ๋๋ค. ์ด ์์ง์์ ์ซ์, ๋ฌธ์์ด, ๋ฐฐ์ด, Unit์ ๊ฐ์ฒด ๋์์ด ์๋๋๋ค. ๊ฐ์ ์ด๋ฆ์ ์ง์ญ ๊ฐ์ฒด ๋ณ์๊ฐ ๋ชจ๋๋ณด๋ค ์ฐ์ ํฉ๋๋ค..Method(arguments) / .fieldโ ๊ฐ์ฒด ๋ฉ์๋๋ ๊ดํธ์ ํจ๊ป ์ฌ์ฉํฉ๋๋ค: .Add(value), .Item(index), .Count(). ์ธ์์ ๊ฒฐ๊ณผ๋ ๊ทธ๋๋ก์ด๋ฉฐ Basic.List/Basic.Dictionary๋ฅผ ์ฐธ๊ณ ํ์ธ์. ์์ ๊ฐ์ฒด ํ๋๋ ์์ฑ์ ์ฌ๊ธฐ์ ์ง์ํ์ง ์์ต๋๋ค. ๋ชจ๋์์๋ ์ ๊ทผ ๊ฐ๋ฅํ .field์ .Procedure(arguments)๋ฅผ ์ธ ์ ์์ผ๋ฉฐ Private ๊ท์น๋ ์ ์ฉ๋ฉ๋๋ค. With UO ์์ .Command(...)๋ UO.Command(...)์ ๋๋ค. ๋ฐ์์๋ ๊ฒ์ ๋ช ๋ น์ ๊ณ์ UO๊ฐ ํ์ํฉ๋๋ค.statements / End Withโ ๋ณธ๋ฌธ์ ๋น์ด ์๊ฑฐ๋ ํธ์ถ, ๋์ , ์กฐ๊ฑด ๋ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์ค์ฒฉ๋ ๋ฐ๋ณต๋ฌธ๊ณผ ๋ธ๋ก์ ํฌํจํ ์ ์์ต๋๋ค. End With๋ ํ์์ ๋๋ค. ๋ณธ๋ฌธ ๋ฐ์์๋ ์ ์ผ๋ก ์์ํ๋ ๋ฉค๋ฒ ์ด๋ฆ์ ์ธ ์ ์์ต๋๋ค. ๋ค๋ฅธ ๊ฐ์ฒด๋ ์ ์ฒด ์ด๋ฆ์ผ๋ก ์ ๊ทผํ ์ ์์ต๋๋ค.
๋ฐํ๊ฐ
With๋ ์์ฒด ๋ฐํ๊ฐ์ด ์๋ ์ ์ด ๋ธ๋ก์ ๋๋ค. ID, Boolean, ์ฑ๊ณต ์ฌ๋ถ๋ฅผ ๋ฐํํ์ง ์์ต๋๋ค. ํธ์ถํ ๋ฉ์๋๋ ๊ฐ๊ฐ์ ๋ฐํ ๊ท์น์ ์ ์งํฉ๋๋ค. ์์ ์ Return์ Main์์ Integer๋ฅผ ๋ช ์์ ์ผ๋ก ๋ฐํํ๋ฉฐ 127, 28, 72๋ ์์ ๊ณ์ฐ๊ฐ์ ๋๋ค.
๋์
- ์ค๋น ๋จ๊ณ์์ ๋ธ๋ก์ ๊ฒ์ฌํ๊ณ ์๋ ์ด๋ฆ์ ์ฐ๊ฒฐํฉ๋๋ค. ์ง์ ํ ๋ ์์ ํ๊ฐํ์ฌ ํ์ฌ ํธ์ถ์ ๊ฐ์ฒด ์ฐธ์กฐ๋ฅผ ์ ์ฅํฉ๋๋ค. ์๋ ๋ณ์์ ๋ค๋ฅธ ๊ฐ์ฒด๋ฅผ ๋์ ํด๋ ์ฐธ์กฐ๋ ๋ฐ๋์ง ์์ต๋๋ค. ๋จธ๋ฆฌ ๋ถ๋ถ์ผ๋ก ๋ค์ ์ง์ ํ๋ฉด ์ฌํ๊ฐํ๋ฉฐ ์ฌ๊ท ํธ์ถ์ ๊ฐ์์ ์ฐธ์กฐ๋ฅผ ๊ฐ์ง๋๋ค.
- ์์ชฝ With์ ๋จธ๋ฆฌ ์์ ๋ฐ๊นฅ ๋ฌธ๋งฅ์์ ํ๊ฐํฉ๋๋ค. ์์ชฝ ๋ณธ๋ฌธ์ ์ ์ ์์ชฝ ๊ฐ์ฒด๋ฅผ ๊ฐ๋ฆฌํค๋ฉฐ End With ๋ค์๋ ๋ฐ๊นฅ ๋ฌธ๋งฅ์ด ๋ณต์๋ฉ๋๋ค. Return, ๋ฐ๋ณต๋ฌธ ์ด๋, ๋ฐ๊นฅ์ผ๋ก ํฅํ๋ GoTo๋ ๊ด๋ จ Finally๋ฅผ ์คํํ ๋ค ๋ฒ์ด๋ ๋ฒ์๋ฅผ ์ ๊ฑฐํฉ๋๋ค. With ๋ณธ๋ฌธ ์์ผ๋ก ๋ฐ๋ก ์ด๋ํ๋ ๊ฒ์ ๊ธ์ง๋ฉ๋๋ค.
- ์๋ชป๋ ๋์์ด๋ ์ ์ ์๋ ๋ฉ์๋๋ false๊ฐ ์๋๋ผ ์ค๋ฅ๋ฅผ ๋ฐ์์ํต๋๋ค. Catch/On Error๋ก ์ฒ๋ฆฌํ ์ ์์ต๋๋ค. ๋์ ํ๊ฐ๊ฐ ์คํจํ๋ฉด On Error Resume Next๊ฐ ๋ธ๋ก ์ ์ฒด๋ฅผ ๊ฑด๋๋๋๋ค. With๋ ์์ฒด ๋ฐ๋ณต, ๋๊ธฐ, ์ค๋ ๋ ์์ฑ์ ํ์ง ์์ต๋๋ค. ์ผ์ ์ค์ง์ ์ ์ง ๊ฒ์ฌ๋ ์ ์ง๋ฉ๋๋ค. ์ฐ๊ฒฐ๋ ์ด๋ฆ์ ์ค๋น๋ ์คํฌ๋ฆฝํธ์ ํจ๊ป ์บ์๋๋ฉฐ ๋ฉ์๋๋ง๋ค ๋์ ์์ ๋ค์ ํ๊ฐํ์ง ์์ต๋๋ค.
์์
1. ํ ๋ฒ๋ง ํ๊ฐ
# Choose๋ values๋ฅผ ByVal, calls๋ฅผ ByRef๋ก ๋ฐ์ calls๋ฅผ 1๋ก ๋๋ฆฌ๊ณ ์๋ ๋ชฉ๋ก์ ๋ฐํํฉ๋๋ค. ์ค๊ฐ์ values์ ์ ๋ชฉ๋ก์ ๋์
ํด๋ ๋ .Add๋ ์ ์ฅํ ๋ชฉ๋ก์ 2์ 7์ ์ถ๊ฐํฉ๋๋ค. Item์ 0๊ณผ 1 ์ธ๋ฑ์ค๋ฅผ ์ฌ์ฉํฉ๋๋ค. Main์ 1*100+2*10+7=127์ ๋ฐํํฉ๋๋ค.
Option Explicit On
Function Choose(ByVal values, ByRef calls) As Object
calls += 1
Return values
End Function
Sub Main()
Dim calls=0
Dim values=List()
Dim original=values
With Choose(values, calls)
.Add(2)
values=List()
.Add(7)
End With
Return calls*100+original.Item(0)*10+original.Item(1)
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
Choose๋ values๋ฅผ ByVal, calls๋ฅผ ByRef๋ก ๋ฐ์ calls๋ฅผ 1๋ก ๋๋ฆฌ๊ณ ์๋ ๋ชฉ๋ก์ ๋ฐํํฉ๋๋ค. ์ค๊ฐ์ values์ ์ ๋ชฉ๋ก์ ๋์ ํด๋ ๋ .Add๋ ์ ์ฅํ ๋ชฉ๋ก์ 2์ 7์ ์ถ๊ฐํฉ๋๋ค. Item์ 0๊ณผ 1 ์ธ๋ฑ์ค๋ฅผ ์ฌ์ฉํฉ๋๋ค. Main์ 1100+210+7=127์ ๋ฐํํฉ๋๋ค.
2. ์ค์ฒฉ ๊ฐ์ฒด์ ๋ง๋ฌด๋ฆฌ
# groups๋ ๋ฌธ์์ด ํค "child"์ ๋ชฉ๋ก child๋ฅผ ์ ์ฅํฉ๋๋ค. .Item("child")๊ฐ ๋ฐ๊นฅ ์ฌ์ ์์ ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์ต๋๋ค. ์์ชฝ .Add(2)์ Finally์ .Add(7)์ด ๋ชฉ๋ก์ ๋ณ๊ฒฝํฉ๋๋ค. End With ๋ค์ .Set("result",8)์ ๋ค์ ์ฌ์ ์ ์ ์ฉ๋ฉ๋๋ค. Count()๋ 2, Item("result")๋ 8์ ๋ฐํํ๋ฏ๋ก Main์ 28์ ๋ฐํํฉ๋๋ค.
Option Explicit On
Sub Main()
Dim groups=Dictionary()
Dim child=List()
groups.Set("child", child)
With groups
With .Item("child")
Try
.Add(2)
Finally
.Add(7)
End Try
End With
.Set("result", 8)
End With
Return child.Count()*10+groups.Item("result")
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
groups๋ ๋ฌธ์์ด ํค "child"์ ๋ชฉ๋ก child๋ฅผ ์ ์ฅํฉ๋๋ค. .Item("child")๊ฐ ๋ฐ๊นฅ ์ฌ์ ์์ ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์ต๋๋ค. ์์ชฝ .Add(2)์ Finally์ .Add(7)์ด ๋ชฉ๋ก์ ๋ณ๊ฒฝํฉ๋๋ค. End With ๋ค์ .Set("result",8)์ ๋ค์ ์ฌ์ ์ ์ ์ฉ๋ฉ๋๋ค. Count()๋ 2, Item("result")๋ 8์ ๋ฐํํ๋ฏ๋ก Main์ 28์ ๋ฐํํฉ๋๋ค.
3. ๋ชจ๋๊ณผ UO
# With Tools๋ .total, .AddAmount, .CountItems๊ฐ ์ํ ๋ชจ๋์ ์ง์ ํฉ๋๋ค. total์ 4๋ก ์์ํ๊ณ AddAmount๊ฐ amount=3์ ByVal๋ก ๋ฐ์ 7์ด ๋ฉ๋๋ค. CountItems๋ ๋ ์์ ๋ฐฐ์ด์ ๋ฐ์ With UO๋ฅผ ํตํด UO.GetArrayLength(values)๋ฅผ ํธ์ถํ์ฌ 2๋ฅผ ์ป์ต๋๋ค. Main์ 7*10+2=72๋ฅผ ๊ณ์ฐํฉ๋๋ค. ๋ชจ๋ ์ ๊ทผ ๊ท์น์ ๊ทธ๋๋ก ์ ์ฉ๋ฉ๋๋ค.
Option Explicit On
Module Tools
Public Var total=0
Public Sub AddAmount(ByVal amount)
total += amount
End Sub
Public Function CountItems(ByVal values) As Integer
With UO
Return .GetArrayLength(values)
End With
End Function
End Module
Sub Main()
Dim values[1]
With Tools
.total=4
.AddAmount(3)
Return .total*10+.CountItems(values)
End With
End Sub
๋งค๊ฐ๋ณ์ ๋ฐ ์คํ ์ค๋ช :
With Tools๋ .total, .AddAmount, .CountItems๊ฐ ์ํ ๋ชจ๋์ ์ง์ ํฉ๋๋ค. total์ 4๋ก ์์ํ๊ณ AddAmount๊ฐ amount=3์ ByVal๋ก ๋ฐ์ 7์ด ๋ฉ๋๋ค. CountItems๋ ๋ ์์ ๋ฐฐ์ด์ ๋ฐ์ With UO๋ฅผ ํตํด UO.GetArrayLength(values)๋ฅผ ํธ์ถํ์ฌ 2๋ฅผ ์ป์ต๋๋ค. Main์ 7*10+2=72๋ฅผ ๊ณ์ฐํฉ๋๋ค. ๋ชจ๋ ์ ๊ทผ ๊ท์น์ ๊ทธ๋๋ก ์ ์ฉ๋ฉ๋๋ค.