473,378 Members | 1,504 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,378 software developers and data experts.

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 7490

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Santah | last post by:
hi I'm new to C++ and I'm currently working on Visual C++ 6.0 I'm trying to open a text file, and read some data from it part of the text file looks like this: --------
20
by: ishmael4 | last post by:
hello everyone! i have a problem with reading from binary file. i was googling and searching, but i just cant understand, why isnt this code working. i could use any help. here's the source code:...
6
by: al jones | last post by:
I picked a good project to try to learn to use VS - and up till now everything has worked the way I expect. The code is from a VS.net class, which I picked up on the web, from which I've extracted...
1
by: Roob | last post by:
I am learning C# and was wandering if there is a straightforward way to read a binary file created by C++. For example, I have a data structure as follows: typedef struct _data time_t date;...
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;
16
by: Jm.GlezdeRueda | last post by:
Hi all, Im trying to read a 24bit bmp with fread, and i have some problems.. I want to read the whole structure in one time, but i dont know why, it only reads the first member well.. I have...
13
by: swetha | last post by:
HI Every1, I have a problem in reading a binary file. Actually i want a C program which reads in the data from a file which is in binary format and i want to update values in it. The file...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
6
by: Victory | last post by:
Hi, I need to know the compression type of jpeg (jpg) files. I am using the System.Drawing.Imaging and loading the file using an Image object. The next thing i do, is to examine the propertyItems...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.