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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:17:00+00:00 2026-06-13T13:17:00+00:00

Please help me to understand how to use class to share variables. I have

  • 0

Please help me to understand how to use class to share variables.
I have 3 forms and one class to store some variables. Inside form1 I am calling myclass and setting up variables. Now I show form2 and inside form2 I call form3

Is it possible to get variable from a class , which I have sent from first form ?
Myclass code looks like this :

    Private _var As String
Public Sub setvar(ByVal var As String)
    _var = pvar
End Sub

Public Function getvar() As String
    Return _var
End Function

from form1 :

       Public class1 As myclass
      class1 = New myclass
       class1.setvar("test")

Now I want to call class1.getvar and I want it return the value which I have entered in a first form. is it possible ? if yes please help me how ?

Thanks

  • 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-13T13:17:01+00:00Added an answer on June 13, 2026 at 1:17 pm

    Because you have used the ‘Public’ access modifier on you ‘class1’ variable definition you should be able to access it as a field on Form1 from anywhere that has access to that instance of Form1.

    Dim myString as String = form1.class1.getvar()
    

    It would probably be neater not to do it this way though.

    OPTION1
    If it were me I would prefer to create the instance of MyClass in the first form and then pass that instance to the other forms (possibly through the constructor).

    Public Class Form1
    
       Private _instance As MyType
    
    
       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
          _instance = New MyType
    
          Dim newForm As New Form2(_instance)
       End Sub
    

    End Class
    Modify the New method of Form2 and Form3 to accept a parameter of type MyClass:

    Public Class Form2
    
       Private _instance As MyType
    
       Sub New(instance As MyType)
          _instance = instance
       End Sub
    
    End Class
    

    Then you are passing the variable in when you create the new form and storing it in a private member that you can access anywhere in the code of the second form.

    OPTION2
    Alternatively, you could put the definition of class1 into a module and then you could access it from wherever you want in the project.

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

Sidebar

Related Questions

Please help this Linq newbie! I'm creating a list inside my class under test,
Please help me understand the following code snippet :- def any(l): whether any number
Please help me understand why add1() and add4() report errors and why add2() and
Please help me understand this recursive function... var stack = Array; function power(base, exponent){
Please help me understand where I am going wrong so much so that I
I'm a noob; please help me understand this authentication config / bindings stuff that
the following code is not behaving like I would expect. Please help me understand
Can anyone please help me to understand how should i access json data in
Please could someone help me understand why the div.fl element shown in Developer Tools
Please help me. I can't understand why this function, that uses texture memory __global__

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.