{
"Asset": {
"Quantity": 29, "Ticker": "395160" },
"Cash": {
"Amount": 3912649}
}
'' ODBC using Data Source Name
Dim connStr As String
connStr = "DSN=dsnOra;UID=HR;PASSWORD=1111;"
...
|
'' Direct connetion to Oracle ODBC
Dim connStr As String
connStr = ("DRIVER="Oracle in OraDb11g_home1;" & _
"SERVER=ORCL;" & _
"DBQ=ORCL;" & _
"Uid=HR;" & _
"Pwd=1111;" )
...
|
| 타임스탬프 | 금칙어 | 표준어 | 담당자성명 |
| 2018. 10. 24 오전 10:41:29 | stainless steel | 스테인리스강 | 최치원 |
| 2018. 11. 13 오전 9:58:14 | 스테인리스스틸연결유니언 | 스테인리스유니언 | 박나래 |
| 2018. 11. 13 오전 10:07:24 | 스테인리스스틸앵글밸브 | 스테인리스앵글밸브 | 박나래 |
| 2018-09-05 17:51:00 | 특수아크릴(인장강동 | 특수아크릴(인장강도 | 최치원 |
| 2018. 11. 13 오전 9:58:42 | 스테인리스스틸유니언 | 스테인리스유니언 | 박나래 |
| 2018. 11. 20 오후 5:39:45 | 알루미늄 - D.C | 알루미늄다이캐스팅 | 김치국 |
Function webservice()
''First, Add a reference to MSXML (Tools > references)
Dim req As Object
Dim sheetUrl As String
sheetUrl = "https://docs.google.com/spreadsheets/d/e/(Your-Google-Sheet-ID)/pub?gid=(Your-gid)&single=true&output=csv"
Set req = CreateObject("MSXML2.XMLHTTP")
With req
.Open "GET", sheetUrl, False
.Send
End With
Dim response As String
response = req.ResponseText
''Debug.Print response
Dim table() As String
table() = Split(response, vbCrLf)
Debug.Print LBound(table) & ":" & UBound(table) ''0~128..count=129
''
' Dim 타임스탬프, 금칙어, 표준어, 담당자 As String
' Dim row() As String
' For Each wordrow In table
' ''Debug.Print wordrow
' row() = Split(wordrow, ",")
' 타임스탬프 = row(0)
' 금칙어 = row(1)
' 표준어 = row(2)
' 담당자 = row(3)
' Next
Set req = Nothing
webservice = table
End Function
결과:Function SHA256(sIn As String, Optional bB64 As Boolean = 0) As String'prerequisite'Set a reference to mscorlib 4.0 64-bitDim oT As Object, oSHA256 As ObjectDim TextToHash() As Byte, bytes() As ByteSet oT = CreateObject("System.Text.UTF8Encoding")Set oSHA256 = CreateObject("System.Security.Cryptography.SHA256Managed")TextToHash = oT.GetBytes_4(sIn)bytes = oSHA256.ComputeHash_2((TextToHash))If bB64 = True ThenSHA256 = ConvToBase64String(bytes)ElseSHA256 = ConvToHexString(bytes)End IfSet oT = NothingSet oSHA256 = NothingEnd FunctionFunction ConvToHexString(vIn As Variant) As VariantDim oD As ObjectSet oD = CreateObject("MSXML2.DOMDocument")With oD.LoadXML "" .DocumentElement.DataType = "bin.Hex".DocumentElement.nodeTypedValue = vInEnd WithConvToHexString = Replace(oD.DocumentElement.Text, vbLf, "")Set oD = NothingEnd Function
Base64: MDkBFbBmlo/AYoaEwOl7KAUEnj5dfJ/+1pxVFjKkkuc=44 characters in lengthHex: 30390115b066968fc0628684c0e97b2805049e3e5d7c9ffed69c551632a492e764 characters in length
Dim appName As String
appName = Application.ActiveWorkbook.Name
Debug.Print appName ''VBA_dedicated.xlsx
Workbook Objects ''Workbook object
Dim wb As Workbook
Set wb = Workbooks.Open(appPath & "\" & "VBA_dedicated.xlsx") ''workbook.fullname
Worksheet Objects ''Worksheet object
Dim ws As Worksheet
Set ws = Worksheets(1)
ws.Visible = False
''Range
Dim rng As Range
Set rng = Worksheets("Sheet1").Range("A1:A4")
rng.Value = 5
Function getArea(Length As Double, Optional Width As Variant) Dim findArea As Double If IsMissing(Width) Then findArea = Length * Length ''Square Else findArea = Length * Width ''Area End If ''return: VBA has no return statement, instead using Function Name to return getArea = findArea End Function
Sub show_myArea() Dim 길이 As Double Dim 폭 As Double Dim 면적 As Double 길이 = 4 폭 = 5 ''Call function in sub procedure 면적 = getArea(길이, 폭) Debug.Print 면적 '' f(4,5) = 길이 * 폭 = 4 * 5 = 20 End Sub
' This line is comment.
' Written by : Author VBA Tutorial
REM 이 줄은 코멘트입니다. Rem 작성자 : VBA 강좌
Sub show_Message() '메세지박스 표시 ("Hello VBA.!") MsgBox "Hello VBA.!" End Sub
Sub show_Inputbox() '사용자 입력 박스로 입력을 받는다. Dim 가로 As Integer Dim 세로 As Integer Dim 면적 As Integer 가로 = InputBox("가로 입력 ", "숫자를 입력하시오") 세로 = Application.InputBox("세로 입력 ", "숫자를 입력/셀선택 하시오") 면적 = 가로 * 세로 MsgBox 면적 End Sub
Sub show_variables() ''변수(Variable) ''Type별 변수 정의 Dim var_bool As Boolean Dim var_byte As Byte Dim var_int As Integer Dim var_long As Long Dim var_single As Single Dim var_double As Double '' Dim var_string As String Dim var_date As Date Dim var_variant As Variant '' var_bool = False var_byte = 255 var_int = 32767 var_long = 2147483647# var_single = 3.402823E+38 var_double = 1.79769313486232E+307 var_string = "1 to 65,400 characters" var_date = DateValue("30 / 10 / 2020") var_object = "Some Object" var_variant = "Number or String" Debug.Print var_bool & vbCrLf & _ var_byte & vbCrLf & _ var_int & vbCrLf & _ var_long & vbCrLf & _ var_single & vbCrLf & _ var_double & vbCrLf & _ var_string & vbCrLf & _ var_date & vbCrLf & _ var_variant & vbCrLf End Sub
Const MyInteger As Integer = 24 Const 나의정수 As Integer = 24
| Operator | Description | Example |
| + | Adds the two operands | 10 + 5 will give 15 |
| - | Subtracts the second operand from the first | 10 - 5 will give -5 |
| * | Multiplies both the operands | 10 * 5 will give 50 |
| / | Divides the numerator by the denominator | 5 / 10 will give 2 |
| % | Modulus operator and the remainder after an integer division | 5 % 10 will give 0 |
| ^ | Exponentiation operator | 5 ^ 10 will give 100000 |
| = | Checks if the value of the two operands are equal or not. If yes, then the condition is true. | (10 = 20) is False. |
| <> | Checks if the value of the two operands are equal or not. If the values are not equal, then the condition is true. | (10 <> 20) is True. |
| > | Checks if the value of the left operand is greater than the value of the right operand. If yes, then the condition is true. | (10 > 20) is False. |
| < | Checks if the value of the left operand is less than the value of the right operand. If yes, then the condition is true. | (10 < 20) is True. |
| >= | Checks if the value of the left operand is greater than or equal to the value of the right operand. If yes, then the condition is true. | (10 >= 20) is False. |
| <= | Checks if the value of the left operand is less than or equal to the value of the right operand. If yes, then the condition is true. | (10 <= 20) is True. |
| AND | Called Logical AND operator. If both the conditions are True, then the Expression is true. | 10<>0 AND 0<>0 is False. |
| OR | Called Logical OR Operator. If any of the two conditions are True, then the condition is true. | 10<>0 OR 0<>0 is true. |
| NOT | Called Logical NOT Operator. Used to reverse the logical state of its operand. If a condition is true, then Logical NOT operator will make false. | NOT(10<>0 OR 0<>0) is false. |
| XOR | Called Logical Exclusion. It is the combination of NOT and OR Operator. If one, and only one, of the expressions evaluates to be True, the result is True. | (10<>0 XOR 0<>0) is true. |
| & | Concatenates two Values | "Microsoft" & "VBA" will give MicrosoftVBA |
Sub show_conditions() ''1. if-statement If 234 > 34 Then MsgBox "234 is Greater than 34" End If ''2. if-else Dim X, Y As Integer X = 234 Y = 432 If X > Y Then MsgBox "X is Greater than Y" Else MsgBox "Y is Greater than X" End If ''3. if-elseif X = 234 Y = 234 If X > Y Then MsgBox "X is Greater than Y" ElseIf Y > X Then MsgBox "Y is Greater than X" Else MsgBox "X and Y are EQUAL" End If ''4. 중첩 if Dim a As Integer a = 23 If a > 0 Then MsgBox "a가 양수인 경우" If a = 1 Then MsgBox "The Number is 1" Else MsgBox "The Number is NOT 1" End If End If ''5. switch Dim MyVar As Integer MyVar = 1 Select Case MyVar Case 1 MsgBox "첫번째 수" Case 2 MsgBox "중간 수" Case 3 MsgBox "마지막 수" Case Else MsgBox "Unknown Number" End Select End Sub
Sub show_loops() '''1. for-loop Dim a As Integer a = 8 For i = 0 To a Step 2 MsgBox "The value is i is : " & i Next '''2. for-each-loop Dim fruits As Variant ''fruits는 배열 fruits = Array("apple", "orange", "cherries") 'iterating using For each loop. For Each Item In fruits Debug.Print Item & Chr(10) Next ''3. do-while-loop Dim x As Integer x = 3 Do While x < 5 x = x + 1 MsgBox "The value of x is : " & x Loop End Sub
Dim arr(5)
arr(0) = 10arr(1) = 20arr(2) = 30arr(3) = 40arr(4) = 50Debug.Print LBound(arr) & "~" & UBound(arr) '' 0~4
Sub array_split() 'Split function: 구분자로 분리될 수 있는 문자열을 분리하여 배열로 만든다. ' 구분자(delimiter) comma ',' Dim a as Variant a = Split("Red,Blue,Yellow",",") For i = 0 to UBound(a) msgbox("Value" & i & " is :" & a(i)) Next End Sub Sub array_join() 'Join function: Split 함수의 반대 개념. ' 배열 항목들을 구분하여 문자열을 만든다. a = array("Red","Blue","Yellow") ' Join using $ b = join(a,"$") msgbox("The Join result after using delimiter is : " & b) ''Red$Blue$Yellow End Sub Sub array_filter() 'Filter function: 필터 조건에 맞는 항목만 선택된 배열을 만든다. Dim a,b,c,d as Variant a = array("Red","Blue","Yellow") b = Filter(a,"B") c = Filter(a,"e") d = Filter(a,"Y") For each x in b msgbox("The Filter result 1: " & x) Next For each y in c msgbox("The Filter result 2: " & y) Next For each z in d msgbox("The Filter result 3: " & z) Next End Sub
Sub array_erase() ' IsArray function: 배열인지 아닌지 확인(True, False) Dim a,b as Variant a = array("Red","Blue","Yellow") b = "12345" If IsArray(a) = True then Erase a ' 각 배열의 항목이 초기화 된다. ' Dynamic Array인 경우 사용된 메모리가 Free된다. End If End Sub