locked
Arrays RRS feed

  • Question

  • User-1569730980 posted

    If I have an array that has 400 elements in the X and 8 elements in the Y. How can I split this out in VB.net to have 8 seperate array curves with the 400 elements in X.

    Ie 8 of 400 * 1 instead of 400 * 8

    Saturday, June 2, 2012 10:48 AM

Answers

  • User1954304945 posted

    Hi, please copy the data into DataTable, then use LinQ to get the data you want. For example:

    Dim array As String(,) = {{"Mike", "Amy"}, {"Mary", "Albert"}, {"Mary", "Albert"}, {"Mary", "Albert"}, {"Mary", "Amy"}}
    
            Dim table As New DataTable()
            table.Columns.Add("FirstName", GetType(String))
            table.Columns.Add("LastName", GetType(String))
    
            Dim i As Integer = 0
            Dim str1 As String = ""
            Dim str2 As String = ""
            For Each item As String In array
                If i Mod 2 = 0 Then
                    str1 = item
                    i += 1
                Else
                    str2 = item
                    table.Rows.Add(str1, str2)
                    i = 0
                    str1 = ""
                    str2 = ""
                End If
            Next
    
            Dim list As EnumerableRowCollection = From rows In table.AsEnumerable() Where rows("LastName") = "Amy" Select rows("FirstName")
    
            Dim list1 As New List(Of String)()
            For Each item As String In List
                list1.Add(item.ToString())
            Next
    

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, June 3, 2012 11:10 PM