Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > Visual Studio 2005
Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 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 July 30th, 2008, 02:49 PM
Registered User
Join Date: Oct 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default function return collection in class by VB

Hi friends,
I created a VB class with function in visual studio 2005.I got error that can not convert vb system collection.
I am a new person to learn VB studio. I do not know to fix it.
Please review my codes

Public Class student
    Private m_studentname As String
    Private m_studentid As String
    Public Property studentname() As String
            Return Me.m_studentname
        End Get
        Set(ByVal valuename As String)
            Me.m_studentname = valuename
        End Set
    End Property

    Public Property studentid() As String
            Return Me.m_studentid
        End Get
        Set(ByVal valueid As String)

            Me.m_studentid = valueid
        End Set
    End Property
    Public Sub New(ByVal studentname As String, ByVal studentid As String)
        Me.studentname = studentname
        Me.studentid = studentid
    End Sub
    Public Function getstudent() As Collection
        Dim vn As String = Me.studentname
        Dim vid As String = Me.studentid
        Dim sb As New sortedlist(Of String, String)
        For i As Integer = 1 To 10
            vn = "jimmy" & i
            vid = "1111" & i
            sb.Add(vn, vid)
            'Messagebox.show(vn & "----" & vid, "debug info")
        Return sb
    End Function
End Class

Old July 30th, 2008, 03:12 PM
Friend of Wrox
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

The VB "Collecton" is an internal-to-VB-only collection type. It is *NOT* part of the standard ASP.NET Collections package. That is, a SortedList is *NOT* an instance of a VB.NET Collection.

Just change your Function declaration to explicitly say it is returning a SortedList.

You really want to do that, anyway, since you are returning a particular type of the generic class.

Public Function getstudent() As sortedlist(Of String, String)
If that cause difficulties at other points in your code, then let's look again.

Similar Threads
Thread Thread Starter Forum Replies Last Post
return collection by function in class jimusa Visual Basic 2005 Basics 1 July 30th, 2008 03:18 PM
Collection Class chapter 5 eggspencer BOOK: Professional PHP 5 ISBN: 978-0-7645-7282-1 1 November 27th, 2006 04:46 PM
Calling Oracle function from Vb.net class monuindia2002 ADO.NET 1 August 4th, 2006 05:00 AM
Return Collection object from a Web Method raybo .NET Web Services 2 June 17th, 2006 07:42 AM
How do I make a function return a class? vertigo VB How-To 3 November 3rd, 2004 06:08 AM

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