Wrox Programmer Forums
|
BOOK: ASP.NET Website Programming Problem-Design-Solution
This is the forum to discuss the Wrox book ASP.NET Website Programming: Problem - Design - Solution, Visual Basic .NET Edition by Marco Bellinaso, Kevin Hoffman; ISBN: 9780764543869
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET Website Programming Problem-Design-Solution section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2006, 06:34 AM
Authorized User
 
Join Date: Jun 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default variable used before it has been assigned a value

When compiling the Data tier classes for the Accounts module, I am warned that a null reference exception could occur at runtime because the code uses a variable before it has been assigned a value. The classes "User", "Role" and "Permission" all contain this warning.

Here is an exmaple of a function that makes this warning:

      Public Function GetAllPermissions() As DataSet
         Dim permissions As DataSet
         Try
            permissions = RunProcedure( _
            "AccountsGetAllPermissions", New IDataParameter() {}, "Permissions")
            Return permissions
         Finally
            If Not permissions Is Nothing Then
               permissions.Dispose()
            End If
         End Try
      End Function

The code will still compile, as it is a warning, not an error, but for my peace of mind, is there a better way to write those fragments of code so that this doesn't happen?

 
Old February 10th, 2006, 02:03 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 917
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I can't see any code here that accesses a variable before it's been created. I assume vb.net initialize permissions to "nothing" in the Dim statement? If not, then you can set it to nothing after the Dim and see if that cures the warning.





Similar Threads
Thread Thread Starter Forum Replies Last Post
ASSIGNING A JAVA SCRIPT VARIABLE TO A XSL VARIABLE SOMANATHAN10 XSLT 1 February 21st, 2007 04:26 AM
Notice: Only variables should be assigned by refer harpua Beginning PHP 0 August 22nd, 2006 10:47 AM
html option value assigned to xsl:variable bergs77 XSLT 2 February 23rd, 2006 02:27 PM
how to find assigned images of controls? saravananedu VB How-To 9 July 29th, 2005 01:34 PM
Object variable or With block variable not set tparrish Classic ASP Databases 0 May 21st, 2005 06:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.