Yes, you can do something similar to that...
unlike Visual Basic, Qbasic makes it a little difficult.
It sounds a little strange (and inefficient) to store
numeric values as strings, but it really works. Integers
fit into 2 bytes, Long integers and Single Precision values
fit in 4 bytes and Double Precision values go into eight
bytes.
This really isn't a bad idea since, with a little work,
you can structure a user defined data type with many
(within reason) dimensions.
(Pardon the long lines!)
'********************************************************************************************
[tt]
DEFINT A-Y
DEFSTR Z
TYPE MyStuff[/tt]
'dim for 10 integers
[tt]
IntegerArray AS STRING * 20[/tt]
'dim for 10 long integers
[tt]
LongArray AS STRING * 40[/tt]
'dim for 10 single precision values
[tt]
SingleArray AS STRING * 40[/tt]
'dim for 10 double precision values
[tt]
DoubleArray AS STRING * 80
END TYPE
DECLARE FUNCTION Array$ (Dim1, Dim2, Dim3, Value$)
REDIM SHARED Mstuff(1 TO 10) AS MyStuff[/tt]
' The Mstuff array will be treated as a
' 3-dimensional array containing mixed data types.
' The following constants will be used to refer to
' elements of the user defined type (Dim1).
[tt]
CONST IntegerArray = 1
CONST LongArray = 2
CONST SingleArray = 3
CONST DoubleArray = 4
[/tt]
' Create various values...
[tt]
MyInteger% = 32000
MyLong& = 71234
MySingle! = 123456.123#
MyDouble# = 987656789.9876543#
[/tt]
' Set various array elements with the values above.
' The Value$ parameter accepts the values.
[tt]
zRet = Array$(IntegerArray, 2, 3, STR$(MyInteger%))
zRet = Array$(LongArray, 9, 1, STR$(MyLong&))
zRet = Array$(SingleArray, 2, 7, STR$(MySingle!))
zRet = Array$(DoubleArray, 1, 1, STR$(MyDouble#))
[/tt]
' Get the values back.
' Array$ returns the values if the Value$ parameter = ""
[tt]
NewInteger% = VAL(Array$(IntegerArray, 2, 3, ""
)
NewLong& = VAL(Array$(LongArray, 9, 1, ""
)
NewSingle! = VAL(Array$(SingleArray, 2, 7, ""
)
NewDouble# = VAL(Array$(DoubleArray, 1, 1, ""
)
CLS
[/tt]
' Print them
[tt]
PRINT " Stored:"; MyInteger%, MyLong&, MySingle!, MyDouble#
PRINT "Retrieved:"; NewInteger%, NewLong&, NewSingle!, NewDouble#
[/tt]
'Here's the Array$ function....
'It uses MKI$, MKL$, MKS$ and MKD$ to store the values
' and uses CVI, CVL, CVS and CVD to retrieve them.
[tt]
DEFINT A-Y
DEFSTR Z
FUNCTION Array$ (Dim1, Dim2, Dim3, Value$)
SELECT CASE Value$
CASE ""
SELECT CASE Dim1
CASE IntegerArray
Array$ = LTRIM$(STR$(CVI(MID$(Mstuff(Dim2).IntegerArray, Dim3 * 2 - 1, 2))))
CASE LongArray
Array$ = LTRIM$(STR$(CVL(MID$(Mstuff(Dim2).LongArray, Dim3 * 4 - 1, 4))))
CASE SingleArray
Array$ = LTRIM$(STR$(CVS(MID$(Mstuff(Dim2).SingleArray, Dim3 * 4 - 1, 4))))
CASE DoubleArray
Array$ = LTRIM$(STR$(CVD(MID$(Mstuff(Dim2).DoubleArray, Dim3 * 8 - 1, 8))))
END SELECT
CASE ELSE
SELECT CASE Dim1
CASE IntegerArray
MID$(Mstuff(Dim2).IntegerArray, Dim3 * 2 - 1, 2) = MKI$(VAL(Value$))
CASE LongArray
MID$(Mstuff(Dim2).LongArray, Dim3 * 4 - 1, 4) = MKL$(VAL(Value$))
CASE SingleArray
MID$(Mstuff(Dim2).SingleArray, Dim3 * 4 - 1, 4) = MKS$(VAL(Value$))
CASE DoubleArray
MID$(Mstuff(Dim2).DoubleArray, Dim3 * 8 - 1, 8) = MKD$(VAL(Value$))
END SELECT
END SELECT
END FUNCTION
[/tt]