Use an array in a user-defined TYPE in QBasic











up vote
0
down vote

favorite












I'm trying to learn QBasic. In one of my program, I use several user-defined types, sometimes TYPE arrays. In some of them, I want to declare an array like this :



TYPE TestType
dataArray AS STRING * 4 'Since "dataArray AS _BYTE * 4" doesn't work (wrong syntax compiler says).
END TYPE


I then declare my type like this :



DIM customType(2) AS TestType


And as soon as I want to write in my type's dataArray like this :



customType(1).dataArray(2) = 3


The compiler tells me it is an invalid syntax.



Then, how to store an array in a defined TYPE?
And how to use it?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I'm trying to learn QBasic. In one of my program, I use several user-defined types, sometimes TYPE arrays. In some of them, I want to declare an array like this :



    TYPE TestType
    dataArray AS STRING * 4 'Since "dataArray AS _BYTE * 4" doesn't work (wrong syntax compiler says).
    END TYPE


    I then declare my type like this :



    DIM customType(2) AS TestType


    And as soon as I want to write in my type's dataArray like this :



    customType(1).dataArray(2) = 3


    The compiler tells me it is an invalid syntax.



    Then, how to store an array in a defined TYPE?
    And how to use it?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to learn QBasic. In one of my program, I use several user-defined types, sometimes TYPE arrays. In some of them, I want to declare an array like this :



      TYPE TestType
      dataArray AS STRING * 4 'Since "dataArray AS _BYTE * 4" doesn't work (wrong syntax compiler says).
      END TYPE


      I then declare my type like this :



      DIM customType(2) AS TestType


      And as soon as I want to write in my type's dataArray like this :



      customType(1).dataArray(2) = 3


      The compiler tells me it is an invalid syntax.



      Then, how to store an array in a defined TYPE?
      And how to use it?










      share|improve this question













      I'm trying to learn QBasic. In one of my program, I use several user-defined types, sometimes TYPE arrays. In some of them, I want to declare an array like this :



      TYPE TestType
      dataArray AS STRING * 4 'Since "dataArray AS _BYTE * 4" doesn't work (wrong syntax compiler says).
      END TYPE


      I then declare my type like this :



      DIM customType(2) AS TestType


      And as soon as I want to write in my type's dataArray like this :



      customType(1).dataArray(2) = 3


      The compiler tells me it is an invalid syntax.



      Then, how to store an array in a defined TYPE?
      And how to use it?







      arrays qbasic qb64






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 2 days ago









      Maxime Beasse

      137




      137
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          There are two issues here. In QB64 you simply can't put arrays inside of user defined types. According to the QB64 Wiki's article on TYPE definitions:




          TYPE definitions cannot contain Array variables! Arrays can be DIMensioned as a TYPE definition.




          Besides that, your dataArray (declared dataArray AS STRING * 4) does not declare an array at all, but rather, declares a 4 character string. That's why you get a syntax error when you try to access elements of dataArray using array syntax. You can declare an array consisting of a custom type, like so:



          TYPE TestType
          dataElement AS _BYTE
          END TYPE

          DIM CustomType(4) AS TestType

          CustomType(1).dataElement = 3


          This declares a 4 element array of TYPE TestType, each element containing a variable of TYPE _BYTE. That's about as close as you can get to what you're trying to do. Good luck!






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410020%2fuse-an-array-in-a-user-defined-type-in-qbasic%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            0
            down vote













            There are two issues here. In QB64 you simply can't put arrays inside of user defined types. According to the QB64 Wiki's article on TYPE definitions:




            TYPE definitions cannot contain Array variables! Arrays can be DIMensioned as a TYPE definition.




            Besides that, your dataArray (declared dataArray AS STRING * 4) does not declare an array at all, but rather, declares a 4 character string. That's why you get a syntax error when you try to access elements of dataArray using array syntax. You can declare an array consisting of a custom type, like so:



            TYPE TestType
            dataElement AS _BYTE
            END TYPE

            DIM CustomType(4) AS TestType

            CustomType(1).dataElement = 3


            This declares a 4 element array of TYPE TestType, each element containing a variable of TYPE _BYTE. That's about as close as you can get to what you're trying to do. Good luck!






            share|improve this answer



























              up vote
              0
              down vote













              There are two issues here. In QB64 you simply can't put arrays inside of user defined types. According to the QB64 Wiki's article on TYPE definitions:




              TYPE definitions cannot contain Array variables! Arrays can be DIMensioned as a TYPE definition.




              Besides that, your dataArray (declared dataArray AS STRING * 4) does not declare an array at all, but rather, declares a 4 character string. That's why you get a syntax error when you try to access elements of dataArray using array syntax. You can declare an array consisting of a custom type, like so:



              TYPE TestType
              dataElement AS _BYTE
              END TYPE

              DIM CustomType(4) AS TestType

              CustomType(1).dataElement = 3


              This declares a 4 element array of TYPE TestType, each element containing a variable of TYPE _BYTE. That's about as close as you can get to what you're trying to do. Good luck!






              share|improve this answer

























                up vote
                0
                down vote










                up vote
                0
                down vote









                There are two issues here. In QB64 you simply can't put arrays inside of user defined types. According to the QB64 Wiki's article on TYPE definitions:




                TYPE definitions cannot contain Array variables! Arrays can be DIMensioned as a TYPE definition.




                Besides that, your dataArray (declared dataArray AS STRING * 4) does not declare an array at all, but rather, declares a 4 character string. That's why you get a syntax error when you try to access elements of dataArray using array syntax. You can declare an array consisting of a custom type, like so:



                TYPE TestType
                dataElement AS _BYTE
                END TYPE

                DIM CustomType(4) AS TestType

                CustomType(1).dataElement = 3


                This declares a 4 element array of TYPE TestType, each element containing a variable of TYPE _BYTE. That's about as close as you can get to what you're trying to do. Good luck!






                share|improve this answer














                There are two issues here. In QB64 you simply can't put arrays inside of user defined types. According to the QB64 Wiki's article on TYPE definitions:




                TYPE definitions cannot contain Array variables! Arrays can be DIMensioned as a TYPE definition.




                Besides that, your dataArray (declared dataArray AS STRING * 4) does not declare an array at all, but rather, declares a 4 character string. That's why you get a syntax error when you try to access elements of dataArray using array syntax. You can declare an array consisting of a custom type, like so:



                TYPE TestType
                dataElement AS _BYTE
                END TYPE

                DIM CustomType(4) AS TestType

                CustomType(1).dataElement = 3


                This declares a 4 element array of TYPE TestType, each element containing a variable of TYPE _BYTE. That's about as close as you can get to what you're trying to do. Good luck!







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited yesterday

























                answered yesterday









                Alejandro Alvarado

                359




                359






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410020%2fuse-an-array-in-a-user-defined-type-in-qbasic%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown