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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T16:39:07+00:00 2026-05-27T16:39:07+00:00

I have a variable whose scope needs to be global, because it needs to

  • 0

I have a variable whose scope needs to be global, because it needs to be called in a function as well as in a button press. So I declared the variable in a Module so it would be global.

The problem is that the value of this variable needs to be equal to the value of the text property of a textbox in the form.

Here you can download the VB.net demonstration of my problem: http://db.tt/DDxQJDXl

Below is an explanation of what happens

You enter a string into the textbox, in this case I entered “Hello”. Then you click the button and it displays what you wrote.

You click OK in that message box and change the value in the textbox. In this case I changed it to “Goodbye”. Then I hit the button again, but the variable did not change values and the messagebox displays “Hello” again.

Here is the entire source code:

Module Module1
     Public strDataValue = frmTest.txtDataValue.Text
End Module
Public Class frmTest
    Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
        MsgBox(strDataValue)
    End Sub
End Class

Note: This is just a demonstration of a problem I’m having in a much larger program so the variable does have to be global.

  • 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-27T16:39:08+00:00Added an answer on May 27, 2026 at 4:39 pm

    You need to set the value of the field to the new value in the TextBox:

    Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click
        strDataValue = txtDataValue.Text
        MsgBox(strDataValue)
    End Sub
    

    The field will not change values by itself.

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

Sidebar

Related Questions

I have a global variable called 'name', when a user clicks on a button
I have a variable argument function which prints error messages in my application, whose
I have read somewhere that we can restrict the scope of global variable to
I have an integer variable ( time ) in one view controller whose value
How I can have variable number of parameters in my function in C++. Analog
Is it possible to assign a local variable a value whose scope is outside
i am new to object oriented javascript. I have a variable whose value i
I have a variable $x whose value is read in from an XML file.
So I have a function that loops executing a function, example: function(f){ var variable;
I have a Number variable, named isConflict, whose value is passed in from a

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.