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 / Returning types from functions

Author
Message
Ken
21
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Rochdale, England
Posted: 22nd Sep 2003 16:24
Is it possible to return types from functions? I know you can pass them as parameters but returning them doesn't seem to work.
haggisman
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: United Kingdom
Posted: 22nd Sep 2003 18:00
Nope, not yet anyway.

Defying the convention of an upright avatar since 1985
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Sep 2003 19:11
You could make it a global Type variable, then it's accessible to your functions.

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
Ken
21
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Rochdale, England
Posted: 22nd Sep 2003 19:27
Quote: "Nope, not yet anyway."


Are there any plans to introduce this soon?

Quote: "You could make it a global Type variable, then it's accessible to your functions."


I'm not a fan of 'globalisation' I like to keep my variables local so that my functions don't stuff up anything they shouldn't. Also, I like to reuse functions and having them rely on a variable outside the scope of the function makes them less usefull.

Thanks for your replies.

Ken
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Sep 2003 20:46
You can still use a global variable...set up an extra one solely for the use of this function and whatever calls it. Always assume it is only relevant to the last call to the function.

Yes, it's a bit more coding, but if you really need it...

BatVink (formerly StevieVee)
http://facepaint.me.uk/catalog/default.php
zzabb
21
Years of Service
User Offline
Joined: 25th Apr 2003
Location: Seattle, USA
Posted: 23rd Sep 2003 01:39 Edited at: 23rd Sep 2003 02:53
well you can return info from a function if that is what you want/ment just make the function equal to the variable



or you can return a string




I hope I didn’t make it confusing by using all different variables
I only did that to show that they are independent

My advice is free -
unfortunately you get what you pay for (-:
Ken
21
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Rochdale, England
Posted: 23rd Sep 2003 17:18
Quote: "well you can return info from a function if that is what you want/ment just make the function equal to the variable"


Thanks for replying, but that wasn't what I meant. I already knew that and you didn't confuse me as I am an experienced programmer in other languages (of course you'd only know that if you were psychic )

I was enquiring about returning custom types from functions, which looks like it's impossible at the moment.

Quote: "You can still use a global variable...set up an extra one solely for the use of this function and whatever calls it. Always assume it is only relevant to the last call to the function."


I suppose that's the best work around for the moment. It really niggles me that this hasn't been implemented as the types/arrays system is very powerful otherwise, and at the moment I'm still playing round with the demo trying to work out whether to buy it or not.

At the moment I own Blit3D, which does allow for returning custom types from functions, and I kind of feel lost without it.
zzabb
21
Years of Service
User Offline
Joined: 25th Apr 2003
Location: Seattle, USA
Posted: 23rd Sep 2003 23:09
well the only thing i find limiting is that you can only pull out one variable from a function, if you can transfer in more than one you should be able to transfer out more than one but....

if a global variable would work or global array, which is only limited by your comps memory and you can transfer out specific local variables, i guess i don't see the limitations, but i'm not an experienced programmer
barely capable in DB

tell me why that’s important?
Or a situation that it would be needed?

My advice is free -
unfortunately you get what you pay for (-:
Ken
21
Years of Service
User Offline
Joined: 21st Sep 2003
Location: Rochdale, England
Posted: 24th Sep 2003 11:46
Globals should be used sparingly, in my opinion, as they always exist for the entire duration of the program and are accessible to 100% of your code, which can make errors very hard to find.

The globals version would be:



The way it would be used would be something like:



This is just a simple example, it really isn't meant to do a lot.

This is just a neat and tidy way of programming, it's also a feature in every other language I have used. The problem with the globals route is that it is prone to programmer error, e.g. you could forget to call the function and assume the values in the global are correct.

Also, as the amount of functions increases, so does the amount of globals you need - and don't forget, they are always in memory even if you only use the function once in the whole program.
zzabb
21
Years of Service
User Offline
Joined: 25th Apr 2003
Location: Seattle, USA
Posted: 24th Sep 2003 18:14
thank you for the explaination

My advice is free -
unfortunately you get what you pay for (-:

Login to post a reply

Server time is: 2024-11-25 08:56:30
Your offset time is: 2024-11-25 08:56:30