Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7031171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:46:04+00:00 2026-05-28T00:46:04+00:00

I try to understand the VBA scope type, it’s impossible to make this such

  • 0

I try to understand the VBA scope type, it’s impossible to make this such of thing in VBA, but it’s possible in other language (java,scala,etc):

public sub try()

    dim myVar as String
    myvar = "hello world" 

    Call displayVar()

end sub

public sub displayVar()
   msgbox (myvar)
end sub

Can you give me some information about this type of limited scoping ? It’s dynamical or lexical, i don’t really understand the difference :/

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:46:05+00:00Added an answer on May 28, 2026 at 12:46 am

    Franck Leveque has provided a clear and simple demonstratation of the difference between local and global declarations.

    However, like most languages, VBA allows you to pass parameters to subroutines. Sometimes a global variable is the only choice or the only sensible choice. But normally it it is better to declare myVar within try and pass it as a parameter to displayVar. This prevents displayVar from accidentally changing myVar because, by default, parameters are passed as values. If you want a subroutine to change the value of a parameter you must explicitly pass the parameter as a reference. This is true of most modern programming languages.

    Note also that Public means these subroutines are visible to subroutines in other modules. If Public was omitted or replaced by Private, try and displayVar would only be visible within their module.

    In the code below I have passed the value of myVar as a parameter to displayVar.

    Public Sub try()
    
      Dim myVar As String
    
      myvar = "hello world"
      Call displayVar(myVar)
    
    End Sub
    
    Public Sub displayVar(Stg As String)
      Call Msgbox(Stg, VBOKOnly)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably simple, but im trying to try and understand pointers better. Lets
I can fix the below exception with a try-catch loop but I cannot understand
I try to understand what a Model is. I already read this answer .
I just try to understand the concept of the ItemsPanelTemplate. For this i built
Try to understand WPF. This is my test classes: public partial class MainWindow :
I am try to understand this code: Var1 = re.compile(rnothing is (\d+)).search i am
I've done this sample to try to understand why I'm not sending cookies at
there is something I try to understand. I have this object declaration in my
I try to understand Firefox's behavior regarding the added prevent this page from creating
I try to understand lexical-scoping. In lexical-scoping, I have this code, C like syntax:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.