Create dynamic Name for string

  • Thread starter Thread starter KaHuNa
  • Start date Start date
K

KaHuNa

I want create a string from a row of my db, but for each rows i need a new
string and a new name for the variable.

exemple:
int i = myRow["ID"];
string varName = "news";

createNameVar = varName + i;

but i can't eval this in C#, also the strings news1, new2,...,newsN don't
exist.
How i can do that?
 
KaHuNa said:
I want create a string from a row of my db, but for each rows i need a new
string and a new name for the variable.

exemple:
int i = myRow["ID"];
string varName = "news";

createNameVar = varName + i;

but i can't eval this in C#, also the strings news1, new2,...,newsN don't
exist.
How i can do that?

Why do you need a new name for the variable? Why not just use an array?
 
You don't really need a new name for the variable
If you need to hold all the news strings at the same time you can use an
array or ArrayList

ArrayList newsList = new ArrayList();

foreach(row r in table.rows)
{
int i = r["ID"];
newsList.Add("news" + i);
}

newsList will then hold all the strings. You only need the reference, not
the name.
 
I need a string to send to flash




"Morten Wennevik" <[email protected]> a écrit dans le message de
You don't really need a new name for the variable
If you need to hold all the news strings at the same time you can use an
array or ArrayList

ArrayList newsList = new ArrayList();

foreach(row r in table.rows)
{
int i = r["ID"];
newsList.Add("news" + i);
}

newsList will then hold all the strings. You only need the reference, not
the name.
 
KaHuNa said:
Because i use the string to send the variable in a Macromedia Flash
interface.

You need to be a bit clearer on exactly what you're doing here. How
does the Flash interface work, etc. If you could produce a really
"dummy" version of what you're trying to do (which needn't be related
to the real thing) that would help a lot. It could be that reflection
is what you need, but it's hard to say without more information.
 
You can always send these strings to flash
foreach(string s in newsList)
{
send s to flash
}
 
ok take this exemple:
you have a text file with a="abc"
you load the line and you have a string, but you can use the variable a.
With eval in jscript you can create a="abc" with a is the variable.
I want the same function in c#, a function which evaluates the string to
make varaibles....



"Morten Wennevik" <[email protected]> a écrit dans le message de
You can always send these strings to flash
foreach(string s in newsList)
{
send s to flash
}
 
KaHuNa said:
ok take this exemple:
you have a text file with a="abc"
you load the line and you have a string, but you can use the variable a.
With eval in jscript you can create a="abc" with a is the variable.
I want the same function in c#, a function which evaluates the string to
make varaibles....

Well, you can't - but if you'd explain more *why* you want this, *how*
you were going to use it, we could help to explain what to use instead.
 
Are you perhaps trying to ouput these values into a text file that is then
read in by Flash (which will then assign values in the text file to
variables within its own programming environment) ?

In that case just output " strings" that you build up into that text file...

Pseudo code:

for each row x in my data...

varForFlash = "news" + x + "=" + dataIwantVarToEqual

Ouput varForFlash to text file

next row

This will give you a text file with:
news1 = firstRowData
news2 = 2ndRowData

etc...

Flash will then be able to consume...

I hope this helps, if not then please provide clearer details on what you
are doing as suggested by the others..

Cheers


Giri
 
I think this method could be fine, because i can make the eval in flash and
the server works less....
thank you.


Giri said:
Are you perhaps trying to ouput these values into a text file that is then
read in by Flash (which will then assign values in the text file to
variables within its own programming environment) ?

In that case just output " strings" that you build up into that text file...

Pseudo code:

for each row x in my data...

varForFlash = "news" + x + "=" + dataIwantVarToEqual

Ouput varForFlash to text file

next row

This will give you a text file with:
news1 = firstRowData
news2 = 2ndRowData

etc...

Flash will then be able to consume...

I hope this helps, if not then please provide clearer details on what you
are doing as suggested by the others..

Cheers


Giri
 
Flash will do that more or less for you :

http://www.flashmove.com/tips/cf/


KaHuNa said:
I think this method could be fine, because i can make the eval in flash and
the server works less....
thank you.


Giri said:
Are you perhaps trying to ouput these values into a text file that is then
read in by Flash (which will then assign values in the text file to
variables within its own programming environment) ?

In that case just output " strings" that you build up into that text file...

Pseudo code:

for each row x in my data...

varForFlash = "news" + x + "=" + dataIwantVarToEqual

Ouput varForFlash to text file

next row

This will give you a text file with:
news1 = firstRowData
news2 = 2ndRowData

etc...

Flash will then be able to consume...

I hope this helps, if not then please provide clearer details on what you
are doing as suggested by the others..

Cheers


Giri
variable
string
 
Back
Top