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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:47:20+00:00 2026-05-20T20:47:20+00:00

For some unknown reasons this silly thing cant be implemented. I have an int

  • 0

For some unknown reasons this silly thing cant be implemented.

I have an int count in the main form which I want to return to another class or form.

namespace my_speller
{
   public partial class login : Form
   {
       public login()
       {
        InitializeComponent();
       }

      int count;
      private void btnlogin_MouseUp(object sender, MouseEventArgs e)
      {
           dbaccess obj = new dbaccess();

           for (int i = 0; i < 10; i++)
           {
                    if (txtusername.Text == obj.Usersusername()[i])
                    {
                        count = i;
                        break;
                    }
           }
       } 

       public int namecount()
       {
        return count;
       }

    }
}

dbaccess is another class and I could successfully call a function (Usersusername) defined in that class to my login form. Everything works fine up to this. Now I want to get the int count from main form back to dbaccess class. So I implemented a public function namecount to return count. But count is always zero in the other class. In the main form, I get the value of count correctly (which is i). But nothing gets returned when I call from dbaccess class this way:

        login obj = new login();
       // do stuff

or from another form in the same program, like this:

namespace my_speller
{
   public partial class student : Form
   {
      public student()
      {
        InitializeComponent();
      }

    private void button3_Click(object sender, EventArgs e)
    {
        login obj = new login();
        MessageBox.Show(obj.namecount().ToString());
    }

The messagebox here should display count which is some number, but what’s displayed is zero. What could possibly be the cause??

The same thing happens when I’m trying to return a string from my main form. It’s always null in other classes 🙁

Thanks in advance

Edit: Can you give the code snippet itself. I cant know the technical terms you might use to help me

  • 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-20T20:47:20+00:00Added an answer on May 20, 2026 at 8:47 pm

    This code will create a new instance of your Login form. Each instance will have its own instance variable count.

    login obj = new login();
    MessageBox.Show(obj.namecount().ToString());
    

    The default value for an integer is 0, so each time you create a new instance of the form it will have the value of 0 in the count variable. If you want to have all instances of the form have the same value for count, you should make count static.

    private static int count;
    

    When the variable is static, there will be only one instance of count shared by all instances of the Login form.

    var form1 = new login();
    // mouse up event fires on form1, value of count is set to 3 (for example)
    var form2 = new login();
    form2.namecount(); // returns 3
    

    Depending on what you want to do, there are other patterns, like using events, or a mediator that can help pass messages between components. This way when something happens in one form, other forms can react to the change without actually needing to reference or even know about the other forms in the application.

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

Sidebar

Related Questions

I have an instance of Tomcat which periodically crashes for unknown reasons. There are
For some unknown reason if I have: class A{ int stars; public int getStars(){
So I have some html that looks like the following: <div class='something unknown' id='something_unknown_1'>
I have a table that, some of its columns are unknown at compile time.
For some unknown reasons DAta Picker is not appearing on the Browser. I cam
I have a layout that should be fairly straightforward, but for some unknown reason
We have an application that generates pdf files, some times for some unknown reason,
For some unknown reason I'm running into a problem when passing a variable to
I am trying to use log4net in a VB.NET app for some unknown reason
I need some pointers on how to detect unknown hardware using .NET and C++/C#.

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.