473,385 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Creating variables in a loop!

Hey guys,

Is there ANY way to accomplish this: (see below)? Basically, I want to
have a loop (a < 3 is just for testing purposes, it will be an underermined
amount). In this loop, I want to be able to create a new cell each time. In
this cell, I want the variable name to change. Is this at ALL possible? I've
never been able to figure this out in some of the other languages.

Any help would GREATLY be appreciated.
TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell = new TableCell();
tmRow.Cells.Add(tmCell);
CheckBox chk = new CheckBox();
chk.Text = "This is a test for #" + a;
tmCell.Controls.Add(chk);
tmRow.Cells.Add(tmCell);
a++;
}

would it be something like this???

TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell#a# = new TableCell();
tmRow.Cells.Add(tmCell#a#);
CheckBox chk#a# = new CheckBox();
chk#a#.Text = "This is a test for #" + a;
tmCell#a#.Controls.Add(chk);
tmRow#a#.Cells.Add(tmCell#a#);
a++;
}
Thanks!!!
Apr 3 '07 #1
4 1579
No. It also wouldn't do much good as a variable is only alive for the scope
of the loop and doesn't exist outside it. Keep in mind, you are creating an
object here, specifically object inherited from a webcontrol object. That
means you have a property available to you that you can set the ID of the
resultant control. The tmCell.ID property would allow you to set the name of
the control. You may also want to set the AccessKey property as well. Try
playing with this concept a bit as even if you could alter the name of the
variable in the loop, it doesn't do you any good as that reference is
useless the second you iterate through the loop again, or after the loop
completes.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Todd Jaspers" <To*********@discussions.microsoft.comwrote in message
news:A6**********************************@microsof t.com...
Hey guys,

Is there ANY way to accomplish this: (see below)? Basically, I want
to
have a loop (a < 3 is just for testing purposes, it will be an
underermined
amount). In this loop, I want to be able to create a new cell each time.
In
this cell, I want the variable name to change. Is this at ALL possible?
I've
never been able to figure this out in some of the other languages.

Any help would GREATLY be appreciated.
TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell = new TableCell();
tmRow.Cells.Add(tmCell);
CheckBox chk = new CheckBox();
chk.Text = "This is a test for #" + a;
tmCell.Controls.Add(chk);
tmRow.Cells.Add(tmCell);
a++;
}

would it be something like this???

TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell#a# = new TableCell();
tmRow.Cells.Add(tmCell#a#);
CheckBox chk#a# = new CheckBox();
chk#a#.Text = "This is a test for #" + a;
tmCell#a#.Controls.Add(chk);
tmRow#a#.Cells.Add(tmCell#a#);
a++;
}
Thanks!!!

Apr 3 '07 #2
Mark, thanks for the response, I appreciate it.

It appears to work, the only thing I'm a little bit confused on is how I
retrieve the information (the boolean checked or not checked) back from the
variable if the variable is in fact the same for each one?

Any hints on how I might be able to retrieve the boolean state of each of
them after the grid / table has already been built?
Thanks!!!

Todd

"Mark Fitzpatrick" wrote:
No. It also wouldn't do much good as a variable is only alive for the scope
of the loop and doesn't exist outside it. Keep in mind, you are creating an
object here, specifically object inherited from a webcontrol object. That
means you have a property available to you that you can set the ID of the
resultant control. The tmCell.ID property would allow you to set the name of
the control. You may also want to set the AccessKey property as well. Try
playing with this concept a bit as even if you could alter the name of the
variable in the loop, it doesn't do you any good as that reference is
useless the second you iterate through the loop again, or after the loop
completes.
--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006

"Todd Jaspers" <To*********@discussions.microsoft.comwrote in message
news:A6**********************************@microsof t.com...
Hey guys,

Is there ANY way to accomplish this: (see below)? Basically, I want
to
have a loop (a < 3 is just for testing purposes, it will be an
underermined
amount). In this loop, I want to be able to create a new cell each time.
In
this cell, I want the variable name to change. Is this at ALL possible?
I've
never been able to figure this out in some of the other languages.

Any help would GREATLY be appreciated.
TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell = new TableCell();
tmRow.Cells.Add(tmCell);
CheckBox chk = new CheckBox();
chk.Text = "This is a test for #" + a;
tmCell.Controls.Add(chk);
tmRow.Cells.Add(tmCell);
a++;
}

would it be something like this???

TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell#a# = new TableCell();
tmRow.Cells.Add(tmCell#a#);
CheckBox chk#a# = new CheckBox();
chk#a#.Text = "This is a test for #" + a;
tmCell#a#.Controls.Add(chk);
tmRow#a#.Cells.Add(tmCell#a#);
a++;
}
Thanks!!!


Apr 3 '07 #3
Todd Jaspers wrote:
Hey guys,

Is there ANY way to accomplish this: (see below)? Basically, I want to
have a loop (a < 3 is just for testing purposes, it will be an underermined
amount). In this loop, I want to be able to create a new cell each time. In
this cell, I want the variable name to change. Is this at ALL possible? I've
never been able to figure this out in some of the other languages.
No, you can't create dynamic variables. Use an array.

--
Göran Andersson
_____
http://www.guffa.com
Apr 3 '07 #4
Mark, thanks for the response, I appreciate it.
>
It appears to work, the only thing I'm a little bit confused on is how
I retrieve the information (the boolean checked or not checked) back
from the variable if the variable is in fact the same for each one?

Any hints on how I might be able to retrieve the boolean state of each
of them after the grid / table has already been built?

Thanks!!!

Todd
You added the checkboxes to tablecells, that were added to a tablerow.
You can retrieve them the same way: loop through the Cells collection
of the row, and find the first (only) control inside that cell.
It's "just" a Control, so you will have to cast it to a CheckBox.

Hans Kesting
>
"Mark Fitzpatrick" wrote:
>No. It also wouldn't do much good as a variable is only alive for the
scope of the loop and doesn't exist outside it. Keep in mind, you are
creating an object here, specifically object inherited from a
webcontrol object. That means you have a property available to you
that you can set the ID of the resultant control. The tmCell.ID
property would allow you to set the name of the control. You may also
want to set the AccessKey property as well. Try playing with this
concept a bit as even if you could alter the name of the variable in
the loop, it doesn't do you any good as that reference is useless the
second you iterate through the loop again, or after the loop
completes.

--
Hope this helps,
Mark Fitzpatrick
Former Microsoft FrontPage MVP 199?-2006
"Todd Jaspers" <To*********@discussions.microsoft.comwrote in
message news:A6**********************************@microsof t.com...
>>Hey guys,

Is there ANY way to accomplish this: (see below)? Basically, I want
to
have a loop (a < 3 is just for testing purposes, it will be an
underermined
amount). In this loop, I want to be able to create a new cell each
time.
In
this cell, I want the variable name to change. Is this at ALL
possible?
I've
never been able to figure this out in some of the other languages.
Any help would GREATLY be appreciated.

TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell = new TableCell();
tmRow.Cells.Add(tmCell);
CheckBox chk = new CheckBox();
chk.Text = "This is a test for #" + a;
tmCell.Controls.Add(chk);
tmRow.Cells.Add(tmCell);
a++;
}
would it be something like this???

TableRow tmRow = new TableRow();
tblCreditCards.Rows.Add(tmRow);
int a = 0;
while (a < 3)
{
TableCell tmCell#a# = new TableCell();
tmRow.Cells.Add(tmCell#a#);
CheckBox chk#a# = new CheckBox();
chk#a#.Text = "This is a test for #" + a;
tmCell#a#.Controls.Add(chk);
tmRow#a#.Cells.Add(tmCell#a#);
a++;
}
Thanks!!!

Apr 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: John Smith | last post by:
This might be an absurd question, but is it possible to create variables on the fly? For example, if I have an array of values myArray(0) = "foo" myArray(1) = "bar" myArray(2) = "foobar" ...
10
by: Dee | last post by:
Is C++ the best language to create a Windows based Instant Messenger? Something along the lines of MSN Messenger, ICQ, Yahoo Chat, etc? Are there any downloadable full or trial SDK's out there?...
9
by: Patrick.O.Ige | last post by:
I have a code below and its a PIE & BAR CHART. The values now are all static but I want to be able to pull the values from a database. Can you guys give me some ideas to do this? Thanks ...
2
by: Dave Monk | last post by:
Hi, I'm reasonably proficient in PHP but have been asked how to do something which has got me stumped. Hence, my posting: I want to create a small number of variables, $pos1, $pos2 ... $pos5...
3
by: Damo | last post by:
Hi, I want to create variables in a loop, each with a different name. Here is the loop i'm using: if (is_array($attribs)) { echo "Attributes : <br />"; while(list($key,$val) =...
1
by: joe_doufu | last post by:
I'm creating a page with multiple "widgets", each with its own XMLHttpRequest object, so the user can play with the widgets in parallel. The widgets are enclosed in divs with class "widget" and a...
13
by: jkimbler | last post by:
As part of our QA of hardware and firmware for the company I work for, we need to automate some testing of devices and firmware. Since not everybody here knows C#, I'm looking to create a new...
14
by: tdahsu | last post by:
I have twenty-five checkboxes I need to create (don't ask): self.checkbox1 = ... self.checkbox2 = ... .. .. .. self.checkbox25 = ... Right now, my code has 25 lines in it, one for each...
6
by: AMP | last post by:
Hello, I am trying to do the following with a loop because the amount of channels can change. uint Chan_1 = 0; uint Chan_2 = 0; uint Chan_3 = 0; uint Chan_4 = 0; uint Chan_5 = 0; uint Chan_6...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.