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

Home Posts Topics Members FAQ

for loop is used to assign values to textboxed?

I try to use "for" loop to retrieve and assign values in web form. The code
is in the following. But it can not be compiled.
What I want to do is:
txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1")
txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2")
.....
txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10")

------code -------
Dim field As String = "Q"
Dim score As String = "txtQ"
For i As Integer = 1 To 10
field += i
score += i
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Next
--------------

Thank you for your help.

David
Apr 4 '06 #1
6 2247
you cannot have a Textbox and a local variable both called 'score'. If this
is not the problem what is the compliation error?

"david" wrote:
I try to use "for" loop to retrieve and assign values in web form. The code
is in the following. But it can not be compiled.
What I want to do is:
txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1")
txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2")
....
txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10")

------code -------
Dim field As String = "Q"
Dim score As String = "txtQ"
For i As Integer = 1 To 10
field += i
score += i
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Next
--------------

Thank you for your help.

David

Apr 4 '06 #2
textbox IDs:
txtQ1, txtQ2, ...., txtQ10.

Can I use a variable and FOR loop to assign values to those boxes like what
I did?
The proble is the variable score as string. I have changed as follows
-----
For i As Integer = 1 To 35
field = "Q" + i
score = "txtQ" + i
If Not IsDBNull(ds.Tables("mmsSpecRecord").Rows(0)(field) ) Then
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Else
score.Text = "NA"
End If

Next
-----
It is suppoesed to do the following:

i=1, score = txtQ1 and field=Q1
i=2, score =txtQ2 and field =Q2
....
i=10, score =txtQ10 and field=Q10

But they do not know score ( think it undefined).
How to use loop to get the result?

David

"Steven" wrote:
you cannot have a Textbox and a local variable both called 'score'. If this
is not the problem what is the compliation error?

"david" wrote:
I try to use "for" loop to retrieve and assign values in web form. The code
is in the following. But it can not be compiled.
What I want to do is:
txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1")
txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2")
....
txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10")

------code -------
Dim field As String = "Q"
Dim score As String = "txtQ"
For i As Integer = 1 To 10
field += i
score += i
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Next
--------------

Thank you for your help.

David

Apr 4 '06 #3
What is score defined as? In one part of your code you are assigning it as
though it is a string variable.
e.g.
score = "txtQ" + i
elsewhere it seems you are trying to assign to a Text property of score,
which would suggest score is a control.
e.g.
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)

again later in the example you are assigning score to the control txtQ1 not
the test property if txtQ1
e.g.
i=1, score = txtQ1 and field=Q1

if you assign score to txtQ1 then you are assigning score to the control not
the text within.
e.g.
i=1, score = txtQ1 and field=Q1
should be
i=1, score = txtQ1.Text

if you assign score to "txtQ" + i this will give score a text value of
"txtQ1" .... "txtQ35" not the text value of the control.
A string variable should alsway be assigned <variable> = <string value>
A textbox Text property should be assigned <control>.Text = <string value>
hope this helps if not can you post the entire method with the declaration
for 'score.

"david" wrote:
textbox IDs:
txtQ1, txtQ2, ...., txtQ10.

Can I use a variable and FOR loop to assign values to those boxes like what
I did?
The proble is the variable score as string. I have changed as follows
-----
For i As Integer = 1 To 35
field = "Q" + i
score = "txtQ" + i
If Not IsDBNull(ds.Tables("mmsSpecRecord").Rows(0)(field) ) Then
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Else
score.Text = "NA"
End If

Next
-----
It is suppoesed to do the following:

i=1, score = txtQ1 and field=Q1
i=2, score =txtQ2 and field =Q2
...
i=10, score =txtQ10 and field=Q10

But they do not know score ( think it undefined).
How to use loop to get the result?

David

"Steven" wrote:
you cannot have a Textbox and a local variable both called 'score'. If this
is not the problem what is the compliation error?

"david" wrote:
I try to use "for" loop to retrieve and assign values in web form. The code
is in the following. But it can not be compiled.
What I want to do is:
txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1")
txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2")
....
txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10")

------code -------
Dim field As String = "Q"
Dim score As String = "txtQ"
For i As Integer = 1 To 10
field += i
score += i
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Next
--------------

Thank you for your help.

David

Apr 4 '06 #4
Sorry, I just come back from meeting.
I mean that use score="txtQ"+i+".Text" instead. I will try it.

David

"Steven" wrote:
What is score defined as? In one part of your code you are assigning it as
though it is a string variable.
e.g.
score = "txtQ" + i
elsewhere it seems you are trying to assign to a Text property of score,
which would suggest score is a control.
e.g.
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)

again later in the example you are assigning score to the control txtQ1 not
the test property if txtQ1
e.g.
i=1, score = txtQ1 and field=Q1

if you assign score to txtQ1 then you are assigning score to the control not
the text within.
e.g.
i=1, score = txtQ1 and field=Q1
should be
i=1, score = txtQ1.Text

if you assign score to "txtQ" + i this will give score a text value of
"txtQ1" .... "txtQ35" not the text value of the control.
A string variable should alsway be assigned <variable> = <string value>
A textbox Text property should be assigned <control>.Text = <string value>
hope this helps if not can you post the entire method with the declaration
for 'score.

"david" wrote:
textbox IDs:
txtQ1, txtQ2, ...., txtQ10.

Can I use a variable and FOR loop to assign values to those boxes like what
I did?
The proble is the variable score as string. I have changed as follows
-----
For i As Integer = 1 To 35
field = "Q" + i
score = "txtQ" + i
If Not IsDBNull(ds.Tables("mmsSpecRecord").Rows(0)(field) ) Then
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Else
score.Text = "NA"
End If

Next
-----
It is suppoesed to do the following:

i=1, score = txtQ1 and field=Q1
i=2, score =txtQ2 and field =Q2
...
i=10, score =txtQ10 and field=Q10

But they do not know score ( think it undefined).
How to use loop to get the result?

David

"Steven" wrote:
you cannot have a Textbox and a local variable both called 'score'. If this
is not the problem what is the compliation error?

"david" wrote:

> I try to use "for" loop to retrieve and assign values in web form. The code
> is in the following. But it can not be compiled.
> What I want to do is:
> txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1")
> txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2")
> ....
> txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10")
>
> ------code -------
> Dim field As String = "Q"
> Dim score As String = "txtQ"
> For i As Integer = 1 To 10
> field += i
> score += i
> score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
> Next
> --------------
>
> Thank you for your help.
>
> David

Apr 4 '06 #5
I try to use "score" as variable of textbox control and change the value in
loop.
So you mean that I have to declare score as textbox:
dim score as textbox

David

"Steven" wrote:
What is score defined as? In one part of your code you are assigning it as
though it is a string variable.
e.g.
score = "txtQ" + i
elsewhere it seems you are trying to assign to a Text property of score,
which would suggest score is a control.
e.g.
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)

again later in the example you are assigning score to the control txtQ1 not
the test property if txtQ1
e.g.
i=1, score = txtQ1 and field=Q1

if you assign score to txtQ1 then you are assigning score to the control not
the text within.
e.g.
i=1, score = txtQ1 and field=Q1
should be
i=1, score = txtQ1.Text

if you assign score to "txtQ" + i this will give score a text value of
"txtQ1" .... "txtQ35" not the text value of the control.
A string variable should alsway be assigned <variable> = <string value>
A textbox Text property should be assigned <control>.Text = <string value>
hope this helps if not can you post the entire method with the declaration
for 'score.

"david" wrote:
textbox IDs:
txtQ1, txtQ2, ...., txtQ10.

Can I use a variable and FOR loop to assign values to those boxes like what
I did?
The proble is the variable score as string. I have changed as follows
-----
For i As Integer = 1 To 35
field = "Q" + i
score = "txtQ" + i
If Not IsDBNull(ds.Tables("mmsSpecRecord").Rows(0)(field) ) Then
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Else
score.Text = "NA"
End If

Next
-----
It is suppoesed to do the following:

i=1, score = txtQ1 and field=Q1
i=2, score =txtQ2 and field =Q2
...
i=10, score =txtQ10 and field=Q10

But they do not know score ( think it undefined).
How to use loop to get the result?

David

"Steven" wrote:
you cannot have a Textbox and a local variable both called 'score'. If this
is not the problem what is the compliation error?

"david" wrote:

> I try to use "for" loop to retrieve and assign values in web form. The code
> is in the following. But it can not be compiled.
> What I want to do is:
> txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1")
> txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2")
> ....
> txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10")
>
> ------code -------
> Dim field As String = "Q"
> Dim score As String = "txtQ"
> For i As Integer = 1 To 10
> field += i
> score += i
> score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
> Next
> --------------
>
> Thank you for your help.
>
> David

Apr 4 '06 #6
If I declare score as TextBox, how can I assign it txtQ1.Text, txtQ2.Text,
..... and so on dynamically? where TxtQ1, txtQ2, ... are TextBox control's IDs.

David

"david" wrote:
I try to use "score" as variable of textbox control and change the value in
loop.
So you mean that I have to declare score as textbox:
dim score as textbox

David

"Steven" wrote:
What is score defined as? In one part of your code you are assigning it as
though it is a string variable.
e.g.
score = "txtQ" + i
elsewhere it seems you are trying to assign to a Text property of score,
which would suggest score is a control.
e.g.
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)

again later in the example you are assigning score to the control txtQ1 not
the test property if txtQ1
e.g.
i=1, score = txtQ1 and field=Q1

if you assign score to txtQ1 then you are assigning score to the control not
the text within.
e.g.
i=1, score = txtQ1 and field=Q1
should be
i=1, score = txtQ1.Text

if you assign score to "txtQ" + i this will give score a text value of
"txtQ1" .... "txtQ35" not the text value of the control.
A string variable should alsway be assigned <variable> = <string value>
A textbox Text property should be assigned <control>.Text = <string value>
hope this helps if not can you post the entire method with the declaration
for 'score.

"david" wrote:
textbox IDs:
txtQ1, txtQ2, ...., txtQ10.

Can I use a variable and FOR loop to assign values to those boxes like what
I did?
The proble is the variable score as string. I have changed as follows
-----
For i As Integer = 1 To 35
field = "Q" + i
score = "txtQ" + i
If Not IsDBNull(ds.Tables("mmsSpecRecord").Rows(0)(field) ) Then
score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
Else
score.Text = "NA"
End If

Next
-----
It is suppoesed to do the following:

i=1, score = txtQ1 and field=Q1
i=2, score =txtQ2 and field =Q2
...
i=10, score =txtQ10 and field=Q10

But they do not know score ( think it undefined).
How to use loop to get the result?

David

"Steven" wrote:

> you cannot have a Textbox and a local variable both called 'score'. If this
> is not the problem what is the compliation error?
>
> "david" wrote:
>
> > I try to use "for" loop to retrieve and assign values in web form. The code
> > is in the following. But it can not be compiled.
> > What I want to do is:
> > txtQ1.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q1")
> > txtQ2.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q2")
> > ....
> > txtQ10.Text = ds.Tables("mmsSpecRecord").Rows(0)("Q10")
> >
> > ------code -------
> > Dim field As String = "Q"
> > Dim score As String = "txtQ"
> > For i As Integer = 1 To 10
> > field += i
> > score += i
> > score.Text = ds.Tables("mmsSpecRecord").Rows(0)(field)
> > Next
> > --------------
> >
> > Thank you for your help.
> >
> > David

Apr 4 '06 #7

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

Similar topics

6
1723
by: Buddy Ackerman | last post by:
I created a simple class: Public Class MyTestClass Public Test() As String End Class I tried to assign some values to the array Test() and display them like this:
2
1830
by: MLH | last post by:
Gentlemen: I have declared an array Dim MyTables(14) AS Long Now I want to assign values for MyTables(0) - MyTables(14) equal to the number of records in each table. Catch, I want the code...
7
21919
by: Paul via AccessMonster.com | last post by:
I have a report with some Unbound text boxes. I want to shows the values in these text boxes from my VBA code. How can I assign the valuse thru code ? Pls help me. -- Message posted via...
3
15046
by: giant food | last post by:
This seems like a long shot, but I wondered if there's a way to loop over the values in an Enum. For example, say I have an Enum as follows: Public Enum statusValues Ready Running Finished...
9
53573
by: Fred Zwarts | last post by:
What is the recommended way to loop over all enum values of a certain enum type? Consider the following definition: typdef enum {A=2, B, C=5, D} E; then for (E x = A; x <= D; ++x) { ... }
8
1834
by: fanoftvb | last post by:
hi, is it possible to assign values to button? I will not need to enter any values and when i click on the button, the values on the datagrid and database will automatically change. Is there anyway...
22
2314
by: Yakov | last post by:
What would be the nicest way to write the loop for all values of unsigned short (0..0xffff), usnig 'unsigned short port;' as an index ? For comparison, there is just one way to write the for(k=0;...
1
2699
by: NewHeights | last post by:
Excel 2007- I have a survey that uses radio buttons (3 choices each answer) to select the answer.? My trouble starts with assigning values to the answers (Answer 1 is 0, Answer 2 is 1, Answer 3 is...
0
7225
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
7124
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
7326
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
5629
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,...
0
4707
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
3195
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
3182
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1558
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 ...
0
418
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.