Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default On the lack of control arrays.

I am using Excel 97.

As fas as I understand VB in Excel does not have control arrays, no controls
have an index property.

On a form I have seven labels called lbl1 to lbl7. I would like to set their
captions to a(i) where a is an array and i runs from 1 to 7.

The code below does not work:

for i = 1 to 7
labelname = "lbl" & format(i)
&labelname.caption = a(i)
next

but is there a way to construct the name of the control as a string, and
then use it?

I would hate to have to say:
lbl1.caption = a(1)
lbl2.caption = a(2)
etc

Any help is greatly appreciated.

Sincerely,
Jan Nordgreen


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default On the lack of control arrays.

Hi Jan,

You can use the Controls collection to do this:

Controls("lbl" & CStr(i)).Caption = a(i)

--
Regards,

Jake Marx
www.longhead.com


Jan Nordgreen wrote:
I am using Excel 97.

As fas as I understand VB in Excel does not have control arrays, no
controls have an index property.

On a form I have seven labels called lbl1 to lbl7. I would like to
set their captions to a(i) where a is an array and i runs from 1 to 7.

The code below does not work:

for i = 1 to 7
labelname = "lbl" & format(i)
&labelname.caption = a(i)
next

but is there a way to construct the name of the control as a string,
and then use it?

I would hate to have to say:
lbl1.caption = a(1)
lbl2.caption = a(2)
etc

Any help is greatly appreciated.

Sincerely,
Jan Nordgreen

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default On the lack of control arrays.

&labelname . . . this ain't foxpro, clipper, or dbase <g

for i = 1 to 7
labelname = "lbl" & i
Userform1.Controls(labelname).caption = a(i)
next

"i" will be coerced to a string without an additional function or use
cstr(i) if you prefer

--
Regards,
Tom Ogilvy



Jan Nordgreen wrote in message
...
I am using Excel 97.

As fas as I understand VB in Excel does not have control arrays, no

controls
have an index property.

On a form I have seven labels called lbl1 to lbl7. I would like to set

their
captions to a(i) where a is an array and i runs from 1 to 7.

The code below does not work:

for i = 1 to 7
labelname = "lbl" & format(i)
&labelname.caption = a(i)
next

but is there a way to construct the name of the control as a string, and
then use it?

I would hate to have to say:
lbl1.caption = a(1)
lbl2.caption = a(2)
etc

Any help is greatly appreciated.

Sincerely,
Jan Nordgreen




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default On the lack of control arrays.

Jan,

You can use the following:

Controls(labelname).Caption = a(i)

--

John Green - Excel MVP
Sydney
Australia


"Jan Nordgreen" wrote in message ...
I am using Excel 97.

As fas as I understand VB in Excel does not have control arrays, no controls
have an index property.

On a form I have seven labels called lbl1 to lbl7. I would like to set their
captions to a(i) where a is an array and i runs from 1 to 7.

The code below does not work:

for i = 1 to 7
labelname = "lbl" & format(i)
&labelname.caption = a(i)
next

but is there a way to construct the name of the control as a string, and
then use it?

I would hate to have to say:
lbl1.caption = a(1)
lbl2.caption = a(2)
etc

Any help is greatly appreciated.

Sincerely,
Jan Nordgreen




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Counting the lack of a union of two lists Skippy Howenstein Excel Worksheet Functions 2 February 23rd 10 02:25 PM
Excel lack of compatibility robbiebell22 Excel Discussion (Misc queries) 1 July 23rd 08 01:30 AM
Control arrays on Excel 2007 userforms Informative Excel Discussion (Misc queries) 1 February 26th 08 09:36 PM
Help with GUI (for lack of a better term) Mike in Saukville Excel Discussion (Misc queries) 1 February 21st 07 09:55 PM
Nice idea lack of knowledge! carnelain Excel Discussion (Misc queries) 3 March 21st 06 07:40 PM


All times are GMT +1. The time now is 04:27 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"