Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"TYPE" problems 1

Status
Not open for further replies.

PZ

Programmer
Jul 21, 2000
18
IT
This problem is really killing me: what I need is a record that can contain arrays, something like this..

TYPE
var1 as integer
var2 as whatever
var3 as array(1 to n)
END TYPE


Question is how do I declare var3?? Is it possible to have arrays in records with qb? Please help, I'm going crazy!

This is a game. Who is the toy?
.:: PZ ::.
 
I don't think it's possible in QB to create an array INSIDE another array.

--MiggyD It's better to have two heads to solve a problem from different angles than to have tunnel vision to a dead end.
 
Yes! It is possible to put arrays inside arrays. But only in qb7.1!!!!

Try searching the web for qb7.1 it has many advanced features including the one u want. BUT a word of caution u will not be able to use any of the qb4.5 libraries nor any qb4.5 specific programs in qb7.1(But i think u will be able to use 99.99% of the programs. Who knows! u can never say what may happen!).

Other then that it is 100% safe to use qb7.1.

Bye,
The Big Basic Q
 
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]


VCA.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top