开发者

Calling a SUB from a Class from a namespace VB.Net

开发者 https://www.devze.com 2023-01-26 20:21 出处:网络
I have a code but cant get it to work. I have a .vb site with a namespace and a Class and a Sub. Then on my index.aspx site i cant to call this sub

I have a code but cant get it to work. I have a .vb site with a namespace and a Class and a Sub. Then on my index.aspx site i cant to call this sub The 2 sites is in the root of my project, and the name of the project is CalendarWeek

My WeekController.vb is

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

End Namespace

And My index.aspx is

    <%@ Import Namespace="CalendarWeekController" %>
<%@ Page Language="vb" AutoEventWireup="false开发者_StackOverflow" 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>

i get this error when running the site. Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Could not load type 'CalendarWeek.CalendarWeekController'.

Source Error:

Line 1: <%@ Import Namespace="CalendarWeekController" %> Line 2: <%@ Page Language="vb" AutoEventWireup="false" Inherits="CalendarWeek.CalendarWeekController" %> Line 3: Line 4:


You have to call shared subs with Classname.Subname. In your case:

WeekShow.Main()
0

精彩评论

暂无评论...
验证码 换一张
取 消