Variable Scope in VB.NET

Discussion in 'ASP.NET / ASP.NET Core' started by jgs3, Jun 10, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I am shooting for the dumb question of the day....</o:p>
    </o:p>
    Very new to .Net code I am trying to give some variable global scope on a web page. The best information I have indicates that a declaration in my .aspx file as such:</o:p>
    </o:p>
    <script language="VB" runat="server">
    dim NextPrezCon as date= Application("NextPrezCon")
    dim NextPrezConEnd as date = Application("NextPrezConEnd")
    dim DaysUntil as integer = DateDiff("d",Now,NextPrezCon)
    </o:p>
    </o:p>
    would be legal syntax. However IIS thinks otherwise:</o:p>
    </o:p>
    Object reference not set to an instance of an object.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

    Source Error:





    Code:
    Line 8:  
    Line 9:  <script language="VB" runat="server">
    Line 10: dim NextPrezCon as date= Application("NextPrezCon")
    Line 11: dim NextPrezConEnd as date = Application("NextPrezConEnd")
    Line 12: dim DaysUntil as integer = DateDiff("d",Now,NextPrezCon)
    </o:p>
    </o:p>
    What newbie thing am I missing here? Thanks in advance for your help.</o:p>
    </o:p>
    Jim</o:p>
     
  2. Bruce

    Bruce DiscountASP.NET Staff

  3. Yes, when the dim's were in a sub, they retrieved the data just fine.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page