• 0

Problem w/ Immediate Window in VB.NET


Question

Hi guys,

I'm moving from VB6 to VS.NET 2010, and I'm getting the hang of it but I am having a hell of a time trying to use the Immediate window like I used to in VB6.

For example, when I typed in:

MsgBox "test"

I would get a msgbox with Text in it.

If I try the same in VB.NET:

MsgBox("test")

all I get is this:

'MsgBox' is not declared. It may be inaccessible due to its protection level.

Why can't this thing just work the way it used to, or am i missing something?

Thanks!

Link to comment
https://www.neowin.net/forum/topic/1023628-problem-w-immediate-window-in-vbnet/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

My VB is rusty, but if I recall you may need to import the Microsoft.VisualBasic namespace for the older MsgBox function. Should be imported by default in a WinForm app, will need to reference it manually in a console app I believe. Personally, you might want to consider getting used to the MessageBox class instead though.

  • 0
  On 07/09/2011 at 11:27, Jen Smith said:

My VB is rusty, but if I recall you may need to import the Microsoft.VisualBasic namespace for the older MsgBox function. Should be imported by default in a WinForm app, will need to reference it manually in a console app I believe. Personally, you might want to consider getting used to the MessageBox class instead though.

Jen, your on the ball. I tried the Microsoft.VisualBasic.MsgBox("hello") function, and it worked. If I try just MessageBox class, it gives the error again...

This is what I am after however:

Microsoft.VisualBasic.MsgBox(My.Computer.Info.OSVersion)

so I can see that so I can write code based on total number of dots.

<sigh>

I really wish MS hadn't messed with VB...

  • 0

Don't use the old VB MsgBox function, instead use the .NET MessageBox class and its static Show method.

Imports System.Windows.Forms

MessageBox.Show("Hellold.")

The reason why your code didn't work is because you need to import the proper namespaces. An Imports statement would have fixed your code, but it's better to make use of the 'real' .NET classes. ;)

  • 0
  On 07/09/2011 at 11:42, Mr. Black said:
<sigh>I really wish MS hadn't messed with VB...

I'm more of a C++/C# coder, but once you get the hang of the framework VB is a lot better than it used to be, be it in features or in the language itself. If anything read over MSDN, there's a crazy amount of documentation and help material to go over. Still should consider getting used to using the proper MessageBox class though. While you're at it, poke around the various namespaces in the object browser, there's an absurd amount of functionality built into the platform right out of the box.

Just to save yourself a bit of typing, you can import the namespace so you don't have to constantly name the whole method every time you use it. Example:

Imports Microsoft.VisualBasic

Module Module1

    Sub Main()
        MsgBox("OS Version: " + My.Computer.Info.OSVersion)
    End Sub

End Module

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • It depends if they can market it to hipsters, then they might hold a niche.
    • No Man's Sky Beacon update overhauls settlements and player overseer duties by Pulasthi Ariyasinghe Hello Games is back with another major update to its sci-fi space survival game No Man's Sky. This time, it has targeted settlement systems. The title will now let players be overseers who manage settlements across multiple planets while also discovering towns run entirely by robotic lifeforms. Space-faring players can now be the overseers of four settlements across the universe, with the job being offered to them after completing a unique objective. "Govern your settlers wisely and invest in their infrastructure to enable each settlement to flourish, producing lucrative resources, and becoming an invaluable base of operations throughout your journey," explains the studio. Settlement management has also been completely reworked with this update. Hello Games says that players will now have more important construction and upgrade choices, as each building has its own calculated contribution to the happiness, population, and productivity of its settlement. These can benefit the player via a wide range of resource production options. Not only that, each settler will even have their own personalities, strengths, weaknesses, and skills that will change how they work in their community. Players can find these by simply talking to any settler they meet on a planet. When a citizen dispute comes up, the number of choices offered to the overseer has been increased as well. As for the robotic settlements, they can only be found by scanning planets with specialist technology. Once found, these Autophage settlements can be taken over as well, letting players be the overseer and take care of the scrap metal-built locals. Other additions to this update include Intel Xe Super Sampling (XeSS) upscaling tech support on PC, more voice types for player characters, better snapping when building structures, and cross-save support across all platforms. Don't forget that No Man's Sky will soon be arriving on a brand-new platform too. The title will be a day-one launch on the Nintendo Switch 2 on June 5. Find the complete patch notes for No Man's Sky 5.7 Beacon Update over here.
    • Eh. I think I'm more in favor of this not being a thing. One of the most useful things on Reddit is being able to see if the person posting is consistently who they say they are. Hiding posts just allows shitposters to hide.
  • Recent Achievements

    • Week One Done
      mywakehealth earned a badge
      Week One Done
    • Dedicated
      jbatch earned a badge
      Dedicated
    • Week One Done
      Leonard grant earned a badge
      Week One Done
    • One Month Later
      portacnb1 earned a badge
      One Month Later
    • Week One Done
      portacnb1 earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      294
    2. 2
      snowy owl
      159
    3. 3
      +FloatingFatMan
      155
    4. 4
      ATLien_0
      140
    5. 5
      Xenon
      126
  • Tell a friend

    Love Neowin? Tell a friend!