473,698 Members | 2,632 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("mmsS pecRecord").Row s(0)("Q1")
txtQ2.Text = ds.Tables("mmsS pecRecord").Row s(0)("Q2")
.....
txtQ10.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(0)(field)
Next
--------------

Thank you for your help.

David
Apr 4 '06 #1
6 2262
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("mmsS pecRecord").Row s(0)("Q1")
txtQ2.Text = ds.Tables("mmsS pecRecord").Row s(0)("Q2")
....
txtQ10.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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.Tab les("mmsSpecRec ord").Rows(0)(f ield)) Then
score.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(0)("Q1")
txtQ2.Text = ds.Tables("mmsS pecRecord").Row s(0)("Q2")
....
txtQ10.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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>.Tex t = <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.Tab les("mmsSpecRec ord").Rows(0)(f ield)) Then
score.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(0)("Q1")
txtQ2.Text = ds.Tables("mmsS pecRecord").Row s(0)("Q2")
....
txtQ10.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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>.Tex t = <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.Tab les("mmsSpecRec ord").Rows(0)(f ield)) Then
score.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(0)("Q1")
> txtQ2.Text = ds.Tables("mmsS pecRecord").Row s(0)("Q2")
> ....
> txtQ10.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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>.Tex t = <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.Tab les("mmsSpecRec ord").Rows(0)(f ield)) Then
score.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(0)("Q1")
> txtQ2.Text = ds.Tables("mmsS pecRecord").Row s(0)("Q2")
> ....
> txtQ10.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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>.Tex t = <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.Tab les("mmsSpecRec ord").Rows(0)(f ield)) Then
score.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(0)("Q1")
> > txtQ2.Text = ds.Tables("mmsS pecRecord").Row s(0)("Q2")
> > ....
> > txtQ10.Text = ds.Tables("mmsS pecRecord").Row s(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("mmsS pecRecord").Row s(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
1731
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
1836
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 to identify only those tables beginning with the letters "JA". Is this possible? Or, should I break down and manually type in all the table names?
7
21938
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 http://www.accessmonster.com
3
15088
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 Error End Enum
9
53742
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
1851
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 to do it? Thanx in advance.
22
2359
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; k<1000; k+ +) loop, but there seems to be several subtle ways to enumerate all 0..0xffff values using ushort. And no, for(port=0; port <PORT_MAX; port++) {} is not one of them. Yakov
1
2707
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 2), so that at the end of each section the total can be automatically calculated to eventually have a final total of all the sections. My Questions 1. How to assign values to radio button selections 2. Which formula would I use to add all...
0
8685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8612
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4373
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3053
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 we have to send another system
3
2008
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.