creating dynamic variables
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Patrick_Bowe
Posted On:   Tuesday, October 1, 2002 12:19 PM

I have a need to create a Vector whose name should be generated dynamically, as I don't know when I access the database exactly how many Vector's I'll need. In other words, say I run a database query that returns "Bob" "Jane" and "Sue". Now I want to loop through that resultset, and create a vector for each one. Optimally, I would like to call them something like dataBob dataJane and dataSue. The next time through may return other results. Does anyone know how I would create unique vector names based on the results returned by my database query?

Re: creating dynamic variables

Posted By:   Joe_Cheng  
Posted On:   Wednesday, October 2, 2002 07:28 AM

Yeah, this is impossible in static languages like Java. (I imagine something like this is pretty easy to do in Perl, Python, etc.?) I used to do stuff like this in ColdFusion and couldn't understand why I couldn't do it when learning C++.

But there tends to not be any good reason to want to dynamically create variables on the stack anyway. The other posters are right, what you are really looking for is a data structure to hold some vectors which you can retrieve by name--which is precisely what HashMap is for.

Re: creating dynamic variables

Posted By:   Anonymous  
Posted On:   Tuesday, October 1, 2002 12:52 PM

This can not be done, thank God! There are much better ways to do this, like creating a vector containing multiple vectors for each row...
About | Sitemap | Contact