Referencing a form in Immediate Window in

I'm used to Microsoft Access where I can type "Forms!FormName!ControlName" in the immediate window to get the value of a control on an open form.  In, how can I get the "selectedvalue" of a listbox on an open form from the immediate window (or some other window)?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
When you are in scope, just type:

Open in new window

Jacques Bourgeois (James Burger)PresidentCommented:
First of all, you need to know that the old Immediate Windows features have now been splitted in 2 different windows.

The window where you type code and it runs is still called Immediate Window. It is a lot more limited than the "old" one however. In most situations, you cannot use it as you used to. This is partly because VB.NET code is compiled instead of being interpreted as it was in VBA, partly because there are many levels of visibility for methods in .NET (Public, Private, Friend...), while most were Public in VBA.

When the application is not running, the Immediate Windows can only be used to call Public methods in a module. Calling methods that are not Public or are in a class (a Form is a class) is not possible. And even in a module, because the application has to be entirely compiled before it runs, it can take time and the application must be free of compilation errors before you can get a result.

The Immediate Window is thus mostly used when you are in Debug mode after hitting a breakpoint in your code. There, it can be used to call any code that you would be able to call from the breakpoint location in the code.

The other window, the Debug Window is the one that receives the Debug.Print commands that you were possibly using in VBA and are still there. This is what Éric recommended (although he forgot to tell you that it is called the Debug Window). This is not something that you go in and type in. It will simply write the value that you requested in the Debug.Print instruction when that line will be hit during execution.

So, ideally, put a breakpoint in your code at the proper location where you want to see your value. This usually has to be somewhere in the form itself.  The application will temporarily stop on the breakpoint. If there was a Debug.WriteLine before that point, you will see the result in the Output Window. Or you can call the value you are seeking by calling it ?YourValue in the Immediate Window. Or you can set up the Watch window to display the values that you want to get.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Declan_BasileITAuthor Commented:
Wow.  That was a very comprehensive answer and helped me understand in comparison to Access much better.  Thank you very much.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.