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?
arrays qbasic qb64
add a comment |
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?
arrays qbasic qb64
add a comment |
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?
arrays qbasic qb64
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
arrays qbasic qb64
asked 2 days ago
Maxime Beasse
137
137
add a comment |
add a comment |
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!
add a comment |
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!
add a comment |
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!
add a comment |
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!
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!
edited yesterday
answered yesterday
Alejandro Alvarado
359
359
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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