Simple as below:
If 1 = 2 Then
Dim i As Integer
Else
Dim i As Integer
End If
This will give an error as “duplicated declaration in current scope”. Why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Variables are local to the sub/function (procedure). In your case, the “current scope”. VB, VBA, and VBScript do not have the concept of code blocks within a procedure. If I remember correctly, the only code blocks are modules, classes, forms (which are classes), and procedures.
You can declare a variable anywhere within the procedure as a convenience. Yet, the “current scope” is the procedure.
It was a design decision to make the language easier to use for B-eginners.
Duplicate declaration in current scope
Inserted from http://msdn.microsoft.com/en-us/library/gg251613.aspx