Wrox Programmer Forums
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old January 5th, 2008, 01:30 PM
Registered User
Join Date: Jan 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Accessing Names

Hello everybody!
I spent one night and whole day to get out of this stuck.

I have problem with naming my button. For example:I have my own XPbutton(UserControl). I want to put the code in core of this control, because on form I have always 2 buttons. button1 name "btn(0)" and button2 named "btn(1)". So it is a control array(name is "btn" and indexes are 0 and 1. I want that whenever after the button1 "btn(0)" is presseed, the button2 "btn(1)" will change the caption. I solve the problem with For Each....IfTypeOf...etc, but I don't wanna use this solution, because if I use that solution, sth else go wrong. So I want just strictly change the caption of button.

If I use Screen.ActiveForm.btn(1).Caption = "yes" - this works. But this are my navigation btns, so I want to use them many times. So I did :
dim bName as string: bName = ScreenActiveControl.Name
dim bInd as Byte: bInd=Screen.ActiveControl.Index. So far so good.

Now I just want to locate:
Screen.Activeform.Contorls(bName(bInd+1)).Caption = "Caption for Second Button" -- Of course this doesn't work, but how can I solve this. Once again, I dont want to use For Each sentence.
Or just shorter, hot to access any control, if you partly know its name.

Please any suggestion?

Greetings from Slovenia.

Old January 6th, 2008, 01:49 PM
Friend of Wrox
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi

hey there.. you croos post this.. not good ;)

Why use a so dificult solution?? why not just change the name of the other button when you press any of them?



================================================== =========
Read this if you want to know how to get a correct reply for your question:
^^Took that from dparsons signature and he Took that from planoie's profile
================================================== =========
My programs achieved a new certification (can you say the same?):
================================================== =========
I know that CVS was evil, and now i got the proof:
================================================== =========
Old January 7th, 2008, 09:27 PM
Registered User
Join Date: Jan 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts

Hey "gbianchi"!
Thaks for your interest. I tried your suggested way. But it doesn't work. Because its problem in exact naming. If I use exact name-no problem. But if I want to use for example public sub, I cannot reach that contorol. Even if I use different names insted of control array.

Thanks anyway.

P.S: I think i am close to solution. When I (If I) solve this problem, I will tell everybpdy, how.

Old January 7th, 2008, 09:52 PM
Registered User
Join Date: Jan 2008
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts

I know that my post is a little confused, but Brian solved them.

I knew it should be some trivial trick:
Screen.ActiveForm.Controls(bName)(bInd + 1) -- WORKS.

Thanks again to all.

Old January 8th, 2008, 05:07 PM
Friend of Wrox
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts

This is cross-posted at http://p2p.wrox.com/topic.asp?TOPIC_ID=68101.

edit ————————————————†”————————————————⠀”———————————————— ————————

Hey Gonzo: I just noticed that i have passed your post-count by 1 (1300 to 1301). But who’s counting?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Names within tags ? tjclifford XSLT 3 June 10th, 2008 08:33 AM
To Many Names bachuss SQL Language 0 January 18th, 2006 12:40 PM
Table names arnabghosh SQL Server 2000 3 November 24th, 2005 10:01 AM
Constraint for names barkingstars Oracle 2 April 14th, 2004 01:29 PM
User Names Ben Horne Forum and Wrox.com Feedback 4 April 8th, 2004 08:30 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.