• 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

    • highly doubt that, he's giving away his wealth, he's been doing it for years now
    • Might be just about usable in about 5 years.
    • New Outlook for Windows gets a major boost with June 2025 Update by Pradeep Viswanathan Despite widespread criticism, Microsoft has remained focused on replacing the classic Outlook for Windows with the new web-based Outlook app for everyone. Every month, Microsoft releases updates to the new Outlook app based on user feedback. Today, Microsoft released the June 2025 update for Outlook for Windows with several improvements, including some of the most requested features by Outlook users. With this latest update, Microsoft has improved support for .pst (Outlook Data File) files. You can now reply to and forward emails in a stored .pst file. Microsoft is also working on further improving support for .pst files in the new Outlook for Windows. If you're using the new Outlook app with your personal Microsoft account that has access to Copilot Pro or AI credits through a Microsoft 365 Personal or Family subscription, Copilot features will now be available even for other personal email accounts configured in the Outlook app. This Copilot sharing feature works with email addresses such as Outlook.com, Hotmail.com, Live.com, MSN.com, and third-party providers like Gmail, Yahoo, and iCloud. Microsoft has also added the ability to easily move emails between personal accounts. This feature is disabled by default for enterprise users, but admins can enable it if needed. With this update, Microsoft has increased the default mail sync window in offline mode from 7 days to 30 days. Additionally, you can now access search folders and cancel an email after selecting Send in offline mode. This new update also brings email coaching support through Copilot. Copilot can now suggest adjustments to tone, clarity, and reader sentiment before you hit Send. If you are annoyed with Copilot, you can now disable Copilot completely by going to the Copilot > Copilot control page in the Settings window. In this release, Microsoft has added the ability to add shared folders to your Favorites, making it easier to access content directly from the Favorites list. Finally, an "External" tag will be added to external contact suggestions that appear in the dropdown menu when entering contacts in the email compose form, helping you distinguish between your organization's and external contacts.
    • "give" I believe he will give loans and drown the countries in debt
  • Recent Achievements

    • Week One Done
      Adam Todd earned a badge
      Week One Done
    • Contributor
      Ed B went up a rank
      Contributor
    • One Month Later
      moporcho earned a badge
      One Month Later
    • One Month Later
      Parotel earned a badge
      One Month Later
    • Reacting Well
      Cryptecks earned a badge
      Reacting Well
  • Popular Contributors

    1. 1
      +primortal
      210
    2. 2
      snowy owl
      156
    3. 3
      ATLien_0
      134
    4. 4
      Xenon
      120
    5. 5
      +FloatingFatMan
      113
  • Tell a friend

    Love Neowin? Tell a friend!