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 variable names using a variable?

Author
Message
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 17th Nov 2008 23:27


Not the whole code, but enough to describe my situation. How do you say something like "x+str$(NewObject)#=x*50"? Like, if NewObject is 15, then it becomes x15=...?
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 17th Nov 2008 23:40
Is it supposed to write "=x*50" at the end or the result of the operation x*50?
In the latter event, you would do it like so:



-> Oh, come on...
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 18th Nov 2008 00:23 Edited at: 18th Nov 2008 00:53
I'll just post the whole code so you can see what's going on. It's not much. I'm not writing a string, I'm creating a variable and defining it within a for/next command based on the condition that TestLevel1Data=9.



I'm making a bunch of spheres, and therefore I need a bunch of variables to define their position if I want to interact with them. I figure there must be a way to create unique variable names to go along with the unique spheres I'm creating. I want DBPro to automatically create them for me.

So as NewObjects are created, variables specific to each object are also created. If NewObject=1, then it creates x1#=value, y1#=value, and z1#=value; if NewObject=12, then it creates x12#=value, y12#=value, z12#=value.

I want to use for/next commands to define and write only the variables I need. The alternative that I see for this is to plan how many spheres I want to have, and copy and paste the same code over and over again with the only difference being adding a different number after the x,y,z to define a specific variable for a specific sphere. This method I have will work if only there was a way to name a variable using another variable.

EDIT: Updated code
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 18th Nov 2008 11:38
Ah, I see.
To put it short, you cannot do that.
That's when you would use an array, preferably of a custom type.
You could try something like this:


Hope that helps

For more info, you could search for arrays and udt / user defined types on this forum.


-> Oh, come on...
Deego
16
Years of Service
User Offline
Joined: 21st May 2008
Location:
Posted: 18th Nov 2008 16:56
I've been looking around at arrays and types, and it wasn't until your example did I understand how to use it. Thanks!
Rudolpho
18
Years of Service
User Offline
Joined: 28th Dec 2005
Location: Sweden
Posted: 18th Nov 2008 19:00
Glad to be of help
I see now that I apparently wrote the positioning code into the make sphere command in my snippet, but I guess you figured that out already


-> Oh, come on...

Login to post a reply

Server time is: 2024-11-25 14:47:32
Your offset time is: 2024-11-25 14:47:32