Re: Read a file a line at a time from memory
- From: jcrouse1@xxxxxxxxxxx
- Date: 4 Aug 2006 14:29:58 -0700
Rick
Thanks for all your help and advice the last few days. A little
background, I am a forum moderator and spend about 10 hours a week
reply to posts and I am continually asking the author for more
information. However, until you get a feel for the forum sometimes this
is bad because people will avoid the longer posts. I will try and give
more information here, from now on. Also, believe it or not, I used to
teach VB6 at a local CC about 7 or 8 years ago. It was just an
introductory course but I have many hours with the basics. I however,
haven't looked at VB6 in years and now use .Net. Man, is it nice going
back to VB6.
Anyways, again, thanks for your help. I will have a few more questions
in the next day or two.
John
Rick Rothstein wrote:
OK .... I will start giving more information. Here is a sniplet from
the file I want to read in.
276
63
12
76
True
16777215
Transparent
Arial
6
True
False
Center
This is part of the GDI layout designer I mentioned in a post a few
days ago. The layout designer contains 64 labels that the user can
place, size and set attributes for. The parameters are then all
written to a file. The above sniplet is the information for one label.
As you can guess, top, left, height, width and so forth. Remember,
there are 64 labels. Since I wrote the file I know the exact line each
piece of information resides on.
Now The program also has a viewer. It is the app that I'm working on
now. It need to be able to read the above file and the adjust it's
label properties accordingly.
I also have to populate the captions for all the labels. That is going
to be done in the exact same manner, once I get this figured out.
I did read the file into a variable array but thought that might be
slower. I had a heck of a time dimensioning the array. I actually did
two loops. One to tell how many lines were in the file (the size of the
second file, example not shown, could change). Then I did a ReDim and
then looped through again to populate the array.
The first thing you need to do is create a dynamic array to house the
individual lines from the file. To do this, you need to Dim the dynamic
array somewhere within your code; where depends on the scope you want for
it, but I am guessing you will want it in the (General)(Declarations)
section of the form (in order for any procedure emanating from the form to
have access to its content) or in a Module (so that any procedure on any
form can access it). Here is the Dim statement that you need...
Dim Lines() As String
where I have chosen to name the dynamic array Lines. Now, in the code I
originally posted, right after you load the entire file into the TotalFile
variable, you can populate the Lines array like this...
Lines = Split(TotalFile, vbCrLf)
Now, the first line from the file is in Lines(0), the second line is in
Lines(1) and so on... note that the Nth line in the file is located in
Lines(N). If I understand correctly, you can now find and use any piece of
data you want... no double loops, no single loops, basically one additional
line over what I posted originally.
The key thing you should take away from this exchange is that when you ask
questions on the newsgroups, give us as much information as you can about
your problem and include details about data you have, what you want from it,
what you have done, what has not happened the way you wanted, error messages
if any, snippets of code that you have tried, etc. If you don't hide
information from us, we can craft our answers to meet your needs. If, on the
other hand, you don't tells as much as you can, then all we can do is answer
the question you asked (even if it is the "wrong" question for what you
ultimately want).
Rick
.
- Follow-Ups:
- Re: Read a file a line at a time from memory
- From: jcrouse1
- Re: Read a file a line at a time from memory
- References:
- Read a file a line at a time from memory
- From: jcrouse1
- Re: Read a file a line at a time from memory
- From: Rick Rothstein
- Re: Read a file a line at a time from memory
- From: jcrouse1
- Re: Read a file a line at a time from memory
- From: Rick Rothstein
- Read a file a line at a time from memory
- Prev by Date: Re: VBA does not save references from one run to the next
- Next by Date: Re: Error trying to kill a database from vb6 program
- Previous by thread: Re: Read a file a line at a time from memory
- Next by thread: Re: Read a file a line at a time from memory
- Index(es):
Relevant Pages
|