accessing data in external file?

  • Thread starter Thread starter Geoff Cox
  • Start date Start date
G

Geoff Cox

Hello,

Just starting C# with MS Visual Studio Pro 2005 ...

How do I access array data which is in an external file? I would
prefer to have it there to make the code less cluttered..

Thanks

Geoff
 
Geoff,

How are you storing the data in the file? Can you provide a sample of
the file?

The first recommendation would be to use the FileStream class to open
the file for reading. Once you have that, you can use the BinaryReader
class to read primary type information from the file (assuming you wrote the
file in a format that the BinaryReader can understand).

Hope this helps.
 
Geoff,

How are you storing the data in the file? Can you provide a sample of
the file?

Nicholas,

The idea is to have a series of statements, the left hand side and the
right hand side statements, for each of several situations, eg

var lhs_0 = new Array(8)
lhs_0[0]="situation 1 lhs statement 1";
lhs_0[1]="situation 1 lhs statement 2";
etc

var rhs_0 = new Array(8)
rhs_0[0]="situation 1 rhs statement 1";
rhs_0[1]="situation 1 rhs statement 2";
etc

var lhs_1 = new Array(8)
lhs_1[0]="situation 2 lhs statement 1";
lhs_1[1]="situation 2 lhs statement 2";
etc

var rhs_1 = new Array(8)
rhs_1[0]="situation 2 rhs statement 1";
rhs_1[1]="situation 2 rhs statement 2";
etc

Cheers

Geoff
 
Geoff,
the "var" keyword doesn't come out until C# 3.0, so we can only assume that
this is Javascript. How about storing your data in some sort of CSV format
with delimiters which would be easier to parse?
Or, you could make the array a member of a serializable class, serialize the
class to a byte array using the BinaryFormatter class, and save it as a
binary file. This would be much easier to read back and deserialize into the
class.
Peter


--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Geoff Cox said:
Geoff,

How are you storing the data in the file? Can you provide a sample of
the file?

Nicholas,

The idea is to have a series of statements, the left hand side and the
right hand side statements, for each of several situations, eg

var lhs_0 = new Array(8)
lhs_0[0]="situation 1 lhs statement 1";
lhs_0[1]="situation 1 lhs statement 2";
etc

var rhs_0 = new Array(8)
rhs_0[0]="situation 1 rhs statement 1";
rhs_0[1]="situation 1 rhs statement 2";
etc

var lhs_1 = new Array(8)
lhs_1[0]="situation 2 lhs statement 1";
lhs_1[1]="situation 2 lhs statement 2";
etc

var rhs_1 = new Array(8)
rhs_1[0]="situation 2 rhs statement 1";
rhs_1[1]="situation 2 rhs statement 2";
etc

Cheers

Geoff








The first recommendation would be to use the FileStream class to open
the file for reading. Once you have that, you can use the BinaryReader
class to read primary type information from the file (assuming you wrote the
file in a format that the BinaryReader can understand).

Hope this helps.
 
Geoff,
the "var" keyword doesn't come out until C# 3.0, so we can only assume that
this is Javascript. How about storing your data in some sort of CSV format
with delimiters which would be easier to parse?

Peter,

Yes, you are correct, I am trying to make a C# version of some
javascript code. At the time I could not find a slider control. I was
using Visual Web Developer 2005 Express at that time.
Or, you could make the array a member of a serializable class, serialize the
class to a byte array using the BinaryFormatter class, and save it as a
binary file. This would be much easier to read back and deserialize into the
class.

Could you point me at info re how to make the array a member of a
serializable class etc?

Cheers

Geoff
 
Back
Top