Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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 April 28th, 2011, 10:33 PM
Registered User
 
Join Date: Apr 2011
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default creating variable in a class

Hi

This may be beyond the scope of the book, but I'm working on an assignment for a visual basic class I'm taking.

The goal is to make a store front for a movie store.

I've been able to pass the database record key to a variable in the code-behind of my browse.aspx. When I pass the variable to the ShoppingCart class, I get a null reference exception. My code below isn't exact, but it's close to what I'm working on.

this works fine:
Code:
[browse.aspx button-click event]
Dim cart as New Shopping Cart = nothing
Dim dk as string
dk= detailsview.datakey.value.tostring()
cart.Add(dk)
Then in the ShoppingCart.vb file I have

Code:
Imports System.Collection

Public Class ShoppingCart
Dim cart as new stringcollection = nothing

Public Sub Add(ByVal value as string)
     cart.Add(value)
End Sub
The cart.Add throws a null reference exception and I cannot figure out why. On the other hand, I'm not even sure this is a good way to approach the problem, since once the user navigates to the cart.aspx I have no idea if I'll even be able to access the cart created on browse.aspx

Thanks =)
 
Old April 30th, 2011, 05:27 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Quote:
This may be beyond the scope of the book
Yes, it is ;-) You're much better off posting questions like these in a more general ASP.NET category: http://p2p.wrox.com/asp-net-4-539/ Makes it easier for everyone to find what they are looking for.

Anyway, you need to post your real code. There's not much point trying to debug code that doesn't even compile....

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 30th, 2011, 06:20 AM
Registered User
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Post Answer

Class variables means Object of Class,Because an instance of class can access the all instances and Method of class ,
Class sum
{
int a,b;
public static void main()
{
sum s=new sum() //This is a variable of class.......sum
s.a=20;
s.b=40;
}
}
 
Old April 30th, 2011, 07:45 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi Niraj Singh,

How does this answer the question or help the OP? His question is about a null reference exception in VB code, and as a reply you explain the concept of a class? And in C#?

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old April 30th, 2011, 01:52 PM
Registered User
 
Join Date: Apr 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Class

Class is an User Defined Data type.Class is also an object.............
Class has blue print for accessing/Creating Variable and Method.
 
Old April 30th, 2011, 02:06 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Yes, but what does that have to do with the original question? It's like replying and saying: an orange is a citrus fruit. True, but not very helpful.... :-)

And BTW: a class is not an object. You use a class to create objects (instances) of that class.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Enumerated Property in a Class sg48 Visual Basic 2008 Essentials 0 May 4th, 2010 04:38 PM
Can I create a class from a variable? MAtkins General .NET 2 August 1st, 2005 11:57 AM
Creating a Class for multi projects ocarroll General .NET 6 December 4th, 2004 05:13 PM
creating a .dll from a .cs class vb_developer C# 1 October 27th, 2004 05:59 PM
Need help creating reusable code in a class. jbenson001 ASP.NET 1.x and 2.0 Application Design 1 November 21st, 2003 01:07 PM





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