Solved

value cannot be converted

Posted on 2006-11-27
2
230 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

810 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