【问题标题】:Calling a SUB from a Class from a namespace VB.Net从命名空间 VB.Net 中的类调用 SUB
【发布时间】:2010-11-23 21:33:35
【问题描述】:

我有一个代码,但不能让它工作。 我有一个带有命名空间和一个类和一个子的 .vb 站点。 然后在我的 index.aspx 网站上我不能调用这个子 这2个站点在我的项目的根目录下,项目的名称是CalendarWeek

我的 WeekController.vb 是

Imports System
Imports System.Web.UI.WebControls.Calendar
Imports System.Globalization

Namespace CalendarWeekController
    Public Class WeekShow

    Shared Sub Main()
        ' Gets the Calendar instance associated with a CultureInfo.
        Dim myCI As New CultureInfo("da-DK")
        Dim myCal As Calendar = myCI.Calendar

        ' Gets the DTFI properties required by GetWeekOfYear.
        Dim myCWR As CalendarWeekRule = myCI.DateTimeFormat.CalendarWeekRule
        Dim myFirstDOW As DayOfWeek = myCI.DateTimeFormat.FirstDayOfWeek

        ' Displays the number of the current week relative to the beginning of the year.
        Console.WriteLine("The CalendarWeekRule used for the en-US culture is {0}.", myCWR)
        Console.WriteLine("The FirstDayOfWeek used for the en-US culture is {0}.", myFirstDOW)
        Console.WriteLine("Therefore, the current week is Week {0} of the current year.", myCal.GetWeekOfYear(DateTime.Now, myCWR, myFirstDOW))

        ' Displays the total number of weeks in the current year.
        Dim LastDay = New System.DateTime(DateTime.Now.Year, 12, 31)
        Console.WriteLine("There are {0} weeks in the current year ({1}).", myCal.GetWeekOfYear(LastDay, myCWR, myFirstDOW), LastDay.Year)
    End Sub 'Main 


End Class

结束命名空间

我的 index.aspx 是

    <%@ Import Namespace="CalendarWeekController" %>
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb" Inherits="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <%  
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Me.IsPostBack = False Then
        Call WeekShow(Sub Main) 

        End If
    End Sub

%>
    </div>
    </form>
</body>
</html>

我在运行网站时收到此错误。 说明:解析服务此请求所需的资源时出错。请查看以下特定的解析错误详细信息并适当地修改您的源文件。

解析器错误消息:无法加载类型“CalendarWeek.CalendarWeekController”。

来源错误:

第 1 行: 第 2 行: 第 3 行: 第 4 行:

【问题讨论】:

    标签: vb.net class


    【解决方案1】:

    您必须使用Classname.Subname 调用共享子。 在你的情况下:

    WeekShow.Main()
    

    【讨论】:

    猜你喜欢
    • 2011-07-31
    • 1970-01-01
    • 2021-06-12
    • 1970-01-01
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    相关资源
    最近更新 更多