473,480 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamic Variables

Hi All,

Any ideas on how I could make the code below less verbose and more
scalable (more iterations are needed)...My thoughts are dynamically
named variables but I don't know how to do this (is it possible?)

VB.Net ideas preferred,
Many thanks,
Mark

=================================================

Select Case i
Case 1
Dim AttBtn1 As New ImageButton

With AttBtn1
.CssClass = "Att_Button " +
node.Attributes("type").Value
End With

e.Item.Cells("2").Controls.Add(AttBtn1)

Case 2
Dim AttBtn2 As New ImageButton
With AttBtn2
.CssClass = "Att_Button " +
node.Attributes("type").Value
End With

e.Item.Cells("2").Controls.Add(AttBtn2)

Case 3
Dim AttBtn3 As New ImageButton
With AttBtn3
.CssClass = "Att_Button " +
node.Attributes("type").Value
End With

e.Item.Cells("2").Controls.Add(AttBtn3)

'repeat ad infinitum

End Select
================================================== =

Jan 3 '06 #1
4 1240
What is the "i" variable ?

Here it seems to me this is the exact same code in all branch so why have
branches ? You can perfectly use the same variable for several controls one
after the other. If you need to keep a reference to those controls you could
use an array.

--
Patrice

"Cuperman" <ma**@liquidjelly.co.uk> a écrit dans le message de
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi All,

Any ideas on how I could make the code below less verbose and more
scalable (more iterations are needed)...My thoughts are dynamically
named variables but I don't know how to do this (is it possible?)

VB.Net ideas preferred,
Many thanks,
Mark

=================================================

Select Case i
Case 1
Dim AttBtn1 As New ImageButton

With AttBtn1
.CssClass = "Att_Button " +
node.Attributes("type").Value
End With

e.Item.Cells("2").Controls.Add(AttBtn1)

Case 2
Dim AttBtn2 As New ImageButton
With AttBtn2
.CssClass = "Att_Button " +
node.Attributes("type").Value
End With

e.Item.Cells("2").Controls.Add(AttBtn2)

Case 3
Dim AttBtn3 As New ImageButton
With AttBtn3
.CssClass = "Att_Button " +
node.Attributes("type").Value
End With

e.Item.Cells("2").Controls.Add(AttBtn3)

'repeat ad infinitum

End Select
================================================== =

Jan 3 '06 #2
Hi Patrice
The i is a counter. I was hoping to use a Dim AttBtn + i as
ImageButton logic.

If I can use the same variable name again and again, then i probably
havn't got a problem at all.

Thanks for your help.
Mark

Jan 3 '06 #3

"Cuperman" <ma**@liquidjelly.co.uk> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
Hi All,

Any ideas on how I could make the code below less verbose and more
scalable (more iterations are needed)...My thoughts are dynamically
named variables but I don't know how to do this (is it possible?)

VB.Net ideas preferred,
Many thanks,
Mark

=================================================


If don't know VB.net but I give it a try :)
Why don't you try to put this in the counter loop:
Dim AttBtn As New ImageButton
AttBtn.CssClass = "Att_Button " +
node.Attributes("type").Value
e.Item.Cells("2").Controls.Add(AttBtn)

Best Regards,

Jeroen Vandezande.
Jan 3 '06 #4
No problem. Once the control is created you add it to the control
collection. From there you can reuse this variable for another control. The
control is still available as it has been added to the list of controls.

--
Patrice

"Cuperman" <ma**@liquidjelly.co.uk> a écrit dans le message de
news:11*********************@z14g2000cwz.googlegro ups.com...
Hi Patrice
The i is a counter. I was hoping to use a Dim AttBtn + i as
ImageButton logic.

If I can use the same variable name again and again, then i probably
havn't got a problem at all.

Thanks for your help.
Mark

Jan 3 '06 #5

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

Similar topics

11
2345
by: propizzy | last post by:
Appreciate any help!!! PROBLEM: I have this form that allows the user to dynamically create additional fields (see javascript code bellow). I am trying to retrieve the values entered into these...
2
8393
by: Tommy Lang | last post by:
Hi everybody! I am trying to learn the basics of C++ myself and have a hard time understanding some stuff like pointers and references etc. I have created a small program that adds two numbers...
1
2229
by: Tommy Lang | last post by:
I am trying to learn to use dynamic variables. I have pasted the code below. Is this the proper way of using dynamic variables? Thanks, Tommy ...
4
13041
by: Tim.D | last post by:
People, I've ventured into the wonderful world of Stored Procedures. My first experience has been relatively successful however I am stuck on using host variables to specifiy actualy table or...
1
17619
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
28
4571
by: Dennis | last post by:
I have a function which is called from a loop many times. In that function, I use three variables as counters and for other purposes. I can either use DIM for declaring the variables or Static. ...
12
6211
by: scott | last post by:
Is there a way to create dynamic variables when looping through a recordset? For example below, after the 1st loop I'd have myVarA1 and myVarB1, after 2nd loop, I'd get myVarA2 and myVarB2. CODE...
2
2923
by: deejayquai | last post by:
Hi I'm trying to produce a report based on a dynamic crosstab. Ultimately i'd like the report to actually become a sub report within a student end of year record of achievement. The dynamic...
2
6340
by: JWL | last post by:
Hi I need to create a bunch of sites with slightly dynamic CSS. Basically, all the image paths in the CSS need to be dynamic, depending on the values of certain ASP variables. I can think of...
3
1931
by: Mark S. | last post by:
As I understand it, C# doesn't offer dynamic variable names. Below is my attempted workaround. Is what I'm doing possible? FYI, I already read all the "why in the world do you need dynamic...
0
6905
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...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
6908
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2994
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2980
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.