Filling a Structure Automatically

Filling a Structure Automatically

After a structure is defined witha “TYPE” declaration, do you know of a way to directly fillthe structure with data, rather than individually assigingthe elements, or reading from a file? I haven’t seen anyway in either the manuals, or in 4 different after marketreference books that I have.

Note: This answer came from the person who asked the question.

I used the code:

        TYPE StructType                ‘/* setup stucture of type char */                a AS STRING * 1                b AS STRING * 1                c AS STRING * 1                d AS STRING * 1        END TYPE        DIM Structure as StructType        ‘/* find the address of the first element */        ptrData& = VARPTR(Structure)        ‘/* then, if I know the structure elements size, */        ‘/*         I can POKE data into them */        Test$=”1234″        ‘/* place the ASCII representation of each char into structure */        for i% = 1 to len(Structure)                POKE i% + ptrStructure& – 1, ASC(MID$(Test$,i%,1))        NEXT        ‘/* display the elements */        PRINT CHR$(Structure.a)        PRINT CHR$(Structure.b)        PRINT CHR$(Structure.c)        PRINT CHR$(Structure.d)


Share the Post: