From: GS on
mp formulated the question :
> "Mayayana" <mayayana(a)invalid.nospam> wrote in message
> news:hvaidu$td0$1(a)news.eternal-september.org...
>> I'm using a method I like a lot. I think I
>> originally got the idea from Larry Serflaten.
>>
>> It turns out that a UDT can be read from/written
>> to disk as a binary file. Despite the string values
>> being pointers, VB will nevertheless write all data
>> stored in the UDT in serial fashion!
>>
>> So I declare a large UDT in the program to hold
>> various settings of all types. At startup I fill the
>> UDT by reading in a settings.dat binary file. If the
>> file isn't there I write it with an empty UDT, which
>> accords with default settings. At program close I
>> write the current UDT to disk. During operation I
>> refer to the UDT members to get or change settings
>> values.
>>
>> It's a very clean, simple method with room for
>> expansion, and it provides intellisense at design
>> time for referencing settings variables.
>>
>
>
> hmm sounds interesting
> you don't have a small sample you'd be willing to share by chance?
> (just the write udt to disk, read udt from disk part)
> thanks
> mark

That's pretty much what I do. Works very well (as Mayayana says).
Here's the code to use:

To read into UDT:
On Error GoTo ErrHandler
Open FileName For Binary As #1
Get #1, , Data

ErrHandler:
Close #1

To write UDT to file:
On Error GoTo ErrHandler
Open FileName For Binary As #1
Put #1, , Data

ErrHandler:
Close #1

I actually use a single procedure where I pass a boolean arg that flags
whether I'm reading or writing. So the resulting code would be:
On Error GoTo ErrHandler
Open FileName For Binary As #1
If bReadingData Then Get #1, , Data Else Put #1, , Data


ErrHandler:
Close #1

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


From: mp on

"GS" <gesansom(a)netscape.net> wrote in message
news:hvb593$4qu$1(a)news.eternal-september.org...
> mp formulated the question :
>> "Mayayana" <mayayana(a)invalid.nospam> wrote in message
>> news:hvaidu$td0$1(a)news.eternal-september.org...
>>> I'm using a method I like a lot. I think I
>>> originally got the idea from Larry Serflaten.
>>>
>>> It turns out that a UDT can be read from/written
>>> to disk as a binary file. Despite the string values
>>> being pointers, VB will nevertheless write all data
>>> stored in the UDT in serial fashion!
>>>
>>> So I declare a large UDT in the program to hold
>>> various settings of all types. At startup I fill the
>>> UDT by reading in a settings.dat binary file. If the
>>> file isn't there I write it with an empty UDT, which
>>> accords with default settings. At program close I
>>> write the current UDT to disk. During operation I
>>> refer to the UDT members to get or change settings
>>> values.
>>>
>>> It's a very clean, simple method with room for
>>> expansion, and it provides intellisense at design
>>> time for referencing settings variables.
>>>
>>
>>
>> hmm sounds interesting
>> you don't have a small sample you'd be willing to share by chance?
>> (just the write udt to disk, read udt from disk part)
>> thanks
>> mark
>
> That's pretty much what I do. Works very well (as Mayayana says). Here's
> the code to use:
>
> To read into UDT:
> On Error GoTo ErrHandler
> Open FileName For Binary As #1
> Get #1, , Data
>
> ErrHandler:
> Close #1
>
> To write UDT to file:
> On Error GoTo ErrHandler
> Open FileName For Binary As #1
> Put #1, , Data
>
> ErrHandler:
> Close #1
>
> I actually use a single procedure where I pass a boolean arg that flags
> whether I'm reading or writing. So the resulting code would be:
> On Error GoTo ErrHandler
> Open FileName For Binary As #1
> If bReadingData Then Get #1, , Data Else Put #1, , Data
>
>
> ErrHandler:
> Close #1
>
> HTH
>
> --
> Garry
>
> Free usenet access at http://www.eternal-september.org
> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>
>

wow, you're kidding...it's that simple?!
you're implying Data is the udt?
something like:

Public Type tData
value1 As String
value2 As String
value3 As Long
value4 As Double
End Type

Sub test()
Dim thisData As tData
Dim FileName As String
FileName = "C:\testData"

With thisData
..value1 = "Test"
..value2 = "This out"
..value3 = 7
..value4 = 0.05
End With

On Error GoTo ErrHandler
Open FileName For Binary As #1
Put #1, , thisData

ErrHandler:
Close #1

End Sub

amazing! that works...very cool
thanks
mark
ps does the filename typically get any particular extension...obviously it
works even without one...
what do people typically do...make up their own extension per the app and
usage?



From: GS on
> wow, you're kidding...it's that simple?!
> you're implying Data is the udt?

Yes!

> something like:
>
> Public Type tData
> value1 As String
> value2 As String
> value3 As Long
> value4 As Double
> End Type
>
> Sub test()
> Dim thisData As tData
> Dim FileName As String
> FileName = "C:\testData"
>
> With thisData
> .value1 = "Test"
> .value2 = "This out"
> .value3 = 7
> .value4 = 0.05
> End With
>
> On Error GoTo ErrHandler
> Open FileName For Binary As #1
> Put #1, , thisData
>
> ErrHandler:
> Close #1
>
> End Sub

Well, I'd put the read/write process in a reusable sub/function so that
your other app procedures can simply use the UDT values during runtime
(as Mayayana suggests), and just read at startup and write at shutdown.

>
> amazing! that works...very cool
> thanks
> mark

You're welcome!

> ps does the filename typically get any particular extension...obviously it
> works even without one...
> what do people typically do...make up their own extension per the app and
> usage?

As Mayayana suggests, usually this type of file uses the ".dat"
extension, but it can be whatever you want (ie: with or without an
extension: "AppData", "AppData.dat", "Settings.MyAppdat",...). Note
that any case can be used: "appdata", "appdata.DAT",
"settings.myappdat"!


--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


From: mp on

"GS" <gesansom(a)netscape.net> wrote in message
news:hvb8pr$jf7$1(a)news.eternal-september.org...
>> wow, you're kidding...it's that simple?!
>> you're implying Data is the udt?
>
> Yes!
>
>> something like:
>>
>> End Sub
>
> Well, I'd put the read/write process in a reusable sub/function so that
> your other app procedures can simply use the UDT values during runtime (as
> Mayayana suggests), and just read at startup and write at shutdown.
>
>>

right that was just a test

>
> You're welcome!
>
>> ps does the filename typically get any particular extension...obviously
>> it works even without one...
>> what do people typically do...make up their own extension per the app and
>> usage?
>
> As Mayayana suggests, usually this type of file uses the ".dat" extension,
> but it can be whatever you want (ie: with or without an extension:
> "AppData", "AppData.dat", "Settings.MyAppdat",...). Note that any case can
> be used: "appdata", "appdata.DAT", "settings.myappdat"!
>
>

very nice!
thanks again
mark


From: Mayayana on

|
| there is nothing in this world i *fully* understand

Aha. A wiseman has arrived on the scene. :)