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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is the item index available at run time? 1

Status
Not open for further replies.

SBendBuckeye

Programmer
May 22, 2002
2,166
US
I want to create a parallel array to the form controls collection for some additional information. At form initialization time, this is no problem as I just increment a counter as I do a for each ctl in me.controls, etc.

But what about when I get the activecontrol? Is the index tucked away somewhere so I can use it as a direct index into my array or do I need to search on the contrl name?

Thanks in advance for any help you can give me! Please remember to give helpful posts the stars they deserve! This makes the post more visible to others in need![thumbsup]
 
Hallo,

As far as I'm aware, the index of a control or form is not stored in the object itself. This is probably because the index can change so should not be relied upon. You have to use the name.

Code:
'Return the index of the specified control in the forms controls collection. If it can't return the controls index for any reason it returns -1
public function intGetControlIndex(byval pfrmForm as Form, byval pstrControlName as string) as integer
on error goto lblExit
dim intI as integer
  with pfrmForm
    for intI = 0 to .Controls.Count-1
      if .Controls(intI).Name = pstrControlName then
        intGetControlIndex = intI
        exit function
      endif
    next i
  end with
lblExit:
  intGetControlIndex = -1
end function
[\code]

Hope that helps,

- Frink
 
Thanks, I was hoping to be able to avoid that. I notice that you prefix an additional p for parm in your function. I do the same except I use p for a generic parm, r if explicitly ByRef and v if explicitly ByVal.

I haven't actually implemented anything like this yet, but I am thinking about including a level indicator also so I can tell at a glance how far down a calling chain I am (eg p1intVarName at 1st, p2intVarName at 2nd, etc.

Have a great day! Please remember to give helpful posts the stars they deserve! This makes the post more visible to others in need![thumbsup]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top