Menu

Structures

jackjames
2023-01-22
2023-02-03
  • jackjames

    jackjames - 2023-01-22

    It's a real shame that GCB doesn't support structs.
    I solved it by creating an array and assigning each element a name as in the example:

    Structure in Mikrobasic:
    Structure StrutturaDatiMiaCod
    Dim Unit As Byte ' Unità di appartenenza
    Dim Ind1 As Byte ' Indirizzo 1 RX
    Dim Ind2 As Byte ' Indirizzo 2 RX
    Dim Comando As Byte ' Comando trasmesso
    Dim Param1 As Byte ' Parametro N° 1
    Dim Param2 As Byte ' Parametro N° 2
    Dim Param3 As Byte ' Parametro N° 3
    Dim Param4 As Byte ' Parametro N° 4
    Dim Param5 As Byte ' Parametro N° 5
    Dim Param6 As Byte ' Parametro N° 6
    Dim Sequenza As Byte ' Numero Sequenza trasmessa
    Dim CRC As Byte ' CRC
    End Structure
    ' -
    ' Dim Record As StrutturaDatiMiaCod

    Pseudo-Strucure:
    Dim Record (12) As Byte

         #Define DATI_UNIT     Record (0)
        #Define DATI_IND1     Record (1)
        #Define DATI_IND2     Record (2)
        #Define DATI_COMANDO  Record (3)
        #Define DATI_PARAM1   Record (4)
        #Define DATI_PARAM2   Record (5)
        #Define DATI_PARAM3   Record (6)
        #Define DATI_PARAM4   Record (7)
        #Define DATI_PARAM5   Record (8)
        #Define DATI_PARAM6   Record (9)
        #Define DATI_SEQUENZA Record (10)
        #Define DATI_CRC      Record (11)
    

    In this way I can memorize or transmit in sequence the data that interest me.
    And it's even easier to manipulate them by referring to the mnemonic name.
    The only downside is that I can't use strings, but I want to work on them.
    Using bytes of the array for strings is possible, but it becomes difficult then to be able to address, read and write them as easily as it is done for numeric variables.
    Any idea about it?

     
  • Anobium

    Anobium - 2023-01-23

    Structures would be useful. This would be a good upgrade in the future.


    An idea. There must be some way of making this happen with a Function() and a within the Function() a select case. The select case would return the number(0) or the string(1) so you calling code would know how to handle.

     
  • Fulvio _

    Fulvio _ - 2023-02-03

    Such a structure is rather simple, as long as the data are uniform, But for the user it should need to know every pointer on that array. Because that looks like a simple array.

    So it could be possible to use aliases for each array field, but for a different number of byte of any field that would pose more difficulties.
    So there could be something like:

    Dim DATI_UNIT as byte at array(1)
    Dim DATI_IND1 as byte at array(2)
    Dim DATI_GRANDI as Word at array(3)
    

    But I not familiar with the compiler yet.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.