|
-
May 22nd, 2006, 09:01 AM
#1
Thread Starter
Hyperactive Member
noob question ARRAY????
how can i deterrmine if a control is an array
VB Code:
dim ctrl as control
for each ctrl in controls
if typeof ctrl is textbox
if isarray(ctrl)=true then 'function isarray doesn't work
'code
end if
end if
next ctrls
2nd question
how can i create a witheevents on array of textboxes?
Last edited by mikee_phil; May 22nd, 2006 at 09:06 AM.
-
May 22nd, 2006, 09:04 AM
#2
PowerPoster
Re: noob question ARRAY????
Could you check to see if the index is not null?
-
May 22nd, 2006, 09:05 AM
#3
Thread Starter
Hyperactive Member
Re: noob question ARRAY????
i tried it but an error saying "object doesn't support this property..." something like that
-
May 22nd, 2006, 09:19 AM
#4
Re: noob question ARRAY????
A For Each control in Controls loop will only return individual controls, not control arrays. i.e. in the course of the loop you will have txtBox(1), txtBox(2), txtBox(3) - the controls, rather than just txtBox - the array.
You can check if a control is a member of a control array, through error trapping when calling .Index property, or by using a modified version of Randy Birch's code for detecting if an object is a control array:
VB Code:
Public Function IsControlArrayMember(ctl As Object) As Boolean
IsControlArrayMember = TypeName(Me.Controls(ctl.Name)) = "Object"
End Function
how can i create a witheevents on array of textboxes?
you can't do it with a WithEvents object - you have to have a control on your form with Index = 0 and then use Load to create new controls: http://www.vbforums.com/showpost.php...22&postcount=3
-
May 22nd, 2006, 09:45 AM
#5
Thread Starter
Hyperactive Member
Re: noob question ARRAY????
A For Each control in Controls loop will only return individual controls, not control arrays. i.e. in the course of the loop you will have txtBox(1), txtBox(2), txtBox(3) - the controls, rather than just txtBox - the array.
thats what i want to do to loop into individual controls, i am loading events on the textbox ...
and in the 2nd question i created a withevent on textboxand other control and setting the events to all control on the form, the problem is how can i do it on array on controls
VB Code:
'class module
public withevent textbox as textbox
---
---etc(all controls)
private sub textbox_keypress(keyascii as integer)
'code here
end sub
----------------------------------------
' form module
dim controlevent() as class1
private sub form_onload()
dim n as integer
n=0
redim controlevent(0 to me.count)
for each ctrl in controls
if typeof ctrl is textbox
set controlevent(n)= new class1
set controlevent.textbox= ctrl
end if
if typeof ctrl is combobox
set controlevent(n)= new class1
set controlevent.combobox=ctrl
end if
n=n+1
next ctrl
' the problem is if it is an array how can i set class1 individually and also does 'withevent support array like events on control on a form module
'private sub textbox_change(index as integer)
'code here
'end sub
end sub
-
May 22nd, 2006, 09:57 AM
#6
Re: noob question ARRAY????
so your using the class to house all the controls events? why not just handle them all in the form?
As i said, you can't have an object array declared WithEvents, so if you are going to do that, maybe you'll have to create a new instance of the class for every control
-
May 22nd, 2006, 10:35 AM
#7
Thread Starter
Hyperactive Member
Re: noob question ARRAY????
so your using the class to house all the controls events? why not just handle them all in the form?
i have a mdi form with many child, i tried to create a class so it save me up from coding all the control events, i want it to be reusable so everytime a make a application i can use it, i have also made class that handle properties of a control, im just having problem when the control is an array.
-
May 22nd, 2006, 10:40 AM
#8
Re: noob question ARRAY????
all your forms must be very similar then if you are attempting to use one class to handle all the events.
you should perhaps look into creating multiple instances of just one form - and modifying each form as required.
-
May 22nd, 2006, 11:19 AM
#9
Thread Starter
Hyperactive Member
Re: noob question ARRAY????
no i just use 1 example, control arrays have similar events you can put the code with out using the class i created...
using the fucntion you posted i think i can use it....
anyway thanks for the help....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|