Author Topic: Stupid question about control.name  (Read 4591 times)

0 Members and 1 Guest are viewing this topic.

Ricky_76

  • Guest
Stupid question about control.name
« on: June 29, 2006, 07:09:17 PM »
Hi, and tnx 4 your time!
I have a small problem!
I need to refer to some controls dynamically, lets check to the example!

I have 3 disabled combobox (cb_1, cb_2, cb_3) that I need to reenable!

dim i as integer
for i = 1 to 3
     ["cb_" & i].enabled = true
next

I know that in Flash you can refer to a control simply using "[STRING]." it's possible to do in some wai also in VB and VBA???

Actually I use:

dim s as string
dim ctr as control
for i = 1 to 3
    s="cb:_" & i
    for each ctr in me.controls
        if ctr.name=s then
            ctr.enabled = true
        goto cont
        end if
    next
cont:
next


LET ME KNOW!!!! :)
« Last Edit: June 29, 2006, 07:37:17 PM by Ricky_76 »

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Stupid question about control.name
« Reply #1 on: June 29, 2006, 07:30:07 PM »
Sounds good, do you have a problem?

Ricky_76

  • Guest
Re: Stupid question about control.name
« Reply #2 on: June 29, 2006, 07:35:40 PM »
Sounds good, do you have a problem?


Hi Bryco,
it works very well, but I need to use 12 code lines instead of 4!
and in many other cases (the example i reported is only a simple problem) i need this "Function" massively!

Jeff_M

  • King Gator
  • Posts: 4095
  • C3D user & customizer
Re: Stupid question about control.name
« Reply #3 on: June 29, 2006, 08:07:53 PM »
well, here's a shorter version.....
Code: [Select]
Dim i As Integer
Dim ctl As ComboBox
For i = 1 To 3
    Set ctl = Me.Controls.Item("cb_" & i)
    ctl.Enabled = True
Next

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Stupid question about control.name
« Reply #4 on: June 29, 2006, 10:48:38 PM »
not good enough Jeff ... that's 6 lines  :lol:     :lmao:
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Bryco

  • Water Moccasin
  • Posts: 1883
Re: Stupid question about control.name
« Reply #5 on: June 29, 2006, 11:03:19 PM »
4

Function ControlOn(sName As String) As Boolean
    Me.Controls.Item(sName).Enabled = True
    ControlOn = True
End Function

Ricky_76

  • Guest
Re: Stupid question about control.name
« Reply #6 on: June 30, 2006, 03:25:29 AM »
well, here's a shorter version.....
Code: [Select]
Dim i As Integer
Dim ctl As ComboBox
For i = 1 To 3
    Set ctl = Me.Controls.Item("cb_" & i)
    ctl.Enabled = True
Next

tnx Jeff, I have tested your solution but it doesn't work properly, maybe it works in .net, not in VBA!
I'll test it again later. :)
« Last Edit: June 30, 2006, 03:30:45 AM by Ricky_76 »

Ricky_76

  • Guest
Re: Stupid question about control.name
« Reply #7 on: June 30, 2006, 03:26:59 AM »
4

Function ControlOn(sName As String) As Boolean
    Me.Controls.Item(sName).Enabled = True
    ControlOn = True
End Function

HI Bryco,
GREAT, it works fine! TNX a lot!
« Last Edit: June 30, 2006, 03:31:16 AM by Ricky_76 »

Ricky_76

  • Guest
Re: Stupid question about control.name
« Reply #8 on: June 30, 2006, 03:29:56 AM »
not good enough Jeff ... that's 6 lines  :lol:     :lmao:

 :-D  :-D  :-D

Bob Wahr

  • Guest
Re: Stupid question about control.name
« Reply #9 on: June 30, 2006, 10:38:06 AM »
4

[buzzer]

WRONG!

It being a function, you need a line to call it so it's 5 not 4

Jeff_M

  • King Gator
  • Posts: 4095
  • C3D user & customizer
Re: Stupid question about control.name
« Reply #10 on: June 30, 2006, 12:08:27 PM »
tnx Jeff, I have tested your solution but it doesn't work properly, maybe it works in .net, not in VBA!
I'll test it again later. :)
FYI, I only tested that in VBA.....it worked fine for me. But I like Bryco's Function better. :-)

Ricky_76

  • Guest
Re: Stupid question about control.name
« Reply #11 on: June 30, 2006, 12:19:54 PM »
tnx Jeff, I have tested your solution but it doesn't work properly, maybe it works in .net, not in VBA!
I'll test it again later. :)
FYI, I only tested that in VBA.....it worked fine for me. But I like Bryco's Function better. :-)

Hi, you're right!
It works!  8-)
thx!