MsWsII PRNG plus Help file

General FreeBASIC programming questions.
fxm
Moderator
Posts: 11132
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: MsWsII PRNG plus Help file

Post by fxm »

Only the non-static data members are stored/filled by Put/Get.

For the following UDT example, only the 'non_static_data' variable will be stored/filled by 'Put'/'Get' (the 'static_data' variable will not be impacted):

Code: Select all

Type UDT
    Dim As Integer non_static_data
    Static As Integer static_data
End Type
Dim As Integer UDT.static_data
deltarho[1859]
Posts: 3558
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: MsWsII PRNG plus Help file

Post by deltarho[1859] »

OK, my bad.

I still cannot see: 'This' can also be used as argument for writing all non-static data of an UDT instance.
fxm
Moderator
Posts: 11132
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: MsWsII PRNG plus Help file

Post by fxm »

deltarho[1859] wrote: May 24, 2022 8:35 @fxm

You did not use this phrase: 'This' can also be used as argument for writing all non-static data of an UDT instance.

but used '(including referenced by This)'.

The second one still needs a leap – not helpful.

The first one is better.
A sentence was added in the same paragraph for both 'Put' and 'Get' pages.
deltarho[1859]
Posts: 3558
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: MsWsII PRNG plus Help file

Post by deltarho[1859] »

fxm wrote:A sentence was added in the same paragraph for both 'Put' and 'Get' pages.
I have just flushed my internet cache and checked again. The 'sentence' is not there.
fxm
Moderator
Posts: 11132
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: MsWsII PRNG plus Help file

Post by fxm »

data
  • Is the buffer where data is written from. It can be a numeric variable, a string, an array or a user-defined type (including referenced by This). The operation will try to transfer to disk the complete variable, unless amount is given. For a user-defined type instance, the data impacted is only the non-static data members.
    .....
data
  • The buffer where data is written. It can be a numeric variable, a string, an array, a user defined type (including referenced by This), or a dereferenced pointer. The read operation will try to fill completely the variable, unless the EOF is reached. For a user-defined type instance, the data impacted is only the non-static data members.
    .....
deltarho[1859]
Posts: 3558
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: MsWsII PRNG plus Help file

Post by deltarho[1859] »

@fxm

I can see now why I couldn't find “'This' can also be used as argument for writing all non-static data of an UDT instance.” because you are not using it. :)

You have added another sentence which is OK, but we are still in the position when I wrote "I read those but, to my mind, requires quite a leap to realize that 'Put #f, , this', for example, is within those definitions."

It is still not obvious from the latest data paragraph that we can use 'Put #f, , this', for example.

It is not obvious to me – maybe I am being a bit thick.

I think that you are making the cardinal error that many Help authors make by over estimating the expertise of the reader. You are assuming that the reader fully understands 'This'. To my mind, we should always write to the lowest common denominator. Experts won't mind because at one time they belonged to the lowest common denominator.

If 'Put #f, , this' is not specifically referenced, many readers will not get it, especially newcomers.

At the bottom of Get and Put are some examples. It would be worthwhile to have an example showing 'this' being used.

If anyone thinks that I am being over critical with this post, then say so. Equally, if you agree with me, then say so.
fxm
Moderator
Posts: 11132
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: MsWsII PRNG plus Help file

Post by fxm »

I propose to add the following same example in the 'Put' and 'Get' documentation pages:

Code: Select all

' 'THIS' can be used as argument for writing/filling all non-static data of an UDT instance to/from a file

Type UDT
    Dim As String * 32 s
    Dim As Double d
    Declare Sub Save(Byref filename As String)
    Declare Sub Load(Byref filename As String)
End Type

Sub UDT.Save(Byref filename As String)
    Dim As Integer f
    f = Freefile()
    Open filename For Binary As #f
    Put #f, , This  '' writes all non-static data of the UDT instance to the file
    Close #f
End Sub

SUB UDT.Load(Byref filename As String)
    Dim As Integer f
    f = Freefile()
    Open filename For Binary As #f
    Get #f, , This  '' fills all non-static data of the UDT instance from the file
    Close #f
End Sub

Dim As UDT u1
u1.s = "PI number"
u1.d = 3.14159
u1.Save("file.ext")

Dim As UDT u2
u2.Load("file.ext")
Print u2.s
Print u2.d

[edit]
Done.
deltarho[1859]
Posts: 3558
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: MsWsII PRNG plus Help file

Post by deltarho[1859] »

That will do.

Thanks, fxm. :)
Post Reply