Reading two dim array from text file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • al jones

    Reading two dim array from text file

    I'm trying to get something to work here and not having much luck. I can
    take the sledgehammer approach (read each line, parse for the tab sepertor,
    put each part in it's respective element) but with all the array functions
    in 2005 there has to be an easier way.

    Suggestion??? (code appreciated, I'm learning).

    //al
  • Herfried K. Wagner [MVP]

    #2
    Re: Reading two dim array from text file

    "al jones" <alfredmjones@s hotmail.com> schrieb:[color=blue]
    > I'm trying to get something to work here and not having much luck. I can
    > take the sledgehammer approach (read each line, parse for the tab
    > sepertor,
    > put each part in it's respective element) but with all the array functions
    > in 2005 there has to be an easier way.[/color]

    If you do not mind writing the array in a binary format:

    \\\
    Dim a(,) As Integer = {{2, 4, 234234}, {4, 4, 9}, {4, 4, 9}}
    FileOpen(1, "C:\foo.txt ", OpenMode.Binary , OpenAccess.Read Write)
    FilePut(1, a, 1)
    Dim b(2, 2) As String
    FileGet(1, b, 1)
    FileClose(1)
    ///

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://classicvb.org/petition/>

    Comment

    • al jones

      #3
      Re: Reading two dim array from text file

      On Sun, 27 Nov 2005 14:00:41 +0100, Herfried K. Wagner [MVP] wrote:
      [color=blue]
      > "al jones" <alfredmjones@s hotmail.com> schrieb:[color=green]
      >> I'm trying to get something to work here and not having much luck. I can
      >> take the sledgehammer approach (read each line, parse for the tab
      >> sepertor,
      >> put each part in it's respective element) but with all the array functions
      >> in 2005 there has to be an easier way.[/color]
      >
      > If you do not mind writing the array in a binary format:
      >
      > \\\
      > Dim a(,) As Integer = {{2, 4, 234234}, {4, 4, 9}, {4, 4, 9}}
      > FileOpen(1, "C:\foo.txt ", OpenMode.Binary , OpenAccess.Read Write)
      > FilePut(1, a, 1)
      > Dim b(2, 2) As String
      > FileGet(1, b, 1)
      > FileClose(1)
      > ///[/color]

      Thanks for the response HKW, but nope, I need a text file :). Sorry if
      that sounds abrupt.

      I'm trying to wwrite a 'small' program that will sort fonts into folders.
      I can locate the foundry and the designer of a particular font within the
      font file. What I want to do then is search the first element of the array
      for what I've found and then use the second element as the name of the
      folder into which to put the font. The reason, in particular, for the text
      variety is that I have a couple of friends who want to be able to
      manipulate the output folders.

      What I have so far looks like:[color=blue]
      > Using MyReader As New _
      > Microsoft.Visua lBasic.FileIO.T extFieldParser( "C:\fontmover\f oundries.txt")
      > MyReader.TextFi eldType = FileIO.FieldTyp e.Delimited
      > MyReader.SetDel imiters(Chr(9))
      > Dim currentRow As String()
      > While Not MyReader.EndOfD ata
      > Try
      > currentRow = MyReader.ReadFi elds()
      > Dim currentField As String
      > For Each currentField In currentRow[color=green][color=darkred]
      > >> this line arFoundry.add[intcounter,0]=currentrow[0][/color][/color]
      > MsgBox(currentF ield)
      > Next
      > Catch ex As Microsoft.Visua lBasic.FileIO.M alformedLineExc eption
      > MsgBox("Line " & ex.Message & _
      > "is not valid and will be skipped.")
      > End Try
      > End While
      > End Using[/color]
      Stolen right out of MSDN - but I can't see how to do the equivalent of
      somearray(index 1, index2) = somevalue
      I haven't felt the need to code anything for years - and this came up in
      discussion as an interesting exercise - that's about to drive me to the gin
      bottle!

      Appreciate any suggestions //al

      Comment

      Working...