• 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

    • Do they tell Google not to scrape their content via something like robots.txt? Do they specify anywhere that certain agents aren't to scrape? If not, tough. Plus there's no obligation on anyone's part to adhere to any directives that might be in this file anyway...
    • DMDE 4.3.5.823 Beta by Razvan Serea DMDE is a software designed to effectively recover lost data. It retrieves files and folders swiftly and stores them in the user-defined location. It is an easy to use yet powerful tool that will assist both novice and experienced users in getting back lost files in just a few simple steps. Free Edition includes all basic features but a single recovery operation recovers up to 4000 files in the current panel only (you should first open a subdirectory in the current panel and then recover files in the panel). In paid licenses there is no this restriction, and recovery of nested directories is allowed. Can paid versions recover more files than the free version of DMDE? If a file cannot be recovered in the DMDE Free Edition (or it is damaged after recovery) the same will occur in the paid versions. DMDE paid versions are capable of recovering the same files. The only difference is that paid versions can recover all found files in one go, as well as restore the directory structure presented in the free version. Professional Edition provides additional features: rights to provide data recovery services portable use on different computers one-time activation on client computers (including remote use) data recovery reports (include logs and file checksums) read support for E01 disk image files using logs when copying a disk (resume copying, multiple passes) customizable I/O handler script recovery of NTFS alternate data streams DMA access in DOS (for ATA interface) DMDE key features: Portable run without installation Support for NTFS, FAT12/16, FAT32, exFAT, ReFS, Ext2/Ext3/Ext4, btrfs, HFS+/HFSX, APFS Thorough FS and Raw scan, FS reconstruction for data recovery in complex cases Simple partition manager for express search, diagnostics, and restoration of partitions Disk cloning and disk image creating, including I/O error handling, reverse copying, and other features RAID constructor for virtual RAID reconstruction supporting levels RAID-0, RAID-1, RAID-4, RAID-5, RAID-6, delayed parity, custom striping, JBOD/spanned disks; automatic calculation of RAID configurations Cluster map to investigate file allocation Disk editor compatible with the most recent Windows versions which allows viewing, editing, and navigating through different disk structures using built-in and custom templates NTFS tools to work bypassing NTFS driver (copy, delete file, create, repair directory) Support for various device I/O interfaces and settings to work with damaged devices, disk images, NTFS compression and encryption, national names, large disks, large files, large sectors, and other features DMDE 4.3.5.823 Beta changelog: Expanded built-in signatures for RAW search functionality Added file list export to HTML format (DMDE Professional Edition only, view sample) Improved handling of I/O errors with selective skipping by error code Enabled preview support for additional image (graphic) file types (Windows only) Improved extfs reconstruction when copies of superblocks with group descriptors are found Fixed potential hang during Btrfs volume reconstruction Resolved issue with cluster list creation when subfolders are present Other improvements and fixes Download: DMDE 64-bit | 2.4 MB (Free, paid upgrade available) Download: DMDE 32-bit | 2.0 MB Link: DMDE Home Page | DMDE Manual | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • The BBC might have gone about this the wrong way, but if there is a revenue sharing program then they and all other "providers" of data should be included in the plan.
    • PicView 3.1.4 by Razvan Serea PicView is a fast, free and fully customizable image viewer for Windows 10 and 11. It supports a vast range of image file types, including WEBP, GIF, SVG, PNG, JXL, HEIC, PSD and many others. Additional features includes viewing EXIF metadata, image compression, batch resizing, viewing images within archives and comic books, image effects, image galleries, and more. Available in portable and installable versions. PicView 3.1.4 changelog: What's new Mouse Side Buttons Customization: You can now change how the mouse side buttons work. Choose to navigate file history or switch between directories. Find this setting under the Mouse tab in the settings window (#199). Improvements Directory Navigation: Improved navigation between directories. If Search subdirectories is enabled, PicView moves to the next directory in the list; if off (or if there are no directories in the list), it navigates as before. PicView now remembers your startup directory (including subdirectories) and restores it on the next launch. Performance: Preloader has been fine-tuned for better performance and lower memory usage. Bug Fixes Fixed incorrect saved settings path when saving in portable mode (#213). Corrected cases where keybindings and file history were not saved when there was no write permission. Restoring the window from a maximized state now correctly keeps its position when auto-fit is enabled. Fixed start-up menu text alignment and missing text issues. Translations Hebrew translation by @Y-PLONI (#212) Hungarian translation by @JohnFowler58 (#209) Japanese update by @coolvitto (#214) Miscellaneous Updated to Avalonia 11.3.1. Now using ZLinq and ZLinq.FileSystem to reduce memory allocation and possibly improve performance. Future versions managed via Scoop will now preserve configuration files (#15555). Experimental settings (not yet available in the UI—edit UserSettings.json directly): Disable the file watcher (not recommended, untested). Choose preload amount and direction (forward/backward). Download: PicView 3.1.4 | Portable ~50.0 MB (Open Source) Download: PicView ARM64 | Portable ARM64 Links: PicView Home Page | Github Project Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • The design looks good on their phones, but I can't say that I like the look of these.
  • Recent Achievements

    • 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
    • Collaborator
      lethalman went up a rank
      Collaborator
    • Week One Done
      Wayne Robinson earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      681
    2. 2
      ATLien_0
      276
    3. 3
      Michael Scrip
      221
    4. 4
      +FloatingFatMan
      170
    5. 5
      Steven P.
      164
  • Tell a friend

    Love Neowin? Tell a friend!