Type decleration 
Author Message
 Type decleration

In QBasic, is it possible to make a type than containes an array. The
help file doesn't mention it, and I can't seem to make anything work.
I was thinking something along the lines of :

Type Blah
A(3) as integer
B as string * 10
end type

But, this doesn't work. Anybody know what I can do, or if this is even
possible in QBasic?

Thanks in advance.




Thu, 01 Jul 1999 03:00:00 GMT  
 Type decleration

Quote:
>In QBasic, is it possible to make a type than containes an array. The

Hello Dale Neal, Im not sure I know what you mean.
You can declare an array as type if its that.

 type sprite
  x as integer
  y as integer
 end type

 dim alien(10) as sprite

Bye Jester



Thu, 01 Jul 1999 03:00:00 GMT  
 Type decleration


writes:

Quote:
>In QBasic, is it possible to make a type than containes an array. The
>help file doesn't mention it, and I can't seem to make anything work.
>I was thinking something along the lines of :
>Type Blah
>A(3) as integer
>B as string * 10
>end type
>But, this doesn't work. Anybody know what I can do, or if this is even
>possible in QBasic?

Not possible, but what you can do is allocate a string, use
this as an array with MKI$ and CVI to convert integers to
strings and back. For your above type you would use
something like this -

TYPE Blah
    A3 AS STRING * 6
END TYPE
DIM Array(1) AS Blah

CLS
i% = 22
    'convert to string and save to element 3 in string array
MID$(Array(1).A3, 5, 2) = MKI$(i%)
    'get string from array and convert to integer
i% = CVI(MID$(Array(1).A3, 5, 2))
PRINT i%

TTfn,

Craig Wright___

...I'm immortal, well....so far !...



Sat, 03 Jul 1999 03:00:00 GMT  
 Type decleration

Quote:


>Subject: Type decleration
>Date: Sun, 12 Jan 1997 19:41:02 GMT
>In QBasic, is it possible to make a type than containes an array. The
>help file doesn't mention it, and I can't seem to make anything work.
>I was thinking something along the lines of :
>Type Blah
>A(3) as integer
>B as string * 10
>end type
>But, this doesn't work. Anybody know what I can do, or if this is even
>possible in QBasic?

Unfortunately it is not possible.

--
LEXACORP Pty Ltd, Brisbane, Qld Australia
Dataflex / MSAccess / VB Systems Development
http://www.daccess.com/devpages/Lexacorp.htm



Sat, 03 Jul 1999 03:00:00 GMT  
 Type decleration

QBasic won't allow an Array as a member of a Type. QuickBasic, powerbasic,
and VB will however.
i.e.

Type ATestType
        AnArray(1 To 100)       AS Integer
        AnotherArray(1 To 50)   AS Long
End Type

DIM Test        AS ATestType

Test.AnArray(1) = 1
Test.AnotherArray(50) = 100000



Quote:
> >In QBasic, is it possible to make a type than containes an array. The

> Hello Dale Neal, Im not sure I know what you mean.
> You can declare an array as type if its that.

>  type sprite
>   x as integer
>   y as integer
>  end type

>  dim alien(10) as sprite

> Bye Jester



Sun, 04 Jul 1999 03:00:00 GMT  
 Type decleration

Quote:


>Subject: Re: Type decleration
>Date: 15 Jan 1997 21:07:02 GMT
>QBasic won't allow an Array as a member of a Type. QuickBasic, PowerBasic,
>and VB will however.

Sorry, that's not true.   VB - Yes,  QB,PB - No.

--
LEXACORP Pty Ltd, Brisbane, Qld Australia
Dataflex / MSAccess / VB Systems Development
http://www.daccess.com/devpages/Lexacorp.htm



Mon, 05 Jul 1999 03:00:00 GMT  
 Type decleration

My mistake. QB4.5 dosn't support it but PDS does. I haven't done anything
with QB for a while. PBDLL does support arrays as members of a type and all
though I don't have a copy of the newest PowerBasic, I'm sure I have seen
code somewhere that uses them.



Quote:



> >Subject: Re: Type decleration
> >Date: 15 Jan 1997 21:07:02 GMT

> >QBasic won't allow an Array as a member of a Type. QuickBasic,
PowerBasic,
> >and VB will however.

> Sorry, that's not true.   VB - Yes,  QB,PB - No.

> --
> LEXACORP Pty Ltd, Brisbane, Qld Australia
> Dataflex / MSAccess / VB Systems Development
> http://www.daccess.com/devpages/Lexacorp.htm



Mon, 05 Jul 1999 03:00:00 GMT  
 Type decleration

: QBasic won't allow an Array as a member of a Type. QuickBasic, PowerBasic,
: and VB will however.
: i.e.

: Type ATestType
:       AnArray(1 To 100)       AS Integer
:       AnotherArray(1 To 50)   AS Long
: End Type

: DIM Test      AS ATestType

: Test.AnArray(1) = 1
: Test.AnotherArray(50) = 100000

Are you absolutley sure about that? So, you can have this:

DIM Test (1 TO 500) AS ATestType

Test(50).AnArray(2) = 12312

How that affects on RANDOM files?

        Mike



Mon, 05 Jul 1999 03:00:00 GMT  
 Type decleration

Reply from ...
------------------------------------------------
Eric Hoffman

CRI Financial Systems, Inc.
------------------------------------------------



Quote:

> : QBasic won't allow an Array as a member of a Type. QuickBasic,
PowerBasic,
> : and VB will however.
> : i.e.

> : Type ATestType
> :  AnArray(1 To 100)       AS Integer
> :  AnotherArray(1 To 50)   AS Long
> : End Type

> : DIM Test AS ATestType

> : Test.AnArray(1) = 1
> : Test.AnotherArray(50) = 100000

> Are you absolutley sure about that? So, you can have this:

> DIM Test (1 TO 500) AS ATestType

> Test(50).AnArray(2) = 12312

This is legal and is just another way of having a Two-Dimesional Array.

Quote:

> How that affects on RANDOM files?

>    Mike

It has no affect on Randoms Files. Random Files are just a special case of
binary files. They have a fixxed record length that you determine. You can
still output each member of the array as a seperate record or you can write
the whole array in one write. This accomplishes the same. It just depends
on how you want to do it.

i.e.

Type ArrayType
    Members(1 To 50)    As Integer
End Type

Dim FF As Integer, RecLen As Integer, X As Integer

Dim Test(1 To 10) As ArrayType

FF = FreeFile
RecLen = Len(Test(1)) * 10              ' (50 Members * 2 Bytes) * 10 Elements

Open "C:\TEMP\TEST.DAT" For Random As FF Len = RecLen
        Put #FF, , Test()               ' We are actually writing an entire array of
arrays contained in a Type
Close #FF

This code creates a file of 1000 bytes in size. You can read it back in
with a RecLen of 1000 to get the whole array of Arrays, or you can set the
RecLen to 100 and read each element of Test back in, or even set RecLen = 2
and read each Integer Members seperatley.



Sat, 10 Jul 1999 03:00:00 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Global Class Decleration

2. string decleration

3. mapi decleration in vb4

4. Global Decleration - Problem.

5. sophisticated decleration

6. Decleration Problem - Urgent

7. SendInput Decleration

8. Need decleration listview LVM_GETITEMRECT

9. Prob. w\ TYPE data type: err:Type Mismatch

10. object is not valid for type textbox and type textbox

11. Getting the basic [Type] of an array [Type[]]

12. Using types in a different assembly given that the type may be used or not used

 

 
Powered by phpBB® Forum Software