Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Is it possible to return a user defined type from a function in DBP?

Author
Message
Railgun
18
Years of Service
User Offline
Joined: 2nd Sep 2006
Location: Galveston Bay
Posted: 4th Sep 2006 23:49
Can you do something like this in DBP?



Maybe I just have the syntax wrong, but I keep getting 'Both user defined type values must use the same type value' I also tried

ENDFUNCTION b AS MyType

I'm assuming you can't pass parameters by reference in DBP either?
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 5th Sep 2006 02:44
I believe this is what you are trying to do-


Railgun
18
Years of Service
User Offline
Joined: 2nd Sep 2006
Location: Galveston Bay
Posted: 5th Sep 2006 03:32
Thanks, Daemon, but unfortunately, I would like to pass the entire structure to the function, not just one of its fields, as well as return the whole structure.

Of course, this is a way of returning multiple values from a function, and I realize DBP may not even be able to do this. I just thought it
Quote: "interesting"
I could pass a user defined type to a function just fine. It's only when I try to return one that I get the error. Of course, returning just a primitive works just fine.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 5th Sep 2006 23:30
Passing a UDT value into a function works just fine, but you can't return them.

The nearest equivalent I've found is to have a global variable paired with your function.



jinzai
18
Years of Service
User Offline
Joined: 19th Aug 2006
Location: USA
Posted: 6th Sep 2006 05:33
So, it wasn't just me....whew! That is too bad...really. I was hoping for a way around the whole pass by reference versus pass by value gotcha without having to go global, but since you do, then I won't feel bad when I do, thanks!
Railgun
18
Years of Service
User Offline
Joined: 2nd Sep 2006
Location: Galveston Bay
Posted: 6th Sep 2006 17:40
Agreed. Thanks, Ian, won't waste time on that any longer, your work around is useful. Yea, not having a way to pass by reference is unfortunate, but then again, I guess it wouldn't be a type of BASIC if that was allowed. Oh well, once I get to know the engine, I'll probably move on to the SDK anyway...

Login to post a reply

Server time is: 2024-09-25 07:29:01
Your offset time is: 2024-09-25 07:29:01