473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
Nov 26 '05 #1
2 1127
"al jones" <al**********@shotmail.com> schrieb:
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)
///

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

Nov 27 '05 #2
On Sun, 27 Nov 2005 14:00:41 +0100, Herfried K. Wagner [MVP] wrote:
"al jones" <al**********@shotmail.com> schrieb:
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)
///


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:\f ontmover\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.MalformedLineExceptio n
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
Nov 27 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Row | last post by:
HI, I would first like to say its been about 3 years since looking at java im very rusty! I have to write a post it notes type applet which will function online. (reading from a flat text file)...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
10
by: T Cordon | last post by:
I am using a StreamReader to read text from an HTML file and display it as part of a page in a Label Control. Buy it is not displaying characters as: ñ, ó, ú, etc. Please Help. Thanks
7
by: John Dann | last post by:
I'm trying to read some binary data from a file created by another program. I know the binary file format but can't change or control the format. The binary data is organised such that it should...
10
by: nuke1872 | last post by:
Hello guys, I have a file names network.txt which contains a matrix. I want to read this matrix as store it as an array. I am new to stuff like these...can anybody help me out !! Thanks nuke
1
by: bbepristis | last post by:
Hey all I have a wired issue I have a csv file with , seperated values I have some code to read the file and put the record into an array then into textboxes. the problem is it seems to read...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
2
by: GeoUK | last post by:
Hi All, New member here with a bit of problem. I have read the FAQ's and searched text books but still cannot solve the problem that I have. As part of a course I am doing at University I had...
21
by: Stephen.Schoenberger | last post by:
Hello, My C is a bit rusty (.NET programmer normally but need to do this in C) and I need to read in a text file that is setup as a table. The general form of the file is 00000000 USNIST00Z...
1
by: stoogots2 | last post by:
I have written a Windows App in C# that needs to read a text file over the network, starting from the end of the file and reading backwards toward the beginning (looking for the last occurrence of a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.