From: mp on

"Larry Serflaten" <serflaten(a)gmail.com> wrote in message
news:hvmded$edj$1(a)news.eternal-september.org...
>
> "GS" <gesansom(a)netscape.net> wrote
>
>> The line is correct. A text file contains only text unless the content
>> is binary. AFAIK, all text is String type. That means if you're storing
>> numbers or boolean values, for example, then you'll have to convert
>> them accordingly.
>
> The program has settings of different types of variables, and it uses them
> as those data types. The class stores the settings in an array of
> Variants.
> The variant will coerse the values to strings when they go out to the disk
> and will accept the values as strings when they are read back in. But
> the program can still use them as the original data type.
>
> Settings might be any scalar data type (eg. not objects or images, etc.)
> and in order for the class to store it, the class has to have a variable
> that can handle the data type. The Variant is VB's generic data type
> that handle any of the other data types, so an array of variants can
> be used to store all the settings.
>
> In other words, the class puts Evil Type Conversion to a good use.
>
> The only down side is that those are to be treated as settings, and not
> as variables. The program should only assign a value or retrieve a value
> from the class, and not use the class values in any math or other such
> combinations. To avoid the evil type conversion situations the program
> should put the value where it belongs (in a program variable of the proper
> data type) and perform the math or other combinations on it there.
>
>
> LFS
>
>
so it sounds to me like I *am* casting from string to whatever...even if i'm
letting ETC do it for me...i would prefer explicitly casting just for code
clarity and my own sanity...i've gotten too brainwashed into avoiding ETC
where possible...
:-)
mark


From: mp on

"GS" <gesansom(a)netscape.net> wrote in message
news:hvmbpe$983$1(a)news.eternal-september.org...
> mp presented the following explanation :
>> "GS" <gesansom(a)netscape.net> wrote in message
>> news:hvlqnp$64l$1(a)news.eternal-september.org...
>>> mp used his keyboard to write :
>>>> "Larry Serflaten" <serflaten(a)gmail.com> wrote in message
>>>> news:hvlijo$9n9$1(a)news.eternal-september.org...
>>>>>
>>>>> "mp" <nospam(a)Thanks.com> wrote
>>>>>
>>>>>> so FormSettings.ReadFile would just read a text file, parse the lines
>>>>>> with
>>>>>> split
>>>>>> and fill Data(n) accordingly?
>>>>>> that means i also have to cast strings to other datatypes if
>>>>>> req'd(longs,doubles,etc)
>>>>>> lots more code than one call to a get/put function :-)
>>>>>
>>>>> No extra typecasting code, Print and Line Input work with Variants.
>>>>> Your form sets the value, and Print sends it to the disk. Line Input
>>>>> reads it back from the disk and sets the value, just like your form
>>>>> does.
>>>>
>>>> from the help on Line Input
>>>> Reads a single line from an open sequential file and assigns it to a
>>>> string variable
>>>>
>>>> maybe that's also why i always thought of textfiles as containing
>>>> strings
>>>>
>>>> is that line in the help incorrect?
>>>
>>> The line is correct. A text file contains only text unless the content
>>> is binary. AFAIK, all text is String type. That means if you're storing
>>> numbers or boolean values, for example, then you'll have to convert them
>>> accordingly.
>>>
>>> -- Garry
>>>
>>> Free usenet access at http://www.eternal-september.org
>>> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>>>
>>
>> thats' what I had thought but Larry said I don't have to cast so I'm
>> confused.
>> mark
>
> I don't know what you mean by 'don't have to cast'! Larry has described
> another way to do what you want via a class module, where you can reuse it
> for any project.

right, in which he said the class would write to disk and read from. I was
talking about casting the string read from the text file back into a Long or
Int or whatever.


>I have described one way to handle UDTs that you use for every project, AND
>a way to handle project-specific UDTs as required by each project.

yes, very nice, I like the simplicity of writing and reading a udt with
get/put
I've just been figuring out the extent to which I can reduce duplicating
code.
If i have app specific udt i have to duplicate the Read/write function to
accept that specific UDT as input.
If I have generic data common to all progs, I can use a Utility UDT in a bas
module and don't have to duplicate the read/write functions for each program
that uses that data.

Larry's suggestion requires a bit more coding
> but, as he states, you only need to do it once and just import the class
> into your projects to use it.

yes, I like that too. They all have merits and I appreciate everyone who
has helped me learn the limitations and applications for each of the
different ways.
>
> What you need to decide is which of the two approaches works best for you.
> Also, you need to determine whether you want to Put/Get your data or use
> other means to save/load your UDT values.
>
yep
> I suspect a demo sample from Larry might be helpful, as I get the feeling
> you're treading in unkown territory here. I have never done it as Larry
> describes and so I have nothing to offer by way of a sample. -Sorry!

i made a little class to try his method, not bad at all. just have to tweak
the read/write functions a bit to clean it up.


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

thanks for all your help and suggestions
mark


From: GS on
Hi Larry,
I think the simplicity the OP is talking about is that the UDT values
are read into the UDT OR written from the UDT is a single process. I
believe what Mark find perplexing is the additional complexity that
bringing an array into the process causes. Basically, the array has to
be looped to put the values into the UDT, AND the UDT has to be llooped
(somehow) to put the values into the array. It sounds to me like he
doesn't want to do that.

Could he not just pass a ByRef to the UDT into the class so it works
with that instead of an array of variants?

--
Garry

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


From: GS on
Mark,
You don't have to duplicate anything! You can just expand on the sample
I gave you for processing the 3 UDTs I use in every project, on an 'as
needed' basis. So, unless Larry comes up with some way to pass the UDT
ByRef to the class, you'll have to settle for using the array of
variants.

--
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:hvmq3m$quu$1(a)news.eternal-september.org...
> Mark,
> You don't have to duplicate anything! You can just expand on the sample I
> gave you for processing the 3 UDTs I use in every project, on an 'as
> needed' basis. So, unless Larry comes up with some way to pass the UDT
> ByRef to the class, you'll have to settle for using the array of variants.
>
> --
> Garry
>
> Free usenet access at http://www.eternal-september.org
> ClassicVB Users Regroup! comp.lang.basic.visual.misc
>
>

I'm clear that there are two ways to store the data, udt or class.
I've tried them both and like them both.
I'm trying the class for now and am reading and writing the values to disk,
but the form is not taking it's last saved position for some reason.
start program
class reads values from disk (top, left, height, width)
form assigns it's properties to those values
this should put it where it was when last closed, but it never moves, always
appears in default position...don't know what i'm doing wrong
guess this is evolving into a different thread?
'in form initialize
Private Sub Form_Initialize()
'snip error trapping and logging calls
Set FormSettings = New cFormSettings
FormSettings.Filename = App.Path & "FormSettings.txt"

'read former form position and size from file
FormSettings.ReadFile

'this should make the form move to where it was before, but it doesn't
Me.Left = FormSettings.Values(eSettings.FormLeft)
Me.Top = FormSettings.Values(eSettings.FormTop)
Me.Width = FormSettings.Values(eSettings.FormWidth)
Me.Height = FormSettings.Values(eSettings.FormHeight)

ExitHere:
'Form_Initialize = bSuccess

ProcEnd ProcName
On Error GoTo 0
Exit Sub

Form_Initialize_Error:
LogError , ProcName
Resume ExitHere


End Sub
'in form resize
Private Sub Form_Resize()
ResizeFolderViews'adjust controls

'get new form location values into class
FormSettings.Values(FormLeft) = Me.Left
FormSettings.Values(FormWidth) = Me.Width
FormSettings.Values(FormHeight) = Me.Height
FormSettings.Values(FormTop) = Me.Top

End Sub

'in form terminate
Private Sub Form_Terminate()
'leaving out error trapping and logging code
FormSettings.WriteFile 'class writes values to file
Set FormSettings = Nothing
ExitHere:
Unload Me
On Error GoTo 0
Exit Sub
End Sub