[Gambas-user] File Format Help

Christof Thalhofer chrisml at deganius.de
Thu Jun 17 20:09:27 CEST 2021


Am 17.06.21 um 16:46 schrieb John Dovey:

> I hope no-one minds if I ask this here. I'm just really unsure how to do
> this best in Gambas. 
> I want to read and write files that have a (very old) specification
> <http://ftsc.org/docs/fts-0001.016>
> Essentially, it looks like this:
> 
>  1. Application Layer Data Definition : a Stored Message
> 
>                                Stored Message
> 
>        Offset
>       dec hex
>               .-----------------------------------------------.
>         0   0 |                                               |
>               ~                 fromUserName                  ~
>               |                   36 bytes                    |
>               +-----------------------+-----------------------+
>        36  24 |                                               |
>               ~                  toUserName                   ~
>               |                   36 bytes                    |
>               +-----------------------+-----------------------+
> I'm guessing a "Struct" of some sort? 
> 
> Any advice would be appreciated.

I would create a class for that with r/w properties that can be written
and controls the length when the Value is written.

-----------------------------------------------------------------

' Gambas class file

'' From User (max 36 Byte)
Property fromUserName As String
Private $fromUserName As String

'' To User (max 36 Byte)
Property toUserName As String
Private $toUserName As String


' -------------------------- Getter/Setter

Private Function fromUserName_Read() As String

    Return $fromUserName

End

Private Sub fromUserName_Write(Value As String)

    TestSize(Value, 36)
     $fromUserName = Value

End

Private Function toUserName_Read() As String

    Return $toUserName

End

Private Sub toUserName_Write(Value As String)

    TestSize(Value, 36)
     $toUserName = Value

End

Private Sub TestSize(Value As String, Size As Integer)

    If Len(Value) > Size Then
        Error.Raise("Size of string " & Value & " too large. Must not
exceed " & Size)
    Endif

End

Public Function Get() As String

    Return fromUserName & gb.lf & toUserName '... and so on

End

-----------------------------------------------------------------

Alles Gute

Christof Thalhofer

-- 
Dies ist keine Signatur


More information about the User mailing list