Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
|
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 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 December 7th, 2005, 01:43 PM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to myserenity101
Default VB 2005 Generics in a Project Updgraded from 2003

.NET 2.0 introduces Generics which is something that I am just beginning to learn. If I create a new ClassLibrary in VS 2005 I have no problems working with generics. For instance here's a quick sample.

Imports System.Collections

Public Class TreeNode(Of T)
    Private _items As List(Of T)

End Class

This works fine if the project was originally created in VS 2005, however if I try the same thing (within VS 2005) on a project that has been upgraded from VS 2003, "List" isn't even an option in intellisense. However, If I type it(List(Of T)) in regardless it gets highlighted as an error with the statement "Type 'List' is not defined".

Any Ideas?


 
Old December 7th, 2005, 02:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Try this syntax

Dim GColInt As Generic.List(Of Integer)

Regards
Ankur Verma
 
Old December 7th, 2005, 03:46 PM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to myserenity101
Default

Thanks for the quick reply. However, I do not think that I'm being clear. Here is the Generic Class that I can use fine as long as the project itself originated from VS 2005, that is .NET 2.0

Imports System.Collections

Public Class TreeNode(Of T)
    Private _items As List(Of T)

    Public Sub New(ByVal nodeData As T)
        Me._items = New List(Of T)
        Me._items.Add(nodeData)
    End Sub

    Public ReadOnly Property Items() As T()
        Get
            Return Me._items.ToArray()
        End Get
    End Property

    Public Sub Add(ByVal nodeData As T)
        Me._items.Add(nodeData)
    End Sub

End Class

If I cust and paste this sample into a VS 2005 project that was originally created in VS 2003 (.NET 1.1) and been ported over to .NET 2.0, the "List(Of T)" is marked "Type 'List' is not defined".

Thanks Again!

 
Old December 7th, 2005, 04:35 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 453
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Ankur_Verma Send a message via MSN to Ankur_Verma
Default

Hello Daniel,
Generic collections were not there in VS 2003. So you couldnt have written this code in VS 2003, if you had- it wouldnt have compiled error free.

Anyways, when you port from .NET 1.1 to .NET 2.0 the converter wont add any namespaces or assmeblies to your project that were not there in VS 2003, you can guess why?

So to use any features that are specific to VS 2005 either you create the project from scratch in VS 2005 or if you are porting from an earlier version, modify your project to add the required namespaces and assemblies, that are introduced only in VS 2005 and were not ther ealier.

In the case of above code sample, add this line in the begining

Imports System.Collections.Generic

and your project should comile error free without any further changes.

Read about namespaces and their importance if you dont know what they are, you are going to need that information and a lot more if you r doing development in .NET.

Regards
Ankur Verma
 
Old December 7th, 2005, 04:53 PM
Registered User
 
Join Date: Dec 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to myserenity101
Default

Thank You! Thank You! Thank You!

Although I understand namespaces and their importance to .NET development I still have allot to learn. All of the examples that the Wrox Book "Professional .NET 2.0 Generics" have only made use of the System.Collections Namespace. As I stated before, I was able to do this successfully in any new apps but when adding to an old one I was unable to figure out why it failed. Although I was sure that it was due to either a reference or namespace, I never would have guessed to add the .Generics to the System.Collections Namespace.

I hope that others are able to find this post because I'm sure I'm not the only one to fall victim to this.

Thanks Again!

db



 
Old October 24th, 2006, 01:44 PM
Registered User
 
Join Date: Oct 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

My perspective is that the 'Beginning ASP.NET 2.0' book DOESN"T address the generics namespace inclusion, therefore making the code appear broken by not knowing tht list is a correct type.

'Beginning' ought to be the operative word here . . .

Either way, thanks for the post - that did the trick for me, too.





Similar Threads
Thread Thread Starter Forum Replies Last Post
vb 2003 to 2005 convert gone wrong mr_kane General .NET 2 August 5th, 2007 04:35 PM
VB 2005 connect to server 2003 with SQL database Derek_05 Visual Basic 2005 Basics 3 September 20th, 2006 10:10 AM
Conversion from .Net 2003 to .Net 2005 using VB.Ne coleenh Visual Basic 2005 Basics 0 September 19th, 2006 02:48 PM
Can I run VB .net 2005 with DOT NET 2003 APPLICATI kadesskade BOOK: Beginning Visual Basic 2005 ISBN: 978-0-7645-7401-6 2 August 8th, 2006 05:14 AM
Access 2003 project and SQL server 2005 jesseleon Access VBA 3 February 23rd, 2006 12:03 PM





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