473,405 Members | 2,310 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,405 software developers and data experts.

populate textboxes with a loop??

Apologies in advance if this sounds slow-witted, but I didn't find it here.

Need to populate some textboxes on a form. While I could hard code it (the
number of options aren't that high), it would be more compact/efficient to
use a loop.

However, I haven't found anything that describes how to reference the
textboxes sequentially ... evaluating the hard part of the textbox name,
with the number of the loop iteration, to address the specific box.

E.G. textboxes named textbox1, textbox2, textbox3

For x = 1 to 3
{textbox(x)} = x
Next x

What I need is how to call out the part of the line {in braces} so that it
executes dynamically. In the stupid example, t-box 1 would have 1, t-box 2
2, t-box 3 3.

I really don't want to get into arrays here, would be killing an ant with a
cannon, and more learning curve to overcome ... even though my example looks
like array notation

Thanks in advance for help with a real rookie question, but I don't write
much code ... as should be painfully obvious from the question.

Kevin
Aug 21 '05 #1
4 18784
> Apologies in advance if this sounds slow-witted, but I didn't find it
here.

Need to populate some textboxes on a form. While I could hard code it (the number of options aren't that high), it would be more compact/efficient to use a loop.

However, I haven't found anything that describes how to reference the
textboxes sequentially ... evaluating the hard part of the textbox name, with the number of the loop iteration, to address the specific box.

E.G. textboxes named textbox1, textbox2, textbox3

For x = 1 to 3
{textbox(x)} = x
Next x

What I need is how to call out the part of the line {in braces} so that it executes dynamically. In the stupid example, t-box 1 would have 1, t-box 2 2, t-box 3 3.

I really don't want to get into arrays here, would be killing an ant with a cannon, and more learning curve to overcome ... even though my example looks like array notation


You have the wrong impression about arrays... they are extremely useful
devices. In the case of controls, VB provides a construct called control
arrays. They are quite easy to work with and will easily do what you
asked. The key to creating a control array is to give all of the member
controls (they must be of the same type) the same name. The first
duplicate you name will popup a dialog box asking if you want to create
a control array. Answer Yes to the question. Each member of the control
array will have its Index property assigned a value and they will all
share the same events. The event procedures will automatically be given
a parameter (between the parentheses) called, believe it or not, Index.
The beauty of this system is that VB will automatically assign the Index
property value to this Index parameter so that you will know which
control's event was activated. Anyway, for reference purposes, you can
address the members of the control array just like you would the members
of a normal array. For example, the question you asked would be coded
this way...

For X = 1 To 3
Text1(x).Text = CStr(X)
Next

Look up "control arrays" (without the quote marks) in VB's help files
for more information.

Rick
Aug 21 '05 #2
Rick:

Guess I should have been more specific. This is in a MS access project
(form, specifically). Attempting what you outlined gives a duplicate name
error from access ... so no joy in mudville yet.

Other ways to evaluate a dynamic expression inside the code??

Kevin
"Rick Rothstein [MVP - Visual Basic]" <ri************@NOSPAMcomcast.net>
wrote in message news:i4********************@comcast.com...
Apologies in advance if this sounds slow-witted, but I didn't find it

here.

Need to populate some textboxes on a form. While I could hard code it

(the
number of options aren't that high), it would be more

compact/efficient to
use a loop.

However, I haven't found anything that describes how to reference the
textboxes sequentially ... evaluating the hard part of the textbox

name,
with the number of the loop iteration, to address the specific box.

E.G. textboxes named textbox1, textbox2, textbox3

For x = 1 to 3
{textbox(x)} = x
Next x

What I need is how to call out the part of the line {in braces} so

that it
executes dynamically. In the stupid example, t-box 1 would have 1,

t-box 2
2, t-box 3 3.

I really don't want to get into arrays here, would be killing an ant

with a
cannon, and more learning curve to overcome ... even though my example

looks
like array notation


You have the wrong impression about arrays... they are extremely useful
devices. In the case of controls, VB provides a construct called control
arrays. They are quite easy to work with and will easily do what you
asked. The key to creating a control array is to give all of the member
controls (they must be of the same type) the same name. The first
duplicate you name will popup a dialog box asking if you want to create
a control array. Answer Yes to the question. Each member of the control
array will have its Index property assigned a value and they will all
share the same events. The event procedures will automatically be given
a parameter (between the parentheses) called, believe it or not, Index.
The beauty of this system is that VB will automatically assign the Index
property value to this Index parameter so that you will know which
control's event was activated. Anyway, for reference purposes, you can
address the members of the control array just like you would the members
of a normal array. For example, the question you asked would be coded
this way...

For X = 1 To 3
Text1(x).Text = CStr(X)
Next

Look up "control arrays" (without the quote marks) in VB's help files
for more information.

Rick

Aug 21 '05 #3
What I really need is how do you:
Inside code, take a text string, concatenate the value of a counter,
evaluate the result in real time, and then use the result to set a control
value. Referencing a series of access form controls sequentially ... it
shouldn't be difficult, but I'm still getting zippo for help from the VB
help files.

Thanx again

"Kevin H" <sp*****@noyoudont.com> wrote in message
news:II********************@ptd.net...
Rick:

Guess I should have been more specific. This is in a MS access project
(form, specifically). Attempting what you outlined gives a duplicate name
error from access ... so no joy in mudville yet.

Other ways to evaluate a dynamic expression inside the code??

Kevin
"Rick Rothstein [MVP - Visual Basic]" <ri************@NOSPAMcomcast.net>
wrote in message news:i4********************@comcast.com...
Apologies in advance if this sounds slow-witted, but I didn't find it

here.

Need to populate some textboxes on a form. While I could hard code it

(the
number of options aren't that high), it would be more

compact/efficient to
use a loop.

However, I haven't found anything that describes how to reference the
textboxes sequentially ... evaluating the hard part of the textbox

name,
with the number of the loop iteration, to address the specific box.

E.G. textboxes named textbox1, textbox2, textbox3

For x = 1 to 3
{textbox(x)} = x
Next x

What I need is how to call out the part of the line {in braces} so

that it
executes dynamically. In the stupid example, t-box 1 would have 1,

t-box 2
2, t-box 3 3.

I really don't want to get into arrays here, would be killing an ant

with a
cannon, and more learning curve to overcome ... even though my example

looks
like array notation


You have the wrong impression about arrays... they are extremely useful
devices. In the case of controls, VB provides a construct called control
arrays. They are quite easy to work with and will easily do what you
asked. The key to creating a control array is to give all of the member
controls (they must be of the same type) the same name. The first
duplicate you name will popup a dialog box asking if you want to create
a control array. Answer Yes to the question. Each member of the control
array will have its Index property assigned a value and they will all
share the same events. The event procedures will automatically be given
a parameter (between the parentheses) called, believe it or not, Index.
The beauty of this system is that VB will automatically assign the Index
property value to this Index parameter so that you will know which
control's event was activated. Anyway, for reference purposes, you can
address the members of the control array just like you would the members
of a normal array. For example, the question you asked would be coded
this way...

For X = 1 To 3
Text1(x).Text = CStr(X)
Next

Look up "control arrays" (without the quote marks) in VB's help files
for more information.

Rick


Aug 21 '05 #4
> Guess I should have been more specific. This is in a MS access project
(form, specifically). Attempting what you outlined gives a duplicate name error from access ... so no joy in mudville yet.
Yes, you should definitely mention the type of project you are working
on. The newsgroups with "vb" in their names are almost exclusively for
the stand alone Visual Basic language. As you have seen, solutions that
work in it do not necessarily translate over to the VBA programming
modules contained within the Office product line. You might want to post
in a more relevant newsgroup. Microsoft has a public newsgroup server
that probably has a group that would be a closer fit to what you want
than this group. Try this one...

microsoft.public.access.macros

Other ways to evaluate a dynamic expression inside the code??


I don't program Office macros myself, so I don't know if VBA macros
expose a Controls collection or not, but this code will work in VB6...

Dim X As Long
For X = 1 To 3
Me.Controls("Text" & CStr(X)).Text = "TextBox #" & CStr(X)
Next

Me is a reference to the Form object the controls are on, so you might
have to substitute the VBA macro way of referring to the parent form.

Rick
Aug 21 '05 #5

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

Similar topics

0
by: anna | last post by:
I have a grid with some columns that are BOUND columns. I have three more columns that are TEMPLATE columns with textboxes inside. i need to populate one of the textboxes with information based on...
2
by: Mark | last post by:
I am attempting to populate several textbox controls from VBA code. With each attempt, I get the following error: "The macro or function set to the BeforeUpdate or ValidationRule property for...
12
by: Mike | last post by:
I'm calling a component to get my data. The component is returning a dataset. I need to populate text boxes on my aspx page with the data within the datalist. Where can I find an example that...
4
by: Thom | last post by:
I'm a real newbie so I apologize for the easy question. I have academic version of vb.net 2003. I am trying to write a multiline textbox with data from a text file. Properties for the textbox are...
2
by: MLH | last post by:
I would like to populate a table with the following information: tblPropertySettings - the GotFocus property setting string - the LostFocus property setting string I'd like to document...
4
by: Alex Denton | last post by:
Okay, here's my problem: I need to populate different fields in an HTML table with TextBoxes. For example, if I had 3 columns "Name", "Address", and "City"; I need to have a TextBox in all of...
2
by: rn5a | last post by:
This function in a VB class file takes UserID as a parameter & returns a SqlDataReader to the calling function which exists in a ASPX page: Namespace NConnect Public Class Cart Private sqlConn...
0
by: manbassie | last post by:
I have xml web service which returns a dataset. I have textboxes which need to be populated with this data and my problem is how to bind the data to the textboxes when the form loads and be able to...
1
by: Wernerh | last post by:
Hi all, A little problem someone can help me with. Got Access db connected through Adodc connection populating datagrid etc. What I am trying to achieve is for the database records which are each...
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: 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
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
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
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
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
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...

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.