Results 1 to 4 of 4

Thread: set event to new control

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92

    Cool

    Ahoolla, VB fanatics!

    This's what's bugging me...

    I´v just added a new command button with vb.controls.add ...

    the prob is... how do i "set" new instructions to; for example the command button's click event? So that when the user clicks the new command button it actually does something...


    thanks guys... n remember i'm iScanning u

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Is it possible to do something like this?

    Private Sub NewcmdButton1_Click()

    End Sub


    Maybe you can asign a name to the command button

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Posts
    92
    Thing is if the commandbutton was added at runtime
    (Vb.controls.add), how can i and where will i put intructions on the different events that the button as?

    something like: (this code is inside a module)

    Public Sub CrtCommandButton(Name As String, Where As Form, X As Integer, Y As Integer, Str As String)
    Dim D As Control
    Set D = where.Controls.Add("Vb.commandbutton", Name)
    With D
    .Left = X
    .Top = Y
    .Caption = Str
    .Visible = True
    End With


    ''''''
    'should i put here some instructions for the click event for the button being created?....
    name_click() = MsgBox "Hello"
    ''''''


    End Sub

  4. #4
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    You need to reshuffle your code a bit, you need a Variable in the Form it's going to appear in.

    declare it like this
    Code:
    Dim WithEvents MyCommand As CommandButton
    then go to the combobox at the top right of your code with the controls in and D will apear, then you can select the events as normal.

    change the Sub to a Function and have it return a Command button, ie
    Code:
    Public Function Sub CrtCommandButton(Name As String, Where As Form, X As Integer, Y As Integer, Str As String) As CommandButton
    then call it with
    Code:
    Set MyCommand = CrtCommandButton() 'Put your parameters in here.
    you can use arrays etc to store the controlls in, but you need to have the events written somewhere at compile time, you can't write any new code ar runtime.

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