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 / Declaring an Integer Variable (DBC)

Author
Message
flock
18
Years of Service
User Offline
Joined: 10th Mar 2006
Location: Earth
Posted: 6th Aug 2006 21:14
Is there a way to modify an int var's name in the declaration? I believe I've seen this done with strings but I cannot remember from where...

Something like:



So then, later on in the program, I can do something like:



a.k.a. "flockhound"
Gamers for sale
18
Years of Service
User Offline
Joined: 19th Nov 2005
Location: Some where beneath the elements
Posted: 7th Aug 2006 04:07
So, what you are tring to do is add something onto the varible name with out redeclaring it or changing it?
flock
18
Years of Service
User Offline
Joined: 10th Mar 2006
Location: Earth
Posted: 7th Aug 2006 07:52
Yes

a.k.a. "flockhound"
SimSmall
20
Years of Service
User Offline
Joined: 7th Aug 2004
Location: United Kingdom
Posted: 7th Aug 2006 13:37
Unfortunately, due to the very nature of computers, your first snippet is not understood, the only thing it can understand is value = piece + 2, which if I've read properly, is not what you're after...

the only thing you could really do is use an array



...that would work
Gamers for sale
18
Years of Service
User Offline
Joined: 19th Nov 2005
Location: Some where beneath the elements
Posted: 7th Aug 2006 17:30
I still don't get what you are tring to do so I have made a list...

If you just renaming the varible try this:



If your tring to add an integer to it then use this:


But if you are tring to have it store two numbers I would suggest using an array just like the example sim small showed.
flock
18
Years of Service
User Offline
Joined: 10th Mar 2006
Location: Earth
Posted: 8th Aug 2006 03:11
Yes, I know how to do that. I was wondering about random variable generation. I believe PlayBasic has a command or two on it. I didn't want pre-made variables (integer vars), instead, I wanted the user to be able to create their own variable...

a.k.a. "flockhound"
Gamers for sale
18
Years of Service
User Offline
Joined: 19th Nov 2005
Location: Some where beneath the elements
Posted: 8th Aug 2006 03:47 Edited at: 8th Aug 2006 03:50
So you want the users input to create a varible in the program.
Dream And Death
18
Years of Service
User Offline
Joined: 21st Feb 2006
Location: The circus! Juggling job, kids and DBPro
Posted: 8th Aug 2006 14:18
Erm, don't know why you are doing this, but many new coders do ask. I will help, but I think you have to sort your thinking out first though! If a user wants tocreate a new variable at runtime - say bob and asks the program to assign 5 to it, what are you ever going to use it for?

Strictly speaking, a program can't suddenly create a new variable during run-time (as the variables are part of the code, you would have to adjust and re-compile code while the code is running??), but you can mimic it. Anyhow, the best way to do this, is to use two arrays:
One string array:
UserVariableNames()
and one value array:
UserVariableValues()

Then if the user requests a new variable, (say for the first time) you can make
UserVariableNames(1)="Bob"
and
UserVariableValues(1)=5

Hope this helps, but I suspect you need to rethink what you are doing. This sort of thing would really only be useful if you were, say, producing a calculator program, or maths parser, in which the user could type Bob=5 on one line, and then say Bob*2 and get 10 as an answer on another line.

Normally, programs do not create (or rather mimic creating!, cause as I said creation is actually impossible) new variables at run time!

"You get what everyone gets, you get a lifetime!" - Death, The Sandman Library

First you Dream, then you ... - Neil Gaiman, 2001

Login to post a reply

Server time is: 2024-09-25 05:32:13
Your offset time is: 2024-09-25 05:32:13