|
-
Jul 6th, 2000, 09:06 PM
#1
Thread Starter
Lively Member
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
-
Jul 6th, 2000, 09:11 PM
#2
Frenzied Member
Is it possible to do something like this?
Private Sub NewcmdButton1_Click()
End Sub
Maybe you can asign a name to the command button
-
Jul 6th, 2000, 09:33 PM
#3
Thread Starter
Lively Member
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
-
Jul 6th, 2000, 10:18 PM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|