• 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

    • Although I never owned one, I always thought MS has a great design and UI for their phones. I wish they would reconsider coming out with a Windows 11/12 phone.
    • This keeps happening with Intel Arc drives, since intel keeps releasing newer non-whql revisions.
    • Is that the experience of a local account? I don't recall signing out of Edge being an option for them on Microsoft accounts. At the time, the MS default settings blocked 3rd party browsers like Chrome because they had no way to limit what was done without that browser. You are right, there isn't really a way to prevent someone from installing their own OS if they have local access to the system and the knowledge to do so. If someone is willing to go to the lengths of reinstalling an operating system, then you are really beyond protections like this. It would be like hoping a basic spring-loaded privacy lock can contain someone with lock someone with lock picking skills. My personal advice for a situation like that is that parenting isn't only about creating barriers, it is about growing, teaching, and trust. You don't want to see your kid as a hacker that you are trying to contain, you want to see them as someone who you trust to use a computer. If you don't feel that trust is justified, then maybe they shouldn't have unsupervised access to the computer. Even if you do have to set restrictions, there is an element of trust to those restrictions. When someone is grounded from leaving the house, you don't accomplish that by tying them down, you do it by setting expectations. The same applies to the digital world, you can set expectations that you expect them to follow, even if they are not digitally enforced. If they violate that trust, then the answer isn't to try different parental controls, it is to create consequences such as taking the device away for a few weeks.
    • I can't help but feel like MS is giving Windows 11 a spit-shine to get it ready for all the inbound displaced Windows 10 users. They still refuse to give people the things they actually want, but I guess they think silly options like this will at least make it look like they have options.
  • 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
      670
    2. 2
      ATLien_0
      272
    3. 3
      Michael Scrip
      222
    4. 4
      Steven P.
      167
    5. 5
      +FloatingFatMan
      165
  • Tell a friend

    Love Neowin? Tell a friend!