Assigning a dynamic array to a fixed array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rich209
    New Member
    • May 2010
    • 2

    Assigning a dynamic array to a fixed array

    Hello,

    I have been programming for past few months and find it quite fun. I have come across a problem that I can not find an answer to. How do I assign a dynamic string array to a fixed string array?

    What I have done is created a file, wrote to the file, and, using the code below, read from the file. Each line in the file is assigned to an array position and the counter is increased for each line. The array is then sorted and displayed in a list box.

    mArray is not declared in this code because it is a module level variable that I use in other procedures and functions.

    As mentioned earlier I have to take the dynamic array and assign it to an array(24).

    Here is my code:

    Dim index As Integer = 0
    Dim lineoftext As String = ""
    Using sr As New System.IO.Strea mReader("File_O f_Names")
    While Not sr.EndOfStream
    lineoftext = sr.ReadLine
    If lineoftext <> "" Then
    ReDim Preserve mArray(index)
    mArray(index) = lineoftext
    index = index + 1
    mintItemCount = index
    End If
    End While
    sr.Close()
    End Using

    Array.Sort(mArr ay)

    For Each s As String In mArray
    lstDisplaySorte dNames.Items.Ad d(s)
    Next

    Warmest Regards,
    Rich
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    dear,

    To define a fix. array with dyn. arrays, just create a "Type" with dyn. arrays and dim the fix. array "as" the type with the dyn. arrays (see attachment).

    Code:
    Type ARRAYGROUP
       DyA_1() As String
       DyA_2() As String
       DyA_3() As String
    End Type
    
    Dim FiA(1 To 5) As ARRAYGROUP
    br,
    Attached Files

    Comment

    • rich209
      New Member
      • May 2010
      • 2

      #3
      Hello ggeu,

      Thank you. I will be in class all day today but after class I will try your suggestion and let you know if it works.

      Warmest Regards,
      Rich

      Comment

      Working...