Reading Structure from File

  • Thread starter Thread starter Zahid
  • Start date Start date
Z

Zahid

Hi,

I have declared an array holding a custom declared
structure. The structure looks like this:

Private Structure MnuDataFrmFile
Public menuGroup As String
Public ItemDesc As String
Public ItemPrice As Integer
Private PluValue As Integer
Private rgbR As Integer
Private rgbG As Integer
Private rgbB As Integer
Private buttonSize As String
End Structure

Array of Structure:
Dim HoldsAllItems() As MnuDataFrmFile

I want to read out from a file one line at a time. Each
line will populate the structure eaxactly. Currently Im
reading out from the file using:

Dim Item As String
Dim StreamToDisplay As StreamReader
StreamToDisplay = New StreamReader("c:\allitems.txt")
Item = StreamToDisplay.ReadLine()

The problem is that each line is read as a string from
the file. My Structure has differing data types such as
string and integers.

How can I read a line from the file and populate the
Structure with the line split into the elements of the
structure (hence the correct datatypes)?

Urgent, Please help.

Thanks in advance.
 
Zahid said:
Hi,

I have declared an array holding a custom declared
structure. The structure looks like this:

Private Structure MnuDataFrmFile
Public menuGroup As String
Public ItemDesc As String
Public ItemPrice As Integer
Private PluValue As Integer
Private rgbR As Integer
Private rgbG As Integer
Private rgbB As Integer
Private buttonSize As String
End Structure

Array of Structure:
Dim HoldsAllItems() As MnuDataFrmFile

I want to read out from a file one line at a time. Each
line will populate the structure eaxactly. Currently Im
reading out from the file using:

Dim Item As String
Dim StreamToDisplay As StreamReader
StreamToDisplay = New StreamReader("c:\allitems.txt")
Item = StreamToDisplay.ReadLine()

The problem is that each line is read as a string from
the file. My Structure has differing data types such as
string and integers.

How can I read a line from the file and populate the
Structure with the line split into the elements of the
structure (hence the correct datatypes)?

Urgent, Please help.

Thanks in advance.
.

I'm a C# man - but why don't you serialize the objects to file instead?
 
Zahid said:
Private Structure MnuDataFrmFile
Public menuGroup As String
Public ItemDesc As String
Public ItemPrice As Integer
Private PluValue As Integer
Private rgbR As Integer
Private rgbG As Integer
Private rgbB As Integer
Private buttonSize As String
End Structure


How can I read a line from the file and populate the
Structure with the line split into the elements of the
structure (hence the correct datatypes)?

Depends on how you wrote it into the file.

Have a look at:

Visual Studio.NET
Visual Basic and Visual C#
Reference
Visual Basic language
Tour through Visual Basic
Processing drives, folders and files
File access with Visual Basic runtime functions
-> Direct file access


Direct link to topic above for VS 200*3*:

ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB/vbcn7/html/vbconRandomFileAccess.h
tm

(see hints in signature)



--
Armin

- Links might be split into two lines. Concatenate them using notepad.
- Links might require to add a ".nnnn" after the "2003FEB", e.g.
"2003FEB.1033" for localized versions.
- Links starting with "ms-help" are URLs for the document explorer (<F1>).
Paste them in the URL textbox and press enter. Using internal help (menu
extras -> options -> environment -> help), display the "Web" toolbar that
contains the textbox.
- The tree representing the table of contents has been translated from
localized (German) version. Excuse slight deviations.
 
Hello,

Zahid said:
I have declared an array holding a custom declared
structure. The structure looks like this:

Private Structure MnuDataFrmFile
Public menuGroup As String
Public ItemDesc As String
Public ItemPrice As Integer
Private PluValue As Integer
Private rgbR As Integer
Private rgbG As Integer
Private rgbB As Integer
Private buttonSize As String
End Structure

Array of Structure:
Dim HoldsAllItems() As MnuDataFrmFile

I want to read out from a file one line at a time. Each
line will populate the structure eaxactly. Currently Im
reading out from the file using:

Have a look in the docs for:

FileOpen
FileGet
FilePut
FileClose
VBFixedStringAttribute

Regards,
Herfried K. Wagner
 
Back
Top