Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Counting Certain Controls on a Form 1

Status
Not open for further replies.

clydejones

Programmer
Jan 11, 2001
153
0
0
US
Hi,

I have a form where I am creating image controls on the fly. What I need now is some code on how to get the number of image controls that were created. I can get the total number of controls on the form, but I only want the number of image controls. I've tried several things but nothing seems to work. Any help would be appreciated.


Clyde
 
Try doing this...

Code:
dim ctrl as control
dim Count as long

For each ctrl in Form
   If Type ctrl is Image then
       count = count + 1
   endif
next

Now I am not sure if that type of Image is exactly correct but the idea should work....I used this sort of code to just disable a certain type of control on a form once.

Hope this helps some. Mavors
Cincinnati, Ohio
 
Messed that up just a little

the IF should be


IF TypeOf ctrl Is Image then


Left out the "Of"...

Mavors
Cincinnati, Ohio
 
Clyde,

Another option that exists if you have a control array is to use the Ubound of the control array. For example if the name of the image control array is Image1, the following will return the count:

Image1.Ubound

Another option is to just maintain a count as you create them. Keep a count that gets incremented when you create the image. Decrement the count when you unload the image.

Hope that helps a bit.

-crater
 
Great Idea Crater...I think that Array of images is much better than mine....

With that you have minimal processing to get your count. Mavors
Cincinnati, Ohio
 
Thanks To All,

I've used Mavors method (By the way, I figured out the "TypeOf" thing). SC Your method is cool too. I could have used it because I am already storing the number of images that was created. I feel so silly. Oh well, I'm still living and learning. Thanks y'all. This really helped me get over a hump.

clyde
 
No problem. Glad I could help!

Mavors, I've never done it that way but that's a good way to do it as well. Just goes to show that there is always multiple ways to approach any problem!

-crater
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top