Solved

value cannot be converted

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

21 Experts available now in Live!

Get 1:1 Help Now