VBA use public variable when private variable has the same name

CodeCamper

Is it possible to have a 'public' variable and 'dim' variable with the same name and use both in the same sub?

Alex K.

The more local variable wins (shadowing).

To access the variable in the global scope you would need to qualify it with its containing module name:

Public Foo As Long

Sub g()
 dim Foo As String
 ...
 msgbox Foo
 msgbox ModuleName.Foo

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use a global variable in C when there is a local variable that has the same name?

From Dev

Instance variable in derived class has the same name with private instance variable of superclass?

From Dev

Why we use public and private variable separately

From Dev

data.table := assignments when variable has same name as a column

From Dev

VBA use string as variable name

From Dev

Why should variable has public or private or protect but function should not in a class

From Dev

How to remember value of public variable and use it when open excel file in the next time use VBA in outlook

From Dev

Use a class name to call variable of the same name

From Dev

Use a class name to call variable of the same name

From Dev

ncks error when variable name has spaces

From Dev

How to use variable with the same name as String Swift

From Dev

same column name in variable columns when pivot

From Dev

Variable name has a variable at the end

From Dev

Error when using public member function to access private member variable: Variable "was not declared in this scope"

From Dev

Should I use getXXX() or the (private) variable inside the same class?

From Dev

Should I use getXXX() or the (private) variable inside the same class?

From Dev

Managing a private cocoapod with the same name of a public cocoapod

From Dev

Managing a private cocoapod with the same name of a public cocoapod

From Dev

Public Static variable in excel vba

From Dev

Public Static variable in excel vba

From Dev

R: How to use $ when the name is stored in a variable?

From Dev

Why is the parent value getting updated when I use the scope variable of same name as parent?

From Dev

What happens when I use the same variable name in a function called via ajax, that i have previously defined?

From Dev

Is there any purpose to make private class variable to public

From Java

Ada: Using a private variable in a precondition of a public function

From Dev

access private object variable from public method

From Dev

How to make a private variable in a public method

From Dev

Getting "public variable" in a "private method" using CoffeeScript

From Dev

Java public variable is zero in private class

Related Related

  1. 1

    How to use a global variable in C when there is a local variable that has the same name?

  2. 2

    Instance variable in derived class has the same name with private instance variable of superclass?

  3. 3

    Why we use public and private variable separately

  4. 4

    data.table := assignments when variable has same name as a column

  5. 5

    VBA use string as variable name

  6. 6

    Why should variable has public or private or protect but function should not in a class

  7. 7

    How to remember value of public variable and use it when open excel file in the next time use VBA in outlook

  8. 8

    Use a class name to call variable of the same name

  9. 9

    Use a class name to call variable of the same name

  10. 10

    ncks error when variable name has spaces

  11. 11

    How to use variable with the same name as String Swift

  12. 12

    same column name in variable columns when pivot

  13. 13

    Variable name has a variable at the end

  14. 14

    Error when using public member function to access private member variable: Variable "was not declared in this scope"

  15. 15

    Should I use getXXX() or the (private) variable inside the same class?

  16. 16

    Should I use getXXX() or the (private) variable inside the same class?

  17. 17

    Managing a private cocoapod with the same name of a public cocoapod

  18. 18

    Managing a private cocoapod with the same name of a public cocoapod

  19. 19

    Public Static variable in excel vba

  20. 20

    Public Static variable in excel vba

  21. 21

    R: How to use $ when the name is stored in a variable?

  22. 22

    Why is the parent value getting updated when I use the scope variable of same name as parent?

  23. 23

    What happens when I use the same variable name in a function called via ajax, that i have previously defined?

  24. 24

    Is there any purpose to make private class variable to public

  25. 25

    Ada: Using a private variable in a precondition of a public function

  26. 26

    access private object variable from public method

  27. 27

    How to make a private variable in a public method

  28. 28

    Getting "public variable" in a "private method" using CoffeeScript

  29. 29

    Java public variable is zero in private class

HotTag

Archive