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.

DarkBASIC Professional Discussion / Functions: There not exist Local Variables...

Author
Message
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 11th Feb 2003 15:56
There not exist Local Variables In the Functions?
Rob K
Retired Moderator
22
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 11th Feb 2003 16:00
I don't quite follow your question. However, all arrays are a believe, global. Non-arrays declared in functions are local variables.

NOBODY has a forum name as stupid as Darth Shader. I do.
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 11th Feb 2003 16:14
Ok, A simple test: (Please HEELPP)
It Works to you?, I mean The local Variables change when you exe these code?===>
ToXic
22
Years of Service
User Offline
Joined: 8th Sep 2002
Location: Australia
Posted: 11th Feb 2003 23:02
In DBPRO Variables are not Global, to make them global add this line to the top of your code.

Global A,B,C,M

ToXic.
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 12th Feb 2003 02:34
Thanks, But I want to use local Variables; Just that!!!, just LOCAL, LOCAL, LOCAL... Buaaaaaaaaahhh!!!!!.
The Big Babou
22
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 12th Feb 2003 02:43
perhaps declaring the variables inside the function would help

The Big Babou
22
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 12th Feb 2003 02:47
I think i forgot something



btw I didn't try it
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 12th Feb 2003 15:02
Nop, doesn't work


Thnks!
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 12th Feb 2003 15:08
Let us admit it, do not exist variable internal in DBPro, unless they are in a Loop of any type (Loop, Repeat, While).

Thanks to all You.
doclar1
22
Years of Service
User Offline
Joined: 4th Jan 2003
Location: United States
Posted: 12th Feb 2003 17:24
How about this...



Regards,
Lawrence
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 12th Feb 2003 22:05
Have you tested it? In DB Pro?
It Doesn't work for me. To you?
It is exist the "Local" word and apears like reserved word, but not work ¿?¿?¿?¿?¿?¿?¿?¿?¿?
The Big Babou
22
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 12th Feb 2003 22:23
well, there are local variables




the variablename inside the function stays at a value of 50 while the variable inside the loop counts up
The Big Babou
22
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 12th Feb 2003 22:25
i've a thread with a limb problem. could you take a look at it? thanks. its name is limb problem
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 13th Feb 2003 07:40
Thank you again but the promel isn't that because I want o use acounter, if you're code was modified with
a=a+1
then there ocurre nothing!

snif!!
The Big Babou
22
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 13th Feb 2003 14:38
where do you put the "a=a+1"?
did you notice the wait key command? you have to press a key several times, that means every time the loop is run through you have to press a key.
something like this should appear:

2 [here the program waits for a key to be pressed, so press one]
50
3 [press a key]
50
4 [press a key]
50
5 [press key]
50
6 [bla bla]

i should have documented it better
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 13th Feb 2003 22:08
Ok Sorry, my english is worse.
a=50 change it for a=a+1 and try it!.

Sorry again.
The Big Babou
22
Years of Service
User Offline
Joined: 10th Feb 2003
Location: Cyberspace
Posted: 13th Feb 2003 23:51
what result do you get?

2
1
3
1
4
1
5
1

the a in the loop counts up, but the a of the function stays 1. in fact, the a in the function is deleted from the memory when the function is left. it has to be local. or what do you think is a local variable?
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 15th Feb 2003 07:34
A local variable is that is used within sub program and that by the same does not lose its values within that sub program. what other types of languages erase the memory after leave the function?
May be youre answer is thats the answer what I'm looking for.
Thanks!
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 15th Feb 2003 13:27
Ah, you mean a *static* local variable.

Nope, DBPro doesn't provide those. All local variables are created when you enter the function and destroyed when you leave.

You can simulate them by using a global variable, and then only access that variable from your chosen function.
Shadow Robert
22
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 15th Feb 2003 20:35
... hmm not sure i'm following this right so just do a general help

these are always global

#constant [inline name] [inline value]

[variable] AS [variable type]

type [variable type name]
[variables]
endtype

global [variable]

these are local & global depending on placement within a function

dim [array name]([elements])
[variable]
[variable]#
[variable]$

remember that althought an array isn't by default global, because an AS type definition is then this also automatically declares the array as a global

if you wish to keep things private within functions you place the word 'local' infront of it, and this then gives the following function, variable, array access within that function.

also remember that the input variables

function [function name]([input variables])

are also locally defined by defualt, and declaring them as global is likely to crash your DBpro program.

however what if you declare a local variable yet wish it to be used in another function?

remember that whilst the function is running the contained data IS NOT constricted to simply what is running within that function, but if you run a function within it - that too will also be handed down the variable for use because it is localising the variable definition within that particular function ... it is only once the function has ended that the variable is gone.

if no input for a variable you declare is provided within the subiquent function then it is likely that you function will not perform as you wanted it to

hopefully this makes things a little clearer

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Feb 2003 02:52
Not quite raven, here's the ones that I've worked out.

Inside a function
Argument variables - fn only
local [variable] as [type] - fn only
global [variable] as [type] - accepted but does not work
[variable] as [type] - fn only
dim [variable]([elements]) as [type] - fn only
global dim [variable]([elements]) as [type] - dim a global array that has been undimmed
using a variable without declaring it - fn only, but watch out for globals of the same name

Outside a function
local [variable] as [type] - non fn only
global [variable] as [type] - everywhere
dim [variable]([elements]) as [type] - everywhere
using a variable without declaring it - non fn only

I always try and specify local in my functions to eliminate the possibility of accidentally using a global variable of the same name. This will be even more important when Hubdules preprocessor is released
Astucia
22
Years of Service
User Offline
Joined: 21st Dec 2002
Location: Mexico
Posted: 16th Feb 2003 08:00
Thank you guys!.
Thats right, In DB Pro the local are destroyed wen you leave the function. Thats all.

Now, can you give me a tip for a good metod to use the functions and make good programs?
Tnks again.

Login to post a reply

Server time is: 2025-05-18 04:43:05
Your offset time is: 2025-05-18 04:43:05