(KR) MIDAS Civil with VBA

(KR) MIDAS Civil with VBA

VBAλŠ” Excelλ₯Ό λ‹€λ£¨λŠ” μ‚¬μš©μžμ—κ²Œ κ°€μž₯ μœ μš©ν•˜κ³  접근이 μ‰¬μš΄ 개발툴둜, 이λ₯Ό μ΄μš©ν•˜μ—¬ MIDAS Civil APIλ₯Ό μ‚¬μš©ν•˜λŠ” 예제λ₯Ό μž‘μ„±ν•΄λ΄…λ‹ˆλ‹€. 이미 λ‹€μˆ˜μ˜ λ¬Έμ„œμ—μ„œ API λͺ…령어에 λŒ€ν•œ λ‚΄μš©μ„ μˆ˜λ‘ν•˜μ˜€μœΌλ―€λ‘œ, μ—¬κΈ°μ„œλŠ” VBAλ₯Ό λ‹€λ£¨λŠ” 것에 μ§‘μ€‘ν•˜λ„λ‘ ν•˜κ² μŠ΅λ‹ˆλ‹€.

Β 

Json 데이터 닀루기

VBAμ—μ„œ Json 데이터λ₯Ό μ†μ‰½κ²Œ 닀루기 μœ„ν•΄μ„œλŠ” Dictionary Class λ₯Ό μ΄μš©ν•˜λŠ”κ²Œ κ²½ν—˜μƒ μ’‹μŠ΅λ‹ˆλ‹€.

초창기 예제 μž‘μ„±μ‹œ String λ°μ΄ν„°λ‘œ μž‘μ„±ν•˜μ˜€μœΌλ‚˜, μ΄λŠ” Json Dataκ°€ 컀질수둝 μ‚¬μš©ν•˜κΈ° μ–΄λ ΅κ³  (Hell of Chr(34)), 특히 Get Methodλ₯Ό μ΄μš©ν•˜μ—¬ 뢈러온 데이터λ₯Ό 닀루기가 μ–΄λ ΅μŠ΅λ‹ˆλ‹€. ν•˜μ§€λ§Œ λ‹€ν–‰μŠ€λŸ½κ²Œ Dictionary Classλ₯Ό Json 포맷으둜 Converter ν•΄μ£ΌλŠ” Codeκ°€ μžˆμœΌλ―€λ‘œ, 이λ₯Ό μ‚¬μš©ν•˜λ©΄ λ”μš± 더 νŽΈν•˜κ²Œ μž‘μ„±μ΄ κ°€λŠ₯ν•©λ‹ˆλ‹€.

Β 

  • Dictionary Class

Dictionary ClassλŠ”, 메뉴->도ꡬ->μ°Έμ‘°-> Microsoft Scripting Runtime을 ν™œμ„±ν™”ν•˜μ—¬ μ‚¬μš©ν•©λ‹ˆλ‹€.

μ•„λž˜μ™€ 같이 ν™œμ„±ν™”ν•˜μ§€ μ•Šκ³  μ‚¬μš©ν•  수 μžˆμ§€λ§Œ, λΆˆνŽΈν•˜λ―€λ‘œ ν™œμ„±ν™”ν•˜κ³  μ‚¬μš©ν•˜μ‹œκΈΈ μΆ”μ²œλ“œλ¦½λ‹ˆλ‹€.

'ν™œμ„±ν™”ν•˜μ§€ μ•Šκ³  μ‚¬μš©ν•  μ‹œ μ„ μ–Έ 방법(late binding) Dim DicEx As Object 'Declare Set DicEx = CreateObject("Scripting.Dictionary") 'Create 'ν™œμ„±ν™” ν›„ μ„ μ–Έν•˜λŠ” 방법(early binding) Dim DicEx As Dictionary 'Declare Set DicEx = New Dictionary 'Create
VBA (Microsoft Scripting Runtime)

Β 

Dictionary ClassλŠ” λ‹€μŒκ³Ό 같은 섀정값을 κ°€μ§‘λ‹ˆλ‹€.

속성

  • Count : ν˜„μž¬ μ €μž₯된 개체의 갯수λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

  • Item(β€œKeyValue”) : μ§€μ •ν•œ ν‚€μ˜ Valueλ₯Ό λΆˆλŸ¬μ˜€κ±°λ‚˜, λŒ€μ²΄ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

  • Key(β€œKeyValue”) : μ§€μ •ν•œ ν‚€μ˜ Keyλ₯Ό λΆˆλŸ¬μ˜€κ±°λ‚˜, λŒ€μ²΄ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

  • CompareMode : Dictionary κ°œμ²΄μ—μ„œ λ¬Έμžμ—΄ ν‚€λ₯Ό λΉ„κ΅ν•˜λŠ” λͺ¨λ“œλ₯Ό μ„€μ •ν•˜μ—¬ λ°˜ν™˜ν•©λ‹ˆλ‹€.(Binary, text λͺ¨λ“œκ°€ μžˆμœΌλ‚˜, ꡳ이 λ³€κ²½ν•  ν•„μš”λŠ” μ—†μŠ΅λ‹ˆλ‹€.)

λ©”μ†Œλ“œ

  • Add : 킀와 값을 μΆ”κ°€ν•©λ‹ˆλ‹€. μ‘΄μž¬ν•˜λŠ” 킀이면 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

  • Remove : μ§€μ •ν•œ 킀와 ν• λ‹Ήλ˜μ–΄ μžˆλŠ” 값을 μ œκ±°ν•©λ‹ˆλ‹€. μ‘΄μž¬ν•˜μ§€ μ•ŠλŠ” 킀이면 였λ₯˜κ°€ λ°œμƒν•©λ‹ˆλ‹€.

  • RemoveAll : λͺ¨λ“  킀와 값을 μ œκ±°ν•©λ‹ˆλ‹€.

  • Exists : μ§€μ •ν•œ ν‚€κ°€ μ‘΄μž¬ν•˜λ©΄ Trueλ₯Ό λ°˜ν™˜ν•˜κ³ , μ•„λ‹ˆλ©΄ Falseλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€.

  • keys : λͺ¨λ“  킀듀을 λ°°μ—΄λ‘œ λ°˜ν™˜ν•©λ‹ˆλ‹€.

  • Items : λͺ¨λ“  값듀을 λ°°μ—΄λ‘œ λ°˜ν™˜ν•©λ‹ˆλ‹€.

Β 

  • JsonConvertor

Json 양식을 VBAμ—μ„œλŠ” 곡식 μ§€μ›ν•˜λŠ” 것이 μ—†μœΌλ―€λ‘œ, μ•„λž˜ 링크에 μžˆλŠ” JsonConvertorλ₯Ό μ΄μš©ν•©λ‹ˆλ‹€.

GitHub - VBA-tools/VBA-JSON: JSON conversion and parsing for VBA

JsonConverter

Β 

Dictionary μ‚¬μš© 예제

  • 예제1 : Dictionary Class의 기본적인 μ‚¬μš©λ°©λ²•μž…λ‹ˆλ‹€.

Example 1
Option Explicit Option Base 1 Private Sub DicExample() Dim i As Integer Dim varItm, varMItm, varMKey As Variant Dim lngCnt As Long Dim blnKey As Boolean Dim dicExm As Dictionary 'Key와 Valueλ₯Ό ν• λ‹Ήν•©λ‹ˆλ‹€. Set dicExm = New Dictionary dicExm.Add 1, "Apple" dicExm.Add 2, "Banana" dicExm.Add "3", "Cherry" 'Dicrionay Classλ₯Ό Json 포맷으둜 λ³€ν™˜ν•˜κ³  좜λ ₯ν•©λ‹ˆλ‹€. Debug.Print JsonConverter.ConvertToJson(dicExm) Debug.Print "==================================================" '객체의 갯수λ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€. lngCnt = dicExm.Count Debug.Print lngCnt Debug.Print "==================================================" 'νŠΉμ • keyλ₯Ό κ°€μ§€λŠ” valueλ₯Ό λ°˜ν™˜ν•©λ‹ˆλ‹€. varItm = dicExm.Item(1) Debug.Print varItm Debug.Print "==================================================" '킀값을 λͺ¨λ‘ λ³€κ²½ν•©λ‹ˆλ‹€. dicExm.Key(1) = 3 dicExm.Key("3") = 4 Debug.Print JsonConverter.ConvertToJson(dicExm) Debug.Print "==================================================" 'μ§€μ •ν•œ Key의 쑴재 유무λ₯Ό νŒŒμ•…ν•©λ‹ˆλ‹€. blnKey = dicExm.Exists(4) Debug.Print blnKey Debug.Print "==================================================" 'Keyλ₯Ό λ°°μ—΄λ‘œ λ°˜ν™˜ν•©λ‹ˆλ‹€. varMKey = dicExm.Keys For i = LBound(varMKey) To UBound(varMKey) Debug.Print varMKey(i) Next i Debug.Print "==================================================" 'Valueλ₯Ό λ°°μ—΄λ‘œ λ°˜ν™˜ν•©λ‹ˆλ‹€. varMItm = dicExm.Items For i = LBound(varMItm) To UBound(varMItm) Debug.Print varMItm(i) Next i Debug.Print "==================================================" 'λͺ¨λ“  Key와 Valueλ₯Ό μ‚­μ œν•©λ‹ˆλ‹€. dicExm.RemoveAll Debug.Print dicExm.Count Debug.Print "==================================================" End Sub

Β 

Β 

  • 예제2 : μ—¬λŸ¬λ‹¨κ³„μ˜ 깊이λ₯Ό κ°€μ§€λŠ” Dictionary Classλ₯Ό λ§Œλ“œλŠ” μ˜ˆμ œμž…λ‹ˆλ‹€.

VBAλŠ” DeepCopyλ₯Ό μ‹€ν–‰ν•˜λŠ” λͺ…λ Ήμ–΄κ°€ λ”°λ‘œ μ—†μŠ΅λ‹ˆλ‹€(μ œκ°€ μ•ŒκΈ°λ‘ ). λ”°λΌμ„œ μ•„λž˜ μ˜ˆμ œμ™€ 같이 DeepCopy ν˜•νƒœμ˜ Function을 μ΄μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€. ν˜Ήμ€ μ•„λž˜μ™€ 같이 λ§Œλ“€κ³  λ²„λ¦¬λŠ” 반볡 μž‘μ—…μ„ 톡해 λ³€μˆ˜μ˜ 개수λ₯Ό μ΅œμ†Œν™”ν•˜μ—¬ μž‘μ„±ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

'예λ₯Ό λ“€μ–΄ Set dic = new dictionary 'Create 'dic μƒμœ„ ν΄λž˜μŠ€μ— 등둝 Set dic = nothing 'Release 반볡

이에 λŒ€ν•œ λ‚΄μš©μ€ κΉŠμ€ 볡사 VS 얕은 볡사 (velog.io) 이걸 μ°Έμ‘°ν•˜μ‹œλ©΄ 이해가 λΉ λ₯΄μ‹€ κ²λ‹ˆλ‹€.

Β 

Example 2
Private Sub DicExample2() Dim i, j As Integer Dim dicSub2, dicSub1, dicMain As Dictionary '배열을 Value에 λ“±λ‘ν•©λ‹ˆλ‹€. Dim intItm(8) As Integer Set dicMain = New Dictionary For i = 1 To 8 intItm(i) = i Next i dicMain.Add "Integer", intItm Debug.Print JsonConverter.ConvertToJson(dicMain) Set dicMain = Nothing 'μ—¬λŸ¬λ‹¨κ³„μ˜ 깊이λ₯Ό κ°€μ§€λŠ” Dicionary ꡬ쑰 μ˜ˆμ œμž…λ‹ˆλ‹€ 'GRUPλ₯Ό 예제둜 λ‹€μŒ ꡬ쑰λ₯Ό κ°€μ§€λŠ” Dictionaryλ₯Ό λ§Œλ“€μ–΄ λ΄…λ‹ˆλ‹€ '"GRUP":{ ' "1":{ ' "NAME":"G1" ' "E_LIST":[1,2,3,4,5] ' }, ' "2":{ ' "NAME":"G2" ' "E_LIST":[6,7,8,9,10] ' } ' } Dim intElmList(5) As Integer Set dicSub1 = New Dictionary: Set dicMain = New Dictionary For i = 1 To 2 For j = 1 To 5 intElmList(j) = 5 * (i - 1) + j Next j Set dicSub2 = New Dictionary 'Setting dicSub2 as new dictonary dicSub2.Add "NAME", "G" & i dicSub2.Add "E_LIST", intElmList 'dicSub2.Add "E_LIST", Array(1, 2, 3, 4, 5) 'κ°„λ‹¨ν•œ λ°μ΄ν„°λŠ” Array ν•¨μˆ˜λ‘œ 각각 μ²˜λ¦¬ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. dicSub1.Add i, dicSub2 Set dicSub2 = Nothing 'Release dicsub2 Next i dicMain.Add "GRUP", dicSub1 Debug.Print JsonConverter.ConvertToJson(dicMain) Set dicSub1 = Nothing: Set dicMain = Nothing 'LCOM κ³Ό 같이 Dictionary ꡬ쑰λ₯Ό Array둜 κ°€μ§€λŠ” 것에 λŒ€ν•œ μ˜ˆμ œμž…λ‹ˆλ‹€. 'λ‹€μŒ ꡬ쑰λ₯Ό 예제둜 ν•œλ²ˆ μž‘μ„±ν•΄ λ³΄κ² μŠ΅λ‹ˆλ‹€. ' { ' "LCOM": { ' "1": { ' "NAME": "DC", ' "KIND": "GEN", ' "ACTIVE": "ACTIVE", ' "bES": false, ' "iTYPE": 0, ' "DESC": "", ' "iSERV_TYPE": 0, ' "nLCOMTYPE": 0, ' "nSEISTYPE": 0, ' "vCOMB": [ ' { ' "ANAL": "CS", ' "LCNAME": "Dead Load", ' "FACTOR": 1 ' } ' ] ' }, ' "2": { ' "NAME": "CR/SH", ' "KIND": "GEN", ' "ACTIVE": "ACTIVE", ' "bES": false, ' "iTYPE": 0, ' "DESC": "", ' "iSERV_TYPE": 0, ' "nLCOMTYPE": 0, ' "nSEISTYPE": 0, ' "vCOMB": [ ' { ' "ANAL": "CS", ' "LCNAME": "Creep Secondary", ' "FACTOR": 1 ' }, ' { ' "ANAL": "CS", ' "LCNAME": "Shrinkage Secondary", ' "FACTOR": 1 ' } ' ] ' } ' } Dim dicComb(), dicCmn As Dictionary Set dicCmn = New Dictionary Set dicSub1 = New Dictionary: Set dicMain = New Dictionary dicCmn.Add "NAME", "" dicCmn.Add "KIND", "GEN" dicCmn.Add "ACTIVE", "ACTIVE" dicCmn.Add "bES", False dicCmn.Add "iTYPE", 0 dicCmn.Add "DESC", "" dicCmn.Add "iSERV_TYPE", 0 dicCmn.Add "nLCOMTYPE", 0 dicCmn.Add "nSEISTYPE", 0 dicCmn.Add "vCOMB", "" dicSub1.Add 1, DeepCopy(dicCmn) 'for DeepCopy dicSub1.Add 2, DeepCopy(dicCmn) 'for DeepCopy ReDim dicComb(1) Set dicComb(1) = New Dictionary dicComb(1).Add "ANAL", "CS" dicComb(1).Add "LCNAME", "Dead Load" dicComb(1).Add "FACTOR", 1 dicSub1.Item(1)("NAME") = "DC" dicSub1.Item(1)("vCOMB") = dicComb ReDim dicComb(2) For i = 1 To 2: Set dicComb(i) = New Dictionary: Next i dicComb(1).Add "ANAL", "CS" dicComb(1).Add "LCNAME", "Creep Secondary" dicComb(1).Add "FACTOR", 1 dicComb(2).Add "ANAL", "CS" dicComb(2).Add "LCNAME", "Shrinkage Secondary" dicComb(2).Add "FACTOR", 1 dicSub1.Item(2)("NAME") = "CR/SH" dicSub1.Item(2)("vCOMB") = dicComb dicMain.Add "LCOM", dicSub1 Debug.Print JsonConverter.ConvertToJson(dicMain) End Sub Private Function DeepCopy(dic As Dictionary) As Dictionary Dim Key As Variant Set DeepCopy = Nothing Set DeepCopy = New Dictionary For Each Key In dic.Keys DeepCopy.Add Key, dic(Key) Next Key End Function

Β 

Β 

JsonConvertor 예제

  • JsonConvertorλ₯Ό λ‹€λ£¨λŠ” κ°„λ‹¨ν•œ μ˜ˆμ œμž…λ‹ˆλ‹€.

Β 

Private Sub JsonConverterEX() Dim Json As String Dim dicJson As Dictionary 'Json 포맷의 String Data μž‘μ„± Json = "{" & Chr(34) & "NODE" & Chr(34) & ":{" & Chr(34) & "1001" & Chr(34) & ":{" _ & Chr(34) & "X" & Chr(34) & ":1.1," & Chr(34) & "Y" & Chr(34) & ":2.2," & Chr(34) & "Z" & Chr(34) & ":3.3}}}" Debug.Print Json 'Json 포맷의 String Dataλ₯Ό Dictionary둜 λ³€ν™˜ Set dicJson = JsonConverter.ParseJson(Json) Debug.Print dicJson.Item("NODE")("1001")("X") Debug.Print dicJson.Item("NODE")("1001")("Y") Debug.Print dicJson.Item("NODE")("1001")("Z") dicJson.Item("NODE")("1001")("X") = 4.4 dicJson.Item("NODE")("1001")("Y") = 5.5 dicJson.Item("NODE")("1001")("Z") = 6.6 'Dictionay Dataλ₯Ό Json String λ°μ΄ν„°λ‘œ λ³€ν™˜ Dim dicTojson As String dicTojson = JsonConverter.ConvertToJson(dicJson) Debug.Print dicTojson End Sub

Β 


μΆ”κ°€

(1) Runtime error - Timeout

μ•„λž˜ μ½”λ“œλŠ” μœ„μ— μ˜ˆμ œμ—μ„œ ν™œμš©ν•œ HttpRequest Function μž…λ‹ˆλ‹€.

Function WebRequest(Method As String, Command As String, Body As String) As String Dim TCRequestItem As Object Dim URL As String Set TCRequestItem = CreateObject("WinHttp.WinHttpRequest.5.1") URL = "http://localhost:10024" URL = URL & Command TCRequestItem.Open Method, URL, False TCRequestItem.SetRequestHeader "Content-type", "application/json" TCRequestItem.Send Body WebRequest = TCRequestItem.ResponseText End Function

Β 

κ°„ν˜Ή, μ œν’ˆμœΌλ‘œλΆ€ν„° Responseλ₯Ό λ°›κΈ°κΉŒμ§€ μ‹œκ°„μ΄ μ§€μ—°λ˜μ–΄, μ•„λž˜μ™€ 같은 κ²½κ³ μ°½κ³Ό ν•¨κ»˜ VBA μž‘λ™μ΄ λ©ˆμΆ”λŠ” κ²½μš°κ°€ μžˆμŠ΅λ‹ˆλ‹€. (절점과 μš”μ†Œμˆ˜κ°€ λ§Žμ„ 경우 λ“±λ“±)

Β 

그럴 경우 μ•„λž˜μ™€ 같이 μ½”λ“œ ν•œ 쀄을 μ‚½μž…ν•΄μ£Όμ‹œλ©΄ λ©λ‹ˆλ‹€. λ‹¨μœ„λŠ” Milliseconds μž…λ‹ˆλ‹€.

Function WebRequest(Method As String, Command As String, Body As String) As String Dim TCRequestItem As Object Dim URL As String Set TCRequestItem = CreateObject("WinHttp.WinHttpRequest.5.1") 'SetTimeouts(resolveTimeout, ConnectTimeout, SendTimeout, ReceiveTimeout) TCRequestItem.SetTimeouts 60000, 60000, 60000, 60000 URL = "http://localhost:10024" URL = URL & Command TCRequestItem.Open Method, URL, False TCRequestItem.SetRequestHeader "Content-type", "application/json" TCRequestItem.Send Body WebRequest = TCRequestItem.ResponseText End Function

Β 

(2) float point error (λΆ€λ™μ†Œμˆ˜μ  μ—λŸ¬)

이 항은 μˆ˜μΉ˜ν•΄μ„μ— 잘 μ•Œλ €μ§„ μ—λŸ¬μΈ λΆ€λ™μ†Œμˆ˜μ  μ—λŸ¬λ₯Ό VBAμ—μ„œ μ–΄λ–»κ²Œ λ‹€λ£¨λŠ”μ§€μ— λŒ€ν•΄ μ„€λͺ…ν•΄λ΄…λ‹ˆλ‹€.

λΆ€λ™μ†Œμˆ˜μ μ˜ μ—λŸ¬λŠ” 컴퓨터가 λ°›μ•„λ“€μ΄λŠ” 숫자λ₯Ό μ²˜λ¦¬ν•˜λŠ” 방식에 μ˜ν•΄μ„œ μƒκΈ°λŠ” 걸둜 μ΄ν•΄ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

(관심이 μžˆμœΌμ‹  뢄은 Floating-point arithmetic - Wikipedia μ—¬κΈΈ μ°Έκ³ ν•΄λ³΄μ„Έμš”.)

Β 

예λ₯Ό λ“€μ–΄ λ‹€μŒκ³Ό 같은 μ½”λ“œλ₯Ό μ‹€ν–‰μ‹œμΌœ λ³΄κ² μŠ΅λ‹ˆλ‹€.

Option Explicit Sub Test() Dim i As Integer Dim sngVar As Single Dim dblVar As Double For i = 1 To 10000 sngVar = sngVar + 0.0001 Next i Debug.Print TypeName(sngVar) & " : " & sngVar For i = 1 To 10000 dblVar = dblVar + 0.0001 Next i Debug.Print TypeName(dblVar) & " : " & dblVar End Sub

0.0001λ₯Ό 만번 λ”ν–ˆλŠ”λ°, μ›ν–ˆλ˜ 결과인 1이 λ‚˜μ˜€μ§ˆ μ•ŠμŠ΅λ‹ˆλ‹€. κ²Œλ‹€κ°€ μžλ£Œν˜•μ— 따라 κ·Έ μ˜€μ°¨λ„ 차이가 μžˆμŠ΅λ‹ˆλ‹€. 이런 λ¬Έμ œλŠ” ν”„λ‘œκ·Έλž¨μ΄λ©΄ λͺ¨λ‘ κ°€μ§€κ³  μžˆλŠ” λ¬Έμ œμž…λ‹ˆλ‹€. μ•„λž˜λŠ” μ—‘μ…€ μ˜ˆμ œμž…λ‹ˆλ‹€. κ°„λ‹¨ν•œ μ—°μ‚°μž„μ—λ„ λΆˆκ΅¬ν•˜κ³  9번째 행은 μš°λ¦¬κ°€ μ›ν•˜λŠ” κ²°κ³Όλ₯Ό 보여주지 λͺ»ν•©λ‹ˆλ‹€.

이런 μ—λŸ¬λŠ” κ°„λ‹¨ν•˜κ²Œ 유효 자릿수λ₯Ό μ£ΌλŠ” λ°©μ‹μœΌλ‘œ ν•΄κ²°ν•  μˆ˜λ„ μžˆμ§€λ§Œ, μ‘°κΈˆλ„ 근본적인 해결방법이 μžˆλŠ” κ²½μš°κ°€ μžˆμŠ΅λ‹ˆλ‹€. λ°”λ‘œ μžλ£Œν˜•μ„ λ°”κΏ”μ£ΌλŠ” κ²λ‹ˆλ‹€.

Β 

VBAμ—μ„œ 이런 λ¬Έμ œμ— μ“Έ 수 μžˆλŠ” μžλ£Œν˜•μ€ λ°”λ‘œ Decimal μžλ£Œν˜•μž…λ‹ˆλ‹€.

μ•„λž˜μ™€ 같이 0.0001λ₯Ό Decimal μžλ£Œν˜•μœΌλ‘œ λ°”κΏ”μ£Όμ–΄ λ”ν•΄μ£Όκ±°λ‚˜, Decimal μžλ£Œν˜•μœΌλ‘œ μ„ μ–Έν•΄μ„œ μ“°λŠ” 방법 등이 μžˆμŠ΅λ‹ˆλ‹€.(Decimal 은 Variant둜 μ„ μ–Έν•©λ‹ˆλ‹€.)

Β 

Option Explicit Sub Test() Dim i As Integer Dim sngVar As Single Dim dblVar As Double Dim decVar1 As Variant Dim decVar2 As Variant For i = 1 To 10000 sngVar = sngVar + CDec(0.0001) Next i Debug.Print TypeName(sngVar) & " : " & sngVar For i = 1 To 10000 dblVar = dblVar + CDec(0.0001) Next i Debug.Print TypeName(dblVar) & " : " & dblVar For i = 1 To 10000 decVar1 = decVar1 + CDec(0.0001) Next i Debug.Print TypeName(decVar1) & " : " & dblVar For i = 1 To 10000 decVar2 = decVar2 + 0.0001 Next i Debug.Print TypeName(decVar2) & " : " & dblVar End Sub

Β