Results 1 to 12 of 12

Thread: [RESOLVED] [2005] ToString() not working for custom class

Threaded View

  1. #1

    Thread Starter
    Lively Member mightor's Avatar
    Join Date
    Apr 2007
    Location
    Turn around, I'm right behind you...
    Posts
    99

    Resolved [RESOLVED] [2005] ToString() not working for custom class

    Hi there,

    I have created a custom class called XmlSource which has a ToString() function .

    vb Code:
    1. Public Class XmlSource
    2.     Inherits System.Net.WebClient
    3.  
    4.     Private _name As String
    5.     Private _uri As Uri
    6.     Private _xmldoc As System.Xml.XmlDocument
    7.  
    8.     Public Sub New(ByVal name As String, ByVal uri As Uri)
    9.         MyBase.New()
    10.         _name = name
    11.         _uri = uri
    12.     End Sub
    13.  
    14.     Public Sub New(ByVal name As String, ByVal uri As String)
    15.         MyBase.New()
    16.         _name = name
    17.         _uri = New Uri(uri)
    18.     End Sub
    19.  
    20.     Public Overrides Function ToString() As String
    21.         Return _name
    22.     End Function
    23.  
    24.     Public ReadOnly Property XmlDoc() As System.Xml.XmlDataDocument
    25.         Get
    26.             Return _xmldoc
    27.         End Get
    28.     End Property
    29.  
    30.     Public Property Uri() As Uri
    31.         Get
    32.             Return _uri
    33.         End Get
    34.         Set(ByVal value As Uri)
    35.             _uri = value
    36.         End Set
    37.     End Property
    38.  
    39.     Public Property Name() As String
    40.         Get
    41.             Return _name
    42.         End Get
    43.         Set(ByVal value As String)
    44.             _name = value
    45.         End Set
    46.     End Property
    47.  
    48.     Protected Overrides Sub OnDownloadStringCompleted(ByVal e As System.Net.DownloadStringCompletedEventArgs)
    49.         'If the string request went as planned and wasn't cancelled:
    50.         If e.Cancelled = False AndAlso e.Error Is Nothing Then
    51.             'Use e.Result to get the String
    52.             Dim sr As New System.IO.StringReader(CStr(e.Result))
    53.  
    54.             ' The XmlTextReader
    55.             Dim xr As New System.Xml.XmlTextReader(sr)
    56.  
    57.             ' The XmlDocument
    58.             _xmldoc = New System.Xml.XmlDocument
    59.             _xmldoc.Load(xr)
    60.         End If
    61.         MyBase.OnDownloadStringCompleted(e)
    62.     End Sub
    63.  
    64.     Public Sub fetchXML()
    65.         'Fetch HTML page
    66.         MyBase.DownloadStringAsync(_uri)
    67.     End Sub
    68.  
    69. End Class

    In my MainForm_Load sub I am attempting to create a new instance and use it as follows:

    vb Code:
    1. Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim sourceUS As New XmlSource("US", "http://www.worldofwarcraft.com//realmstatus/status.xml")
    3.  
    4.         MsgBox(sourceUS)
    5.         ComboBox_Continent.Items.Add(sourceUS)

    The ComboBox_Continent.Items.Add() function doesn't complain but shows nothing in the control either. The MsgBox() does complain (I Added it for debug purposes). It tells me that Argument 'Prompt' cannot be converted to type 'String'. I was under the impression that was what the ToString() function was for.
    Does anyone have any pointers?

    Thanks,
    Mightor
    Last edited by mightor; May 2nd, 2007 at 01:08 AM. Reason: fixed typo
    What the world needs is more geniuses with humility, there are so few of us left.
    If my post was accidentally useful, please rate it as such, thanks!
    Mon aéroglisseur est plein des anguilles.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width