none
Value of type '1-dimensional array of String' cannot be converted to 'String'.

    Question

  • Thank you. I just tried David Anton's translator.
    The initial conversion went pretty well with only the following resultant compile code error:

    Value of type '1-dimensional array of String' cannot be converted to 'String'.

     Me.listView1.Invoke(CType(Function() AnonymousMethod1(strOfDevices), Action), Nothing)
    
    'these lines of code preceded the erroring line above,
    
    Dim strOfDevices() As String
    strOfDevices = New String() { device1, device2 }
    
    Private Function AnonymousMethod1(ByVal strOfDevices As String) As Object
        PopulateListView(strOfDevices)
        Return Nothing
    End Function
    
    the original c# was
    string[] strOfDevices;
    strOfDevices = new string[] { device1, device2};
    this.listView1.Invoke((Action)delegate { PopulateListView(strOfDevices); }, null);
    
     private void PopulateListView(string[] devicename)
     {
       this.listView1.Items.Clear();
       for (int i = 0; i < 2; i++)
       {
         this.listView1.Items.Add(devicename[i].ToString());
       }
     }
    
    Tuesday, December 08, 2009 2:32 PM

Answers

  • Private Function AnonymousMethod1(ByVal strOfDevices As String) As Object

    I believe this should be

    Private Function AnonymousMethod1(ByVal strOfDevices() As String) As Object
    

    You are seeing the error where it is because your code is calling a method which does not ask for the parameter you are trying to pass to it.
    When you see errors in the form "Value of type 'A' cannot be converted to 'B'" you should always look to see what kind of argument the function is expecting.


    • Proposed as answer by •.trujade.• Tuesday, December 08, 2009 3:49 PM
    • Marked as answer by hazz Tuesday, December 08, 2009 5:16 PM
    Tuesday, December 08, 2009 3:22 PM

All replies

  • Private Function AnonymousMethod1(ByVal strOfDevices As String) As Object

    I believe this should be

    Private Function AnonymousMethod1(ByVal strOfDevices() As String) As Object
    

    You are seeing the error where it is because your code is calling a method which does not ask for the parameter you are trying to pass to it.
    When you see errors in the form "Value of type 'A' cannot be converted to 'B'" you should always look to see what kind of argument the function is expecting.


    • Proposed as answer by •.trujade.• Tuesday, December 08, 2009 3:49 PM
    • Marked as answer by hazz Tuesday, December 08, 2009 5:16 PM
    Tuesday, December 08, 2009 3:22 PM
  • not sure if this helps, but if you are just trying to populate the listview w/the strings in strOfDevices, i would use the For..Next instead of the Do..Loop.

    Public Class Form1
    
        Dim strOfDevices() As String
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            '-- added the following strings for testing purposes
            Dim device1 As String = "device1", device2 As String = "device2", device3 As String = "device3", _
            device4 As String = "device4"
            strOfDevices = New String() {device1, device2, device3, device4}
            Me.ListView1.Invoke(CType(Function() AnonymousMethod1(strOfDevices), Action), Nothing)
        End Sub
        
        Private Function AnonymousMethod1(ByVal strOfDevices() As String) As Object
            PopulateListView(strOfDevices)
            Return Nothing
        End Function
    
        Public Sub PopulateListView(ByVal devicename() As String)
            Me.listView1.Items.Clear()
            For Each itm As String In strOfDevices
                ListView1.Items.Add(itm)
            Next
        End Sub
    
    End Class
    


    •.trujade.•
    Tuesday, December 08, 2009 3:26 PM
  • Thank you so much!
    Tuesday, December 08, 2009 5:16 PM