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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:32:48+00:00 2026-06-07T11:32:48+00:00

In C++, it is possible to do: int x; int& foo = x; //

  • 0

In C++, it is possible to do:

int x;
int& foo = x;

// foo is now a reference to x so this sets x to 56
foo = 56;

But is an equivalent possible in Visual Basic .net (VB.net)?

I am aware of the ByRef term in VB.net but I have only seen (and by extensive research) this in passing parameters by reference to functions/subroutines, so that the function modifies the same variable declared by the calling code.

But I haven’t seen ByRef used to declare variables (as class members or local variables). I have tried to use ByRef to do such a declaration but I get compiler errors for each ordering of the declaration I try.

The reason why I want to do this is because I want a class instance to be able to refer to a variable declared in another class instance.

Specifically, I am working on some existing VB.net code where program logic is mixed up with UI logic in VB.net form classes. I want to separate the program logic out of the form code so that it can be more easily reused. To do this I need the program logic code to be able to ‘talk’ to the form code so I need access to its variables.

I am using Visual Studio 2010 Express with VB.net and would prefer to remain within this environment even though I am aware that full Visual Studio has extended capabilities.

  • 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-07T11:32:50+00:00Added an answer on June 7, 2026 at 11:32 am

    Pointers exist but they’re called object references

    (Now other posters, please don’t quibble with me about the actual differences here. I am talking about the high level task the OP wants to accomplish)

    Obviously you can’t do literally what you’ve said – that is, surgically manipulate one member. But if you have control of the code, you can do almost as well. And from what you describe is your problem, this method will be much better, as you can pass references to an object that has many members you wish to update, instead of having to pass many individual pointers.

    First define a class:

    Class MyScreenValues
        ' Properties will work... using public fields for brevity
        Public TextBox1Value as String
        Public SpinControl1Value as Integer
        public CheckBox1Value as Boolean
    End Class
    

    Now the equivalent of the code you posted:

    Dim x as new MyScreenValues    'int x; 
    dim foo as MyScreenValues = x  'int& foo = x;  
    '// c++:  foo is now a reference to x so this sets x to 56 
    '// .net: foo is now a reference to x so this sets x.SpinControl1Value to 56 
    foo.SpinControl1Value = 56; 
    

    If what you’re doing is trying to pass pointers to, say, every control on your form’s value to a sub, like so:

    Button1_Click(...
        Dim MyObject as new BusinessObject
        MyObject.DoSubmit(TextBox1.Text, SpinButton1.Value, CheckBox1.Checked)
    

    You can use the method provided by superbDeveloper, and use the ByRef keyword on the definition of the DoSubmit Sub:

    Public Sub DoSubmit(ByRef Name as String, ByRef Age as Integer, ByRef Employed as boolean)
        ... business logic...
    

    However this just gives you a 2-layer separation. Look into MVP, MVC, etc – however consider submitting the entire view worth of data. It’s a lot of research you you may settle with what you have now. For example your business logic will be firing events on the form as it changes the form values (well, actually, they won’t fire until the sub exits, due to the way VB deals with byref properties [=temp variable], but it needs to be considered).

    You can also map an object’s properties to a Form’s properties with other libraries. Check out VALUE INJECTOR on the web. It can take a webform/winform and maybe even a WPF form and map the control values to and from an object you have predefined. Excellent for complete separation.

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

Sidebar

Related Questions

Possible Duplicate: create multiple variables based on an int count Objective C Equivalent of
I have a class Foo defined like this: class Foo { public: Foo(int num);
This is going to be a really goofy question but is it possible to
I should get this by now, but I'm just not getting it yet. The
For this function: void foo_ref(const int& i) { cout << i << endl; }
Is it possible to tell g++ to use the FOO& operator when constructing the
I receive a pointer numeric value like: 0xbfe0e6ac it is possible set int foo
Possible Duplicate: return type in c++ #include<iostream> int& fun(); int main() { int p=fun();
I have this code: #include <iostream> class foo { public: foo(int yy){y = yy;}
Say I have this: template<typename T, int X> class foo { public: void set(const

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.