Solved

value cannot be converted

Posted on 2006-11-27
2
259 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

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…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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