Help Needed

Create and event in RunTime for a control

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 5877 Views - Last Post: 06 March 2010 - 06:07 AM Rate Topic: ***** 1 Votes

#1 Guest_evry1falls*


Reputation:

Help Needed

Posted 02 March 2010 - 10:38 AM

Hello ....
Im having difficulties with this code ...
i would so much like to Create an event in the runtime for a control has been created in the runtime as well .... help
Option Explicit 
 
 Dim i As Integer 
Dim cmdButton(200) As CommandButton 
 
Private Sub cmdButton_Click(i As Integer) 
     MsgBox "hi" 
End Sub 
Private Sub Form_Load() 
For i = 0 To 20 
    Set cmdButton(i) = Form1.Controls.Add("VB.CommandButton", "newCommandButton" & Me.Controls.Count) 
      
    With cmdButton(i) 
        .Left = 1000 * i 
        .Top = 1000 
        .Width = 2000 
        .Height = 500 
        .Caption = "Hello" 
        .Visible = True 
     End With 
Next i 
End Sub 
 
Private Sub Form_Unload(Cancel As Integer) 
    Set cmdButton(i) = Nothing 
End Sub


you will find the cmdbutton repeats itself fine... but i want to :

when i click on it , gives me a message ... How ?

Is This A Good Question/Topic? 0

Replies To: Help Needed

#2 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Help Needed

Posted 02 March 2010 - 11:21 AM

view this link

This post has been edited by thava: 02 March 2010 - 11:22 AM

Was This Post Helpful? 0
  • +
  • -

#3 Guest_evry1falls*


Reputation:

Re: Help Needed

Posted 02 March 2010 - 02:32 PM

thanx for the link ...
it was helpful but still did not answer my question !!

Why the event Click of the Indexed commandButton'Made in runtime' doesn't work ! Though .

if we erased the Index as shown in ur link , it works fine !

I mean when i tried to apply the example in the link in my project after makeing changes, it still not giving me the even click result .???

Please any help ?`

This post has been edited by evry1falls: 02 March 2010 - 03:55 PM

Was This Post Helpful? 0

#4 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Help Needed

Posted 02 March 2010 - 08:19 PM

when you try to add a control array just use load and unload methods
Was This Post Helpful? 0
  • +
  • -

#5 Guest_evry1falls*


Reputation:

Re: Help Needed

Posted 03 March 2010 - 09:10 AM

Do You Mean something Like that ======>

Dim instance As BaseControlArray
Dim Index As Short

instance.Unload(Index)


???????

Or what ??
========================================================================|

Quote

Please tell me coz it seems as if im not following here !
Sorry im not that Pro. im trying to get to know the (CreateObject) At RunTime for the first time .

Was This Post Helpful? 0

#6 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help Needed

Posted 03 March 2010 - 11:43 AM

well load actually :)
here is an example :P
Private Sub Command1_Click()
Dim index As Integer

        ' Create the control.'
        index = Picture1.Count
        Load Picture1(index)


        ' Position the control.'
        Picture1(index).Top = Picture1(index - 1).Top + _
                Picture1(index - 1).Height + 30


        ' Display the control.'
        Picture1(index).Visible = True

End Sub



so make a command button add a picture box and set the index property to 0. that way you make an array of object named Picture1 with 1 element. now in command click event put this code. as you can see the variable named "index" is the count of the elements in the array (1 on the first click of the button). using the Load we create the next object by setting his index to 1 as second. now what we do then is position it under the first one and make his property visible to true so it show up.

good luck
Was This Post Helpful? 0
  • +
  • -

#7 Guest_evry1falls*


Reputation:

Re: Help Needed

Posted 03 March 2010 - 11:51 AM

Thanx 'No Brain' ....
Unfortunately, i already know this Info.
My Question was :

How to Make an Event for a Control Array Element(Object) that has been made in The RunTime ...? 'not an object that is already has been placed on the form by hand 'in the designtime' ....

Could You Please Help Me ...........?

You will notice my Code in the very first above page ...

Thank You So Much
Was This Post Helpful? 0

#8 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help Needed

Posted 03 March 2010 - 12:00 PM

sorry
for example start using the right functions for example
Do not use
Private Sub cmdButton_Click(i As Integer)



Use this
Private Sub cmdButton_Click(Index As Integer)



good luck :)
Was This Post Helpful? 0
  • +
  • -

#9 Guest_evry1falls*


Reputation:

Re: Help Needed

Posted 03 March 2010 - 12:10 PM

Again Thanx for Trying ...
But im deadly sorry ........Not working !'I Already tried it b4'
=================================================================

Do i consider it Impossible and move on or find Alternate ?
It would be easier Though .

=================================================================

Any Suggestion ??

I really have faith in you (NoBrain)
Was This Post Helpful? 0

#10 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help Needed

Posted 03 March 2010 - 01:05 PM

well rly it work on me do not know what is happening i try it in this code
Private Sub Command1_Click()
Dim Index As Integer

        ' Create the control.'
        Index = Command2.Count
        Load Command2(Index)


        ' Position the control.'
        Command2(Index).Top = Command2(Index - 1).Top + _
                Command2(Index - 1).Height + 30


        ' Display the control.'
        Command2(Index).Visible = True

End Sub

Private Sub Command2_Click(Index As Integer)
    Select Case Index
        Case 0
            MsgBox "1"
        Case 1
            MsgBox "2"
        Case 2
            MsgBox "3"
    End Select
End Sub


well for 3 button any way :)
Was This Post Helpful? 0
  • +
  • -

#11 Guest_evry1falls*


Reputation:

Re: Help Needed

Posted 03 March 2010 - 03:45 PM

Hi ....
Well this is so fine .... and it is so close to solve the problem ..

But !!!!!!!!!!!

You placed a command1 and command 2 in The IDE.
You made the command1 duplicates command2.
and in the same time you Gave command2 and even (Click).

Now >>>>>>>>

Can't we just reduce the IDE and instead make it in RunTime ??

I Mean ...........

we don't place the command1 in IDE and create it in RunTime. and then goon with the code as illustrated in ur code ?

AT LEAST ...

take my code up there in the first main Thread and work it the way im descriping and tell me Only if it is possible .. don't post it 'just tell me and i will try everything' ok?!

Please
Was This Post Helpful? 0

#12 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help Needed

Posted 03 March 2010 - 04:11 PM

nah i gues you cant ...
Was This Post Helpful? 0
  • +
  • -

#13 Guest_evry1falls*


Reputation:

Re: Help Needed

Posted 04 March 2010 - 07:37 AM

Thanx AnyWay Man ...
You Have been A Big Help .
Was This Post Helpful? 0

#14 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Help Needed

Posted 04 March 2010 - 08:23 AM

well not rly :)
i guess it is because you cant set array of elements that have events:
Private WithEvents cmdObject(20) As CommandButton 



show an error. and if you do it with no event there will be no click event. i think it is a glitch in vb6...

you can always do it the way i show you.
Was This Post Helpful? 0
  • +
  • -

#15 thava  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 180
  • View blog
  • Posts: 1,606
  • Joined: 17-April 07

Re: Help Needed

Posted 04 March 2010 - 04:41 PM

yes
but there is way to handle this click event, do this using a class
more like a wrapper class

This post has been edited by thava: 04 March 2010 - 04:44 PM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2