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

  • SEARCH
  • Home
  • 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 7641613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:58:06+00:00 2026-05-31T08:58:06+00:00

I was reviewing the MSDN documentation on VB.Net’s little-used Static keyword for local variables.

  • 0

I was reviewing the MSDN documentation on VB.Net’s little-used Static keyword for local variables. My question is not about how Static works (I personally plan to avoid using it as it seems like it could cause grief to future programmers who don’t notice the side-effects.) My question is about this statement in the docs:

The behavior of any local variable depends on whether it is declared
in a Shared procedure. If the procedure is Shared, all its local
variables are automatically shared. This includes the Static
variables. There is only one copy of such a variable for the whole
application.

This seems to imply that all local variables in a Shared Sub would behave like Static variables — they would keep their values across separate calls. But I knew this wasn’t the case, and I wrote a little test program to prove it:

Class TestSharedSub

    Shared Sub Main()
        Test()
        Test()
        Test()
        Console.Write("Press any key to continue...") : Console.ReadKey()
        ' Output:
        ' 1, 1
        ' 2, 1
        ' 3, 1
    End Sub

    Shared Sub Test()
        Dim iNormal As Integer
        Static iStatic As Integer
        iNormal += 1
        iStatic += 1
        Console.WriteLine(iStatic & ", " & iNormal)
    End Sub

End Class

So can anyone interpret the above statement for me in a way that makes sense? Or is this a bug in the documentation? It’s been there since the VS 2005 version of the docs and is still present in the Visual Studio 11 version.

  • 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-31T08:58:07+00:00Added an answer on May 31, 2026 at 8:58 am

    No, it’s talking nonsense. It continues being utterly broken in the next paragraph:

    If the procedure is not Shared, its local variables are instance variables.

    Local variables aren’t instance variables…

    Whoever wrote that page appears not to understand local variables at all. Goodness knows what they’d make of recursion. Mind you, it starts off reasonably:

    Normally, a local variable in a procedure ceases to exist as soon as the procedure stops.

    … but that statement is clearly in contradiction to the later ones. Sigh.

    I suggest you file a bug on Connect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reviewing a bunch of older questions asking about logging in .NET. A
Reviewing an earlier question on SO, I started thinking about the situation where a
The MSDN CreatMutex() documentation ( http://msdn.microsoft.com/en-us/library/ms682411%28VS.85%29.aspx ) contains the following remark near the end:
In books I have seen that it exists but MSDN says it does not???
I was reviewing code and found that $(#item1 #item2) and $(#item1>#item2) are used interchangeably.
After reviewing this answer and given the extension method: public static bool IsIn<T>(this T
I'm reviewing for a class, and this is an old question: I need to
I'm reviewing this database and creating the foreign keys, believe me they did not
Reviewing Conery's storefront, and I dont understand why he used Linqs auto-generated classes (ie
While reviewing the demo project for the xVal , a validation framework for ASP.NET

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.