Results 1 to 9 of 9

Thread: noob question ARRAY????

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    noob question ARRAY????

    how can i deterrmine if a control is an array
    VB Code:
    1. dim ctrl as control
    2. for each ctrl in controls
    3.  
    4. if typeof ctrl is textbox
    5.  
    6. if isarray(ctrl)=true then           'function isarray doesn't work
    7. 'code
    8. end if
    9. end if
    10.  
    11. 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.

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: noob question ARRAY????

    Could you check to see if the index is not null?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    Re: noob question ARRAY????

    i tried it but an error saying "object doesn't support this property..." something like that

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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:
    1. Public Function IsControlArrayMember(ctl As Object) As Boolean
    2.     IsControlArrayMember = TypeName(Me.Controls(ctl.Name)) = "Object"
    3. 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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    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:
    1. 'class module
    2. public withevent textbox as textbox
    3. ---
    4. ---etc(all controls)
    5. private sub textbox_keypress(keyascii as integer)
    6. 'code here
    7. end sub
    8. ----------------------------------------
    9. ' form module
    10. dim controlevent() as class1
    11. private sub form_onload()
    12. dim n as integer
    13. n=0
    14. redim controlevent(0 to me.count)  
    15. for each ctrl in controls
    16. if typeof ctrl is textbox
    17. set controlevent(n)= new class1
    18. set controlevent.textbox= ctrl
    19. end if
    20.  
    21. if typeof ctrl is combobox
    22. set controlevent(n)= new class1
    23. set controlevent.combobox=ctrl
    24. end if
    25. n=n+1
    26.  
    27. next ctrl
    28. ' 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
    29.  
    30. 'private sub textbox_change(index as integer)
    31. 'code here
    32. 'end sub
    33.  
    34.  
    35. end sub

  6. #6
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    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.

  8. #8
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Location
    Philippines
    Posts
    468

    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
  •  



Click Here to Expand Forum to Full Width