468,134 Members | 1,273 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,134 developers. It's quick & easy.

Reading Structure from File

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.
Nov 19 '05 #1
3 7232

"Zahid" <mr******@hotmail.com> wrote in message
news:94****************************@phx.gbl...
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?
Nov 19 '05 #2
"Zahid" <mr******@hotmail.com> schrieb
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.

Nov 19 '05 #3
Hello,

"Zahid" <mr******@hotmail.com> schrieb:
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
--
MVP VB Classic, VB .NET
http://www.mvps.org/dotnet
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Santah | last post: by
6 posts views Thread by al jones | last post: by
1 post views Thread by Roob | last post: by
6 posts views Thread by arne.muller | last post: by
16 posts views Thread by Jm.GlezdeRueda | last post: by
13 posts views Thread by swetha | last post: by
6 posts views Thread by efrenba | last post: by
6 posts views Thread by Victory | last post: by
27 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.