본문 바로가기
카테고리 없음

[Excel 매크로 + Davey식 매크로 강좌] Excel 엑셀 매크로 매개변수 (parameter) 와 인수 (argument) 에 대해서 알아보자

by ★√★ 2021. 2. 22.

안녕하세요, Davey입니다. 오늘은 제 자신도 많이 헷갈리는 매개변수(parameter)와 인수(argument)에 대한 내용과 그 둘의 차이에 대해서 제 나름대로 공부한 내용을, 애기해보도록 하겠습니다.

 

 

- 사실 가장 간단한 거 같으면서도, 딱히 설명하면, 제 자신도 어버무릴 거 같은 느낌이 드는 사항인 거 같습니다. 일단 설명에 앞서 제가 블로그 포스팅을 하면서 강박을 좀 받으면서 포스팅을 했던 거 같습니다.

 

- 물론 정확한 정보를 전달해야 되는 게 맞지만 제 자신도 이 매크로를 만든 개발자가 아닌 학습자의 입장에서 틀릴 수 있다 라는 가능성을 좀 없애려고, 부단히(?) 노력을 했던 거 같습니다.

 

- 하지만 저도 학습자의 입장에서는 틀릴 수도 있다 라는 생각을 하니, 약간은 좀 마음이 편안해졌다 라는 생각이 듭니다. 즉, 제 포스팅 내용 중에 혹시 틀린 부분이 있을 경우에는 꼭 댓글로 달아주시면 저한테도, 그리고 댓글을 달아주시는 분 그리고 제 포스팅 보시는 (많이 보시지는 않으시겠지만) 모든 분들에게, 도움이 된다고 생각합니다.

 

- 그럼 넋두리는 여기에서 마무리하고 설명 해 드리도록 하겠습니다.

 

1. 매개변수(parameter)와 인수(argument) 설명을 위한 예제 프로시저

 

쉬운 설명과 Demonstration을 위해서 아래와 같이 간단하게 2개의 프로시저 구문을 만들었습니다.

 

아래 프로시저 구문을 간단하게 설명 드리면, main1() 프로시저에서 Sub_main1 프로시저를 Calling 해서 결과 값을 도출하는 것입니다.

 

1. Sub main1()

Call havingParameter(1, 2)

End Sub

​

2. Sub Sub_main1(ByVal intFirst As Integer, ByVal intSecond as Integer)

total = intFirst + intSecond

MsgBox total

End Sub

 

- 일단 2번째 프로시저에는 매개변수(parameter) "intFirst", "intSecond" 가 상수로 정의가 되고, 이 프로시저안의 매개변수에게 건네지는 것이 인수(argument) 인 "1", "2" 입니다.

 

- 약간 사전적으로 애기를 드리면, 각 프로시저에는 매개변수(parameter)들이 변수, 상수, 구문으로 정의 되어 있고, 이 프로시저안의 매개변수에게 건네지는 것이 인수(argument)이다.

 

- 눈치 채셨겠지만, 매개변수는 어떤 값을 받아 줄 수 있는 이름이 있는 것이고, 그 매개변수에 전달되어 지는 인수는 이름을 가지고 있지 않습니다. 하지만, 매개변수와 인수의 데이터 타입은 동일해야, 호환이 됩니다. 예를 들어 상수의 매개변수에 문자의 인수를 전달하게 되면 오류가 생기게 되는 거죠.

 

 

2. 매개변수 (parameter) 와 인수 (argument)에 대한 발췌한 내용 (출처 - From 엑셀 매크로 도움말)

: 아래 영어로 된 원문은 MS 도움말에서 발췌한 내용입니다. 원문의 내용을 해석한 것이니, 원문을 보시면, 더 명확하게 이해가 되시는 분들도 있을 거라고 생각합니다.

 

1) Differences Between Parameters and Arguments (Visual Basic)

: In most cases, a procedure must have some information about the circumstances in which it has been called. A procedure that performs repeated or shared tasks uses different information for each call. This information consists of variables, constants, and expressions that you pass to the procedure when you call it.

To communicate this information to the procedure, the procedure defines a parameter, and the calling code passes an argument to that parameter. You can think of the parameter as a parking space and the argument as an automobile. Just as different automobiles can park in a parking space at different times, the calling code can pass a different argument to the same parameter every time that it calls the procedure.

2) Parameters

: A parameter represents a value that the procedure expects you to pass when you call it. The procedure's declaration defines its parameters.

When you define a Function or Sub procedure, you specify a parameter list in parentheses immediately following the procedure name. For each parameter, you specify a name, a data type, and a passing mechanism (ByVal or ByRef). You can also indicate that a parameter is optional. This means that the calling code does not have to pass a value for it.

The name of each parameter serves as a local variable in the procedure. You use the parameter name the same way you use any other variable.

3) Arguments

: An argument represents the value that you pass to a procedure parameter when you call the procedure. The calling code supplies the arguments when it calls the procedure.

When you call a Function or Sub procedure, you include an argument list in parentheses immediately following the procedure name. Each argument corresponds to the parameter in the same position in the list.

In contrast to parameter definition, arguments do not have names. Each argument is an expression, which can contain zero or more variables, constants, and literals. The data type of the evaluated expression should typically match the data type defined for the corresponding parameter, and in any case it must be convertible to the parameter type.

 

이상입니다. 오늘도 하나 배워나가는 하루가 되었으면 합니다. 공부하시느라고 수고 하셨고, 항상 도전하고 성장하는 저희가 되었으면 합니다. 감사합니다.

 

[저작권이나, 권리를 침해한 사항이 있으면 언제든지 Comment 부탁 드립니다. 검토 후 수정 및 삭제 조치 하도록 하겠습니다. 그리고, 기재되는 내용은 개인적으로 습득한 내용이므로, 혹 오류가 발생할 수 있을 가능성이 있으므로, 기재된 내용은 참조용으로만 봐주시길 바랍니다. 게시물에, 오류가 있을때도, Comment 달아 주시면, 검증 결과를 통해, 수정하도록 하겠습니다.] 

728x90

댓글


// 내부링크를 현재창으로 열기 // Open internal links in same tab