borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (HELP! Triangle in Circle Construction without Trig?)Next Topic (\"can\'t find project or library\" error) New Topic New Poll Post Reply
AndreaVB Forum : VB General : How can I specify a control ?
Poster Message
iliekater
Level: Master

Registered: 04-02-2005
Posts: 123

icon How can I specify a control ?

Beware ! This is a tough one !
We know that in order not to write the whole name of a specific form , one can simply use :
Me.
My question is , can someone use something similar like that for a control ? For instance :
MeCtrl.Name = "Blabla"
MeCtrl.BackColour = 8544444
etc ?
Some may say that I can just use the
With ......
statement if I am so bored or even use the contol's name like this :
Text100.Text = "yahoooooo"
Text100.Caption = "Don't press me"
etc .
But the problem is that I have plenty of such controls in the form  and I hate writting the same code behind each of them (that is at the event of clicking them) .
I wish there was a property something like "LastClickedControl" so that I could search every control on the form (For each ... In ...) and pick the last cklicked control ,, but unfortunatelly there isn't ...

27-11-2006 at 03:49 PM
View Profile Send Email to User Show All Posts | Quote Reply
iliekater
Level: Master

Registered: 04-02-2005
Posts: 123
icon Re: How can I specify a control ?

I think I should specify a few more things , becouse the above may confuse someone . If it was just as simple as above , I could simply  use :
For Each ctrl In MyForm.Controls
      If ctrl = Image _'or what ever control am I looking for
      And ctrl.Name = "BlaBlaBla" 'the specific controls of that type
      Then
     ... code here ...

However , I want to extract something that is pecific to each control , and that is its name , which means I am not able to write a generic code . And in order to be honnest with you , here's what I am trying to do :
I have a form with lots Image controls on it . I want whenever I press (practically click) one of those Images , its name (the control's name) to be written in a text box . Has anyone any idea how I could do that ? I could use an array of controls and simply extract the control's Tag property , but since I am using VBA , I don't think something like that is possible ...

27-11-2006 at 04:06 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: How can I specify a control ?

Hello, iliekater. I just drop a couple of points of meditation.

I seem to remember that in spite of plain VB, controls' arrays are not avaliable in VBA. So you should have the only way out by writing code for each picturebox' Click event.
You can also get advantage from the Me.ActiveControl property, if it's still avaliable in VBA.
And finally, keep in mind the popular TypeOf checking loop, like
    Dim ctl As Control
    For Each ctl In Me.Controls
        If TypeOf ctl Is PictureBox Then
            ' [... code to execute on pictureboxes...]
This way, you can isolate the picboxes and then check for the name of the picbox you need to operate on.

Just hints. Hope it helps.

____________________________
Real Programmer can count up to 1024 on his fingers

28-11-2006 at 05:29 PM
View Profile Send Email to User Show All Posts | Quote Reply
iliekater
Level: Master

Registered: 04-02-2005
Posts: 123
icon Re: How can I specify a control ?

a) The contols' arrays indeed do not exist in VBA ...
b) The Me.ActiveControl property does exist in VBA , but cannot be applied on Image controls ...
c) I already used the devine loop code (OK , instead of Me. , I used the exact form's name becouse I intend to call the sub from a module) ...

Could you drop a few more points of meditation?
That's a joke ofcourse !

28-11-2006 at 09:25 PM
View Profile Send Email to User Show All Posts | Quote Reply
yronium
Level: Moderator


Registered: 14-04-2002
Posts: 907
icon Re: How can I specify a control ?

No more points, sorry.

quote:
iliekater wrote:...I want whenever I press (practically click) one of those Images , its name (the control's name) to be written in a text box...

You got to detect what control user has clicked on, but I'm afraid the only way is to put down code for each imagecontrol Click event (....it should be the fee to pay for using VBA instead of VB).

Hope it helps.

____________________________
Real Programmer can count up to 1024 on his fingers
29-11-2006 at 04:03 PM
View Profile Send Email to User Show All Posts | Quote Reply
iliekater
Level: Master

Registered: 04-02-2005
Posts: 123
icon Re: How can I specify a control ?

Well , I can't use anything else on AutoCAD , you see . Well , I can use DCL , but it hurts too much or Object DCL , but noone asures me that at the next AutoCAD's version it will still be supported ...

01-12-2006 at 09:51 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB General : How can I specify a control ?
Previous Topic (HELP! Triangle in Circle Construction without Trig?)Next Topic (\"can\'t find project or library\" error) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder