简体   繁体   English

未声明“ MsgBox”。 由于其保护级别,它可能无法访问

[英]'MsgBox' is not declared. It may be inaccessible due to its protection level

I have been using vb.net from a long time, but never had this issue. 我使用vb.net已有很长时间了,但是从未遇到过此问题。 For some reason Intellisense is not detecting MsgBox(). 由于某些原因,Intellisense无法检测到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(). 当我将鼠标悬停在突出显示的红线上时,它说“未声明'MsgBox'。由于其保护级别,它可能无法访问”,并在潜在的修复程序中尝试创建一个名为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

This is the important part: 这是重要的部分:

Inherits System.Web.UI.Page

The VB.Net you know so well is for Windows Forms. 您非常了解的VB.Net是Windows窗体。 What we have here is an ASP.Net WebForms page. 我们这里有一个ASP.Net WebForms页面。 You can't use MsgBox() in a web page, because raw HTML doesn't have a direct match. 您不能在网页中使用MsgBox()因为原始HTML没有直接匹配项。

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. 有时它似乎可以按照您想要的方式工作,但这仅在您的开发环境中,其中Web服务器和客户端浏览器位于同一台计算机上。 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. 在现实世界中,您能找到的最接近的地方是注册一个JavaScript函数,该函数在DOM启动时运行,以调用alert() ,这远远没有那么好。

This is just one of many differences between the Web Forms and WinForms platforms. 这只是Web Forms和WinForms平台之间的众多差异之一。 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. Web Forms旨在使开发人员更轻松地从WinForms过渡到Web开发,但是它仍然是一个全新的平台,基于HTTP Request / Response模型的必要性。 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. 因此,在构建网页时,您需要考虑创建HTML元素来显示消息。 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; 重要的是要记住,您编写的任何VB.Net事件代码都是在Web服务器上运行的,只有在将新请求发送到服务器后才能完全重新启动页面生命周期,并且远离最终用户; never in the user's web browser. 永远不会在用户的Web浏览器中。 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. 刚开始时这可能非常令人沮丧,因为与javascript和公司相比,您几乎会非常了解VB.Net和WinForms API。 But it does get easier with time. 但是随着时间的推移,它确实变得更加容易。

But in this case, you're really only using MsgBox() to output debugging information. 但是在这种情况下,您实际上仅使用MsgBox()来输出调试信息。 What you can do instead here is use the System.Diagnostics.Trace class. 相反,您可以在这里使用System.Diagnostics.Trace类。 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. Trace可让您将消息直接放入Visual Studio输出窗口...,文件,数据库,控制台或您希望查看它们的任何位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 没有宣布。由于其保护级别,它可能无法访问 - not declared. It may be inaccessible due to its protection level 我收到“未声明'Eval'。 由于它的保护级别,它可能无法访问。 - I'm getting “'Eval' is not declared. It may be inaccessible due to its protection level” in a ascx 由于其保护级别无法访问 - inaccessible due to its protection level 由于Windows窗体中的保护级别而无法访问 - Inaccessible due to its protection level in windows forms 成员由于保护级别错误而无法访问 - Member is inaccessible due to its protection level error 由于其保护级别,ConfigurationProperty无法访问 - ConfigurationProperty is inaccessible due to its protection level 'ModbusSerialMaster'由于其保护级别而无法访问 - 'ModbusSerialMaster' is inaccessible due to its protection level 如何修复Winform中的“由于其保护级别而无法访问”错误? - How to fix “inaccessible due to its protection level” error in winform? HttpContext.Current.Items.TryGetValue由于其保护级别而无法访问 - HttpContext.Current.Items.TryGetValue inaccessible due to its protection level 由于其保护级别,ObservableCollection.SetItem()无法访问 - ObservableCollection.SetItem() is inaccessible due to its protection level
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM