Solved

value cannot be converted

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now