Solved

value cannot be converted

Posted on 2006-11-27
2
240 Views
Last Modified: 2010-04-23
for each de as DictionaryEntry in htTableList
        Dim td as New TableDetails()
       
        td = de.Value  
        Dim dd as New Check_Tables.ColumnDetails
        dd = CType(td.GetColumns(),ColumnDetails) 'COMPILER ERROR HERE
        Dim cd as New Check_Tables.ColumnDetails(de.Key,dd.Sources)
        'debug.WriteLine("Reporting:  " + td.GetColumns().ToString)
        debug.WriteLine("Table:  " + de.Key + ", " + de.Value)

    Next

...\Form1.vb(67): Value of type '1-dimensional array of Check_Tables.ColumnDetails' cannot be converted to 'Check_Tables.ColumnDetails'.





CODE DETAILS, FOR YOUR REFERENCE:

Public Class ColumnDetails
  Public Name As String
  Public Sources As ArrayList

  Public Sub New(ByVal n As String, ByVal srcs As ArrayList)
    Me.Name = n
    Me.Sources = srcs
  End Sub

  Public Sub New()
    me.name = nothing
    me.sources = new ArrayList()
  End Sub
End Class

Public Class TableDetails
  Public Sub New()
  End Sub

  Private Sources As ArrayList = New ArrayList
  Private columnsHT As New Hashtable

  Public Sub AddSource(ByVal src As String)
    If Not Sources.Contains(src) Then Sources.Add(src)
  End Sub

  Public Function GetSources() As String()
    Return CType(Sources.ToArray(GetType(String)), String())
  End Function

  Public Sub AddColumn(ByVal ColumnName As String, ByVal src As String)
    If Not columnsHT.ContainsKey(ColumnName) Then
      columnsHT.Add(ColumnName, New ArrayList(New String() {src}))
    End If

    Dim al As ArrayList = CType(columnsHT(ColumnName), ArrayList)
    If Not al.Contains(src) Then
      al.Add(src)
    End If
  End Sub

  Public Function GetColumns() As ColumnDetails()
    Dim al As ArrayList = New ArrayList
    For Each name As String In columnsHT
      al.Add(New ColumnDetails(name, CType(columnsHT(name), ArrayList)))
    Next
    Return CType(al.ToArray(GetType(ColumnDetails)), ColumnDetails())
  End Function

  'Tom Knowlton
  'Earl's function as he left it on Wed, 22 Nov, 2006
  'Public Function GetColumns() As ColumnDetails()
  '  Dim al As ArrayList = New ArrayList
  '  For Each name As String In columnsHT
  '    al.Add( _
  '      New ColumnDetails( _
  '        name, _
  '        CType(columnsHT(name), ArrayList) _
  '      ) _
  '    )
  '  Next

  '  Return CType(al.ToArray(GetType(ColumnDetails)), ColumnDetails())
  'End Function

End Class
0
Comment
Question by:knowlton
  • 2
2 Comments
 
LVL 10

Expert Comment

by:Kinger247
ID: 18021146

Your trying to convert the ColumnDetails class into an array

Try: dd = CType(td.GetColumns,ColumnDetails)
0
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
ID: 18021157
Hang on, that won't work either as GetColumns returns an array.
will this work ?

Dim td as New TableDetails()
td = de.Value  
Dim dd() as New Check_Tables.ColumnDetails
dd = CType(td.GetColumns(),ColumnDetails) 'COMPILER ERROR HERE
Dim cd as New Check_Tables.ColumnDetails(de.Key,dd.Sources)

changed dd to an array.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question