• 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

    • Elon Musk's robotaxi will have a human driver for 'safety' reasons by David Uzondu Image via Depositphotos.com A few days ago, we reported that Tesla was gearing up for its robotaxi launch, set to kick off in Austin, Texas, and now the details of the service are trickling out. Electrek says that some popular pro-Tesla influencers on X have gotten invitations to the launch. These invitations came with a list of rules, and the most glaring one was the presence of what Tesla called a "Safety Monitor" in the front passenger seat. This is basically a human supervising driver whose entire job is to watch the car and make sure it does not drive itself into a ditch. This might feel a little strange, especially given Musk's claims of "no driver" testing in the past. The safety monitor is one of the employees with access to buttons that can stop the car, much like the ones available to Waymo passengers in their fully autonomous rides. The service will operate within a geofenced area from 6 AM to 12 AM and will not run during bad weather. Other requirements include a credit card on file and an agreement that you will not be a jerk. Participants must also agree to a bunch of other rules, and one of the most interesting ones is that their access can be terminated if they share content on social media that shows the vehicle being misused. On top of that, they're not allowed to reverse engineer the technology in any way. At least the passenger gets a bit of a break. So, unlike the Tesla Full-Self Driving Beta, which requires the owner's constant attention, the supervising driver is expected to pay attention. At the same time, you, the passenger, can relax and enjoy the ride. According to Electrek's Fred Lambert, the robotaxi launch seems like an optics thing, designed to let Elon Musk say he met his June deadline for launching a robotaxi network.
    • I don't get why you care how thin your phone is. Most people slap a giant case on it anyway, so it doesn't mean much in the long run.
    • Yay it finally made it to openSUSE Tumbleweed. Installed on the rest of my PCs/laptops and also working just fine. Was also available before for KDE Neon and Fedora. And I hear Arch also already has it.
  • Recent Achievements

    • Week One Done
      Helen Shafer earned a badge
      Week One Done
    • First Post
      emptyother earned a badge
      First Post
    • Week One Done
      Crunchy6 earned a badge
      Week One Done
    • One Month Later
      KynanSEIT earned a badge
      One Month Later
    • One Month Later
      gowtham07 earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      661
    2. 2
      ATLien_0
      268
    3. 3
      Michael Scrip
      224
    4. 4
      Steven P.
      167
    5. 5
      +FloatingFatMan
      160
  • Tell a friend

    Love Neowin? Tell a friend!