Returning a type object

BlitzPlus Forums/BlitzPlus Programming/Returning a type object

schilcote(Posted 2009) [#1]
I need my function to return a type object. Like this:

Type thing
Field number
End Type

While Not KeyDown (1)

For t=0 To 10
box.thing=New thing
box\number=Rand(1,255)
Next

box.thing=MyFunction()
Print Str$(box.thing)

Wend

Function MyFunction()

box.thing=First thing

Return box.thing

End Function


However, no matter what I do, it allways gives me an "Illegal Type Conversion". I've tried changing "Return box.thing" and "box.thing=MyFunction()" to just be box, but that gives me the same error.

How should I do this?


Sauer(Posted 2009) [#2]
The answer lies in the thread below yours:

http://www.blitzbasic.com/Community/posts.php?topic=86223#976902


schilcote(Posted 2009) [#3]
That's what I tried, I get an illegal type conversion.


Matty(Posted 2009) [#4]
Type thing
Field number
End Type

While Not KeyDown (1)

For t=0 To 10
box.thing=New thing
box\number=Rand(1,255)
Next

box.thing=MyFunction.thing()
Print Str$(box.thing)

Wend

Function MyFunction.thing()

box.thing=First thing

Return box.thing

End Function



that should work


schilcote(Posted 2009) [#5]
Yep, that works. Thanks.