473,508 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple loop question - code check

Hi

I have five check boxes in a windows form. They are called chkEQUDS01,
chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am getting the text
name for the check boxes from a datatable and have wrote the code below:

If dtEq.Rows(0).Item(2) = 1 Then
chkEQUDS01.Enabled = True
chkEQUDS01.Text = dtEq.Rows(0).Item(1)
End If

If dtEq.Rows(1).Item(2) = 1 Then
chkEQUDS02.Enabled = True
chkEQUDS02.Text = dtEq.Rows(1).Item(1)
End If
If dtEq.Rows(2).Item(2) = 1 Then
chkEQUDS03.Enabled = True
chkEQUDS03.Text = dtEq.Rows(2).Item(1)
End If
If dtEq.Rows(3).Item(2) = 1 Then
chkEQUDS04.Enabled = True
chkEQUDS04.Text = dtEq.Rows(3).Item(1)
End If
If dtEq.Rows(4).Item(2) = 1 Then
chkEQUDS05.Enabled = True
chkEQUDS05.Text = dtEq.Rows(4).Item(1)
End If
If dtEq.Rows(5).Item(2) = 1 Then
chkEQUDS06.Enabled = True
chkEQUDS06.Text = dtEq.Rows(5).Item(1)
End If

Can anyone tell me if there is a better way to write this? In particular,
how could I create an integer and then refer to a name and the integer which
make up the chkbox name, for example, chkEQUDi and as you password round
each loop i would increase by 1.

Hope this makes some sense?

Thanks
Rich
Nov 20 '05 #1
4 1328
you could create a control array and put your checkboxes in that

have a look here (mind the split)
http://msdn.microsoft.com/library/de...VisualCNET.asp

hope it helps

eric

"Rich" <richard> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi

I have five check boxes in a windows form. They are called chkEQUDS01,
chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am getting the text
name for the check boxes from a datatable and have wrote the code below:

If dtEq.Rows(0).Item(2) = 1 Then
chkEQUDS01.Enabled = True
chkEQUDS01.Text = dtEq.Rows(0).Item(1)
End If

If dtEq.Rows(1).Item(2) = 1 Then
chkEQUDS02.Enabled = True
chkEQUDS02.Text = dtEq.Rows(1).Item(1)
End If
If dtEq.Rows(2).Item(2) = 1 Then
chkEQUDS03.Enabled = True
chkEQUDS03.Text = dtEq.Rows(2).Item(1)
End If
If dtEq.Rows(3).Item(2) = 1 Then
chkEQUDS04.Enabled = True
chkEQUDS04.Text = dtEq.Rows(3).Item(1)
End If
If dtEq.Rows(4).Item(2) = 1 Then
chkEQUDS05.Enabled = True
chkEQUDS05.Text = dtEq.Rows(4).Item(1)
End If
If dtEq.Rows(5).Item(2) = 1 Then
chkEQUDS06.Enabled = True
chkEQUDS06.Text = dtEq.Rows(5).Item(1)
End If

Can anyone tell me if there is a better way to write this? In particular,
how could I create an integer and then refer to a name and the integer which make up the chkbox name, for example, chkEQUDi and as you password round
each loop i would increase by 1.

Hope this makes some sense?

Thanks
Rich

Nov 20 '05 #2
Heh, I was kinda avoiding this one. There is a CheckBox control array
already included in the DotNetFramework if you look at your Toolbox.

Just go to Add Components, and you'll see it in there. I think its in the
Microsoft.VisualBasic namespace.

-CJ

"EricJ" <er********@ThiSbitconsult.be.RE> wrote in message
news:40***********************@news.skynet.be...
you could create a control array and put your checkboxes in that

have a look here (mind the split)
http://msdn.microsoft.com/library/de...VisualCNET.asp
hope it helps

eric

"Rich" <richard> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi

I have five check boxes in a windows form. They are called chkEQUDS01,
chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am getting the text name for the check boxes from a datatable and have wrote the code below:

If dtEq.Rows(0).Item(2) = 1 Then
chkEQUDS01.Enabled = True
chkEQUDS01.Text = dtEq.Rows(0).Item(1)
End If

If dtEq.Rows(1).Item(2) = 1 Then
chkEQUDS02.Enabled = True
chkEQUDS02.Text = dtEq.Rows(1).Item(1)
End If
If dtEq.Rows(2).Item(2) = 1 Then
chkEQUDS03.Enabled = True
chkEQUDS03.Text = dtEq.Rows(2).Item(1)
End If
If dtEq.Rows(3).Item(2) = 1 Then
chkEQUDS04.Enabled = True
chkEQUDS04.Text = dtEq.Rows(3).Item(1)
End If
If dtEq.Rows(4).Item(2) = 1 Then
chkEQUDS05.Enabled = True
chkEQUDS05.Text = dtEq.Rows(4).Item(1)
End If
If dtEq.Rows(5).Item(2) = 1 Then
chkEQUDS06.Enabled = True
chkEQUDS06.Text = dtEq.Rows(5).Item(1)
End If

Can anyone tell me if there is a better way to write this? In particular, how could I create an integer and then refer to a name and the integer

which
make up the chkbox name, for example, chkEQUDi and as you password round
each loop i would increase by 1.

Hope this makes some sense?

Thanks
Rich


Nov 20 '05 #3
"Rich" <richard> schrieb
I have five check boxes in a windows form. They are called
chkEQUDS01, chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am
getting the text name for the check boxes from a datatable and have
wrote the code below:
Can anyone tell me if there is a better way to write this? In
particular, how could I create an integer and then refer to a name
and the integer which make up the chkbox name, for example, chkEQUDi
and as you password round each loop i would increase by 1.

Hope this makes some sense?


Add the controls to an array declared as a Form field:

Private m_chkEQUDS As Checkbox()
'...
m_chkEQUDS = new checkbox() _
{chkEQUDS01, chkEQUDS02, chkEQUDS03, chkEQUDS04, _
chkEQUDS05, chkEQUDS06}

Now you can use a loop on the array.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4
I'll try to remember that when i need it. (won't be the app i'm working on
atm)

eric

"CJ Taylor" <[cege] at [tavayn] dit commmmm> wrote in message
news:%2***************@tk2msftngp13.phx.gbl...
Heh, I was kinda avoiding this one. There is a CheckBox control array
already included in the DotNetFramework if you look at your Toolbox.

Just go to Add Components, and you'll see it in there. I think its in the
Microsoft.VisualBasic namespace.

-CJ

"EricJ" <er********@ThiSbitconsult.be.RE> wrote in message
news:40***********************@news.skynet.be...
you could create a control array and put your checkboxes in that

have a look here (mind the split)

http://msdn.microsoft.com/library/de...VisualCNET.asp

hope it helps

eric

"Rich" <richard> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi

I have five check boxes in a windows form. They are called chkEQUDS01, chkEQUDS02, chkEQUDS03, chkEQUDS04, and chkEQUDS05. I am getting the text name for the check boxes from a datatable and have wrote the code below:
If dtEq.Rows(0).Item(2) = 1 Then
chkEQUDS01.Enabled = True
chkEQUDS01.Text = dtEq.Rows(0).Item(1)
End If

If dtEq.Rows(1).Item(2) = 1 Then
chkEQUDS02.Enabled = True
chkEQUDS02.Text = dtEq.Rows(1).Item(1)
End If
If dtEq.Rows(2).Item(2) = 1 Then
chkEQUDS03.Enabled = True
chkEQUDS03.Text = dtEq.Rows(2).Item(1)
End If
If dtEq.Rows(3).Item(2) = 1 Then
chkEQUDS04.Enabled = True
chkEQUDS04.Text = dtEq.Rows(3).Item(1)
End If
If dtEq.Rows(4).Item(2) = 1 Then
chkEQUDS05.Enabled = True
chkEQUDS05.Text = dtEq.Rows(4).Item(1)
End If
If dtEq.Rows(5).Item(2) = 1 Then
chkEQUDS06.Enabled = True
chkEQUDS06.Text = dtEq.Rows(5).Item(1)
End If

Can anyone tell me if there is a better way to write this? In particular, how could I create an integer and then refer to a name and the integer

which
make up the chkbox name, for example, chkEQUDi and as you password round each loop i would increase by 1.

Hope this makes some sense?

Thanks
Rich



Nov 20 '05 #5

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

Similar topics

38
3479
by: jrlen balane | last post by:
basically what the code does is transmit data to a hardware and then receive data that the hardware will transmit. import serial import string import time from struct import * ser =...
6
4948
by: hoover_richard | last post by:
I am a newbie to C++ and I need help with a simple program I am trying to write. My program is designed to print all of the odd integers contained in an array and output the sum of the odd...
13
4095
by: na1paj | last post by:
here's a simple linked list program. the DeleteNode function is producing an infinit loop i think, but i can't figure out where.. #include <stdio.h> typedef struct { char *str; //str is a...
32
5063
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 *...
0
1673
by: rich | last post by:
Hi all, I have a fairly complex "feed" application that recieves messages from an external user-supplied API via a callback function, and attempts to forward these messages to another...
4
1312
by: theronnightstar | last post by:
I am having a problem with a small bit of code. I can't figure out why it won't work. Here: //code: #include <iostream> #include <fstream> #include <ctype.h> #include <string>
7
1368
by: Tony Johansson | last post by:
Hello! Why does not this cause a compile error because a ulong has never been implicitly convertible to byte? ulong vektor = {100000,200000,300000}; foreach(byte b in vektor) {...
3
1602
by: eDaddi | last post by:
I can't figure out why I cant get this simple loop to work. I'm using it to validate a form. I thought I could put the required field names in an array, loop through the array and have the it check...
1
5987
by: jerry | last post by:
i have written a simple phonebook program,i'll show you some of the codes,the program's head file is member.h . i suppose the head file works well.so i don't post it. here's the clips of main...
2
7584
by: cmb3587 | last post by:
I am having a problem with the validation of the account number and password. The beginning of the program asks for users account # then pwd. The program is then supposed to go to a checkID...
0
7227
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7127
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
7331
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7391
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...
1
7054
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
3188
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1564
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
768
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
424
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.