Re: Put Variables giving problems
From: Khai (middae_at_hotmail.com)
Date: 01/25/05
- Next message: Khai: "Re: Keeping Focus on form"
- Previous message: Russ Holsclaw: "Re: Put Variables giving problems"
- In reply to: Russ Holsclaw: "Re: Put Variables giving problems"
- Next in thread: Russ Holsclaw: "Re: Put Variables giving problems"
- Reply: Russ Holsclaw: "Re: Put Variables giving problems"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 25 Jan 2005 12:15:31 -0600
You don't frighten me - you gave me what i needed. One last question though
If I have Name as String * 30, that's a String fixed at 30 characters. I
assign Name = "John" that only uses 4. Does it store name as "
John", or "John "?
And - I would actually prefer to get it into a database that Access2000
could read also, so I could make manual changes to the file itself without
mussing it up. The file itself would be a new unique file each day (it uses
the date in the name). So, mostly, it'll be pretty small. My second
program is going to read it, make a change to a specific part of the
record, log it in an excel spread***, then put it back in the file, so if
I ever open that one up again, I can see what's been acted on and what
hasn't.
Thank you, Russ, for your info. =D
"Russ Holsclaw" <russ@holsclaw.nyet> wrote in message
news:%23$9K8gwAFHA.1400@TK2MSFTNGP11.phx.gbl...
>
> "Khai" <middae@hotmail.com> wrote in message
> news:EfqdnSxU_sI38GvcRVn-uw@comcast.com...
> >I don't know how to "link" my posts to another newsgroup, but - this
> >Syntax
> > one seems more like where the original post is supposed to be. I'm
sorry
> > for crossposting, but noone's answered the others anyway. ;)
> >
> > Assume Word 2000 VBA.
> >
> > myDataType
> > Name as string
> > phone as string
> > appdate as Date
> > codes(15) of String
> > end type
> >
> > dim myR as myDataType
> > dim myF as integer
> >
> > myF = Freefile
> >
> > ----
> > at this point, I've tried several methods and combinations of Open,
> > Append,
> > random, etc.
> >
> > The only success I've had is when myDataType is very small, then Opening
> > for
> > Random, with a Len = Len(myR). Finding out how to append to it was a
bit
> > more difficult, because each variant i tried of Put, recnum, myR would
> > come
> > up with "Bad record space" or somesuch.
> >
> > myDataType has about 16 strings in it, and 4 dates. Then there's one
> > array
> > of 16 slots, that are strings. the array will not always be full.
> >
> > Am I just missing something? Everytime I try the Open "C:\testfile.txt"
> > for
> > Append Access ... it tells me "bad file mode" when I try to put. Random
> > was
> > the only that got me close, and it doesn't work with the larger
datatype.
> >
> > Is this the wrong way I should go about it? Should I use ADO instead?
> > and
> > if I do that, what's the quickest way to get an understanding of it?
> >
> > The object is to write these datatypes that are based off the data in
the
> > Word Document Merge Source, then - another program would open that
> > database
> > file (or file of myDataTypes), and do something else with it.
>
>
> The problem you have with Random is that your UDT structure is of fixed
> size, and Random files are assumed to have fixed-length records. That is,
> each record is assumed to be the same size, or at least confined to some
> known limit.
>
> Since your "codes" array consists of a set of variable-length strings,
they
> will be written to a Random file as a set of variable-size elements, each
> preceded by a "string descriptor" which gives the length.
>
> Your other String variables have the same problem.
>
> If you really want to use Random, all of your strings should be
> fixed-length, such as:
>
> Type myDataType
> Name as string * 30 '
> phone as string * 13 '...as in "(xxx)xxx-xxxx"
> '(larger if international)
> appdate as Date 'date is always 8 bytes
> codes(15) as String * 2 '...or however long your codes are
> End type
>
> This type of structure will work with Random.
>
> The alternative, if you don't want to use fixed strings, is to use a
Binary
> file. In this case, however, each time you do a Put of one of your data
> types, the size of the output will be variable, and you will
> have to read them sequentially, starting with the first record, and
> you will somehow have to know how many records there are. This
> can be done by writing a record-count at the beginning of the file.
> The record-count value can be written at the start of the file as
> the last thing you write, before closing the file. Then, the code that
> reads the file will know when to stop reading. There is no EOF()
> function for Random or Binary files. You simply must record information
> in the file that helps the program that's reading it "know" what
> to expect. This requires a certain amount of planning, and
> knowing what you're doing.
>
> A file with fixed-length records (a Random file, that is) has the
> advantage that individual records can be updated in place without
> disturbing the surrounding data. A binary file with variable-length
> records, on the other hand, should usually be written and read in
> its entirety, in some carefully-planned sequence, so that it can
> properly be interpreted by the program reading it.
>
> Another little problem, in the case of VB, is that the core VB language
> provides no way to reduce the size of the file, if updated contents
> require less space than was consumed earlier. Ordinarily, and Random or
> Binary file can only get larger, never smaller. There are API functions
> you can use to "shrink" the file, but this must be considered
> "advanced" programming.
>
> If all this is more complicated than you bargained for, you should
> consider using a database engine, such as Jet, that handles
> the ugly details for you. Even Jet files must be compressed from
> time to time, and your program should include the function of
> running the compression functions of Jet, if you go that route.
>
> Learning to write and read binary files can be very educational for
> you, especially if you are new to computer programming. But don't
> expect very much to be done automatically for you. It isn't. The
> overall organization and layout of the file is entirely your
> own responsibility. There is no magic. If you don't know what you're
> doing, you can easily create a file that can not be successfully
> read back in using any deterministic algorithm. If this happens, you
> have only yourself to blame, not VB.
>
> If this frightens you a little, then I have achieved my purpose.
>
- Next message: Khai: "Re: Keeping Focus on form"
- Previous message: Russ Holsclaw: "Re: Put Variables giving problems"
- In reply to: Russ Holsclaw: "Re: Put Variables giving problems"
- Next in thread: Russ Holsclaw: "Re: Put Variables giving problems"
- Reply: Russ Holsclaw: "Re: Put Variables giving problems"
- Messages sorted by: [ date ] [ thread ]