Reading two dim array from text file

  • Thread starter Thread starter al jones
  • Start date Start date
A

al jones

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
 
al jones said:
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.

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.ReadWrite)
FilePut(1, a, 1)
Dim b(2, 2) As String
FileGet(1, b, 1)
FileClose(1)
///
 
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.ReadWrite)
FilePut(1, a, 1)
Dim b(2, 2) As String
FileGet(1, b, 1)
FileClose(1)
///

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:
Using MyReader As New _
Microsoft.VisualBasic.FileIO.TextFieldParser("C:\fontmover\foundries.txt")
MyReader.TextFieldType = FileIO.FieldType.Delimited
MyReader.SetDelimiters(Chr(9))
Dim currentRow As String()
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
this line arFoundry.add[intcounter,0]=currentrow[0]
MsgBox(currentField)
Next
Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
MsgBox("Line " & ex.Message & _
"is not valid and will be skipped.")
End Try
End While
End Using
Stolen right out of MSDN - but I can't see how to do the equivalent of
somearray(index1, 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top