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 8663107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:54:03+00:00 2026-06-12T16:54:03+00:00

OK so i just started to learn vb and did some experimenting until i

  • 0

OK so i just started to learn vb and did some experimenting until i came across this thing which i cant understand

So i have a console application with two modules

Module1.vb (program starts form this)

Module Module1

    Sub Main()
        add.addone()
        add.addone()
        add.addone()
        Console.Read()
    End Sub

End Module

add.vb

Public Module add
    Private counter As Integer

    Public Sub addone()
        counter += 1
        Console.Write(counter)
    End Sub
End Module

I expect it to print on the console a pattern of:

1
1
1

Why does it print out

1
2
3

Im asking this because, what i understand is, after add.addone() is called. The variable (counter) should no longer exist! So when add.addone() is called for the second time it should be blank and thus, printing out 1 again.

I hope you can help me. What am i doing wrong and why is this happening?

thanks,
Vidhu

  • 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-06-12T16:54:05+00:00Added an answer on June 12, 2026 at 4:54 pm

    after add.addone() is called. The variable (counter) should no longer exist!

    Why would that be? counter is declared outside of addone, in the surrounding module add. So of course it remains in existence even after the method exits.

    (Incidentally, you should follow the .NET PascalCase naming convention for modules and methods …)

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

Sidebar

Related Questions

Just started to learn C and came across the following issue: I need to
I have just started to learn asp.net MVC3 and i run into this problem:
I just started to learn about mod rewrite process. Now, I got some problems
I have just started to learn how to code iOS apps. I have made
I have just started learning Rails, is it required for me to learn CoffeeScript
I just started to learn SVN. Please give me your advice to understand the
I just started to learn MVC and am trying to understand how it works.
I just started to learn Android, I'm trying to write a widget which is
I have just started to learn Scala. I was looking for something in line
I have just started to learn Haskell out of interest. I follow learnyouahaskell.com .

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.