1
votes

I have been using vb.net from a long time, but never had this issue. For some reason Intellisense is not detecting MsgBox(). When I hover over the highlighted red line it says "'MsgBox' is not declared. It may be inaccessible due to its protection level" and in the potential fixes it tries to create a new function named MsgBox(). Below is the code:

Imports System
Imports System.Data.SqlClient
Imports System.Runtime.InteropServices
Imports System.Web.Configuration
Imports Microsoft.Office.Interop.Outlook

Public Class ConferenceRooms
    Inherits System.Web.UI.Page

    Dim SQLConnection As New 
SqlConnection(ConfigurationManager.ConnectionStrings("MyDB").ConnectionString)
    Dim SQLcommand As New SqlCommand
    Dim SQLAdapter As SqlDataAdapter
    Dim SQLDataTable As DataTable

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    'MsgBox(LBTest.Attributes("title"))
    'Dim lb As Label = CType(Me.Controls("HR Conference Room"), Label)
     If Not IsPostBack Then
        Dim Query1 As String
        Query1 = "Select Location_ID from LCSConference_Locations where vacant = 1"
        RunQuery(Query1)
        Dim OrganizerEmail As String = OrgEmail.Value
        Dim Agenda As String = MeetAgenda.Value
        Dim Location As String = MeetLocation.Value
        MsgBox("Hello")

    End If
End Sub
1
Do you receive any issues compiling the code? Intellisense isn't perfect. Try restarting the IDE to see if the issue continues.h0r53
Yes, i have tried that as well.user8657231
Thanks, it worked out. I guess it was not included in the project, because it was not tick marked in the properties window.user8657231

1 Answers

7
votes

This is the important part:

Inherits System.Web.UI.Page

The VB.Net you know so well is for Windows Forms. What we have here is an ASP.Net WebForms page. You can't use MsgBox() in a web page, because raw HTML doesn't have a direct match.

Okay, you can with the right tweaks, but it won't work the way you want — the message will show in a special private desktop on the server, where it blocks the request until the thread times out, and the end user will never see it. It might sometimes seem to work the way you want, but this is only in your development environment, where the web server and client browser are on the same machine. The closest you can get in the real world is registering a javascript function to run at DOM startup to call alert(), and that's just nowhere near as nice.

This is just one of many differences between the Web Forms and WinForms platforms. Web Forms is intended to make it easier for developers to transition from the WinForms world to web development, but it's still a whole new platform, based of necessity on the HTTP Request/Response model. It still requires significant study to learn well, just like any other platform.

So when building a web page, you need to think in terms of creating an HTML element to show your message. It's important to remember that any VB.Net event code you write runs on the web server, only after sending a new request to the server that completely re-starts the page lifecyle, and far away from the end user; never in the user's web browser. This can be very frustrating at first, because you'll tend to know VB.Net and the WinForms APIs fairly well, compared to javascript and company hardly at all. But it does get easier with time.

But in this case, you're really only using MsgBox() to output debugging information. What you can do instead here is use the System.Diagnostics.Trace class. Trace will let you put the messages right into the Visual Studio output window... or a file, or a database, or the console, or wherever you want to see them.