Question on calls Sorry to keep asking questions

Question on calls Sorry to keep asking questions

Post by annnonymou » Wed, 24 Nov 2004 16:19:14


Apologize for bing a pain and I googled this to death but I cannot get
this to work on an indexed control (WORKS on Non Index control)

Public Sub Command1_Click(Index As Integer)
MsgBox "Command1 clicked"
End Sub


Does not Work

Private Sub Command2_Click()
CallByName Form1, "Command1_Click(0)", VbMethod
End Sub

Does not Work

Private Sub Command3_Click()
Dim sc
Dim sCommand As String
Set sc = CreateObject("ScriptControl")
sc.Language = "vbscript"
sc.AddObject "Form1", Form1
sCommand = "Form1.Command1_Click(0)"
sc.ExecuteStatement sCommand
Exit sub


On Fri, 19 Nov 2004 21:51:00 -0600, "David Young *** " < XXXX@XXXXX.COM >
 
 
 

Question on calls Sorry to keep asking questions

Post by Rick Roths » Wed, 24 Nov 2004 17:18:53

> Does not Work

As soon as you put quote marks around something, you turn it into a pure
String, even if that something was the name of a variable, function or
subroutine.

Rick - MVP

 
 
 

Question on calls Sorry to keep asking questions

Post by annnonymou » Wed, 24 Nov 2004 17:21:06

Is there a way around thiis so I can use the callbyname function on an
indexed string?

On Tue, 23 Nov 2004 03:18:53 -0500, "Rick Rothstein"
 
 
 

Question on calls Sorry to keep asking questions

Post by Rick Roths » Wed, 24 Nov 2004 17:47:44

> >> Does not Work
pure
or

Alright, let me "correct" what I just said... in the case of CallByName,
yes, that second argument is supposed to be given as a String value
(that's what the syntax calls for). I answered your original post
without thinking carefully enough about what you were trying to do. Now,
as to why your code didn't work... Click is not method of the
CommandButton, it is an event of the CommandButton. CallByName
apparently doesn't not accept events as an argument.

Can you describe what part of the CommandButton call you are trying to
make is not known beforehand... the control array being specified, the
index for a control array, or both? I will point out, if it helps, that
if you know which control array you want, but want to specify the index
dynamically, then this will work...

Command1(SomeIndex).Value = True

where SomeIndex can be specified dynamically. Setting the Value of a
CommandButton to True triggers its Click event.

Rick - MVP
 
 
 

Question on calls Sorry to keep asking questions

Post by annnonymou » Wed, 24 Nov 2004 18:49:02

On Tue, 23 Nov 2004 03:47:44 -0500, "Rick Rothstein"



BOTH
 
 
 

Question on calls Sorry to keep asking questions

Post by David Youn » Wed, 24 Nov 2004 20:39:11

< XXXX@XXXXX.COM > wrote

You use CallByName's forth argument to pass parameters.
CallByName(object, procedurename, calltype,[arguments()])
CallByName Form1, "Command1_Click", VbMethod, 0

The script control method *does* work. I copied your code to vb and after
correcting the last line (you have Exit Sub, should be End Sub) it works as
expected. What problem are you having with it?

David


Public
call
 
 
 

Question on calls Sorry to keep asking questions

Post by annnonymou » Wed, 24 Nov 2004 21:12:49

hmmm... I did try that but before posting but i did not get it to
work. Try again same results. This is what I did

created form1 with two commands button 1 and 2 . button 1 is indexed
to 1 button 2 is unindexed


paste this code

Private Sub Command1_Click(Index As Integer) ' is indexed to 1

MsgBox "Command1 Clicked"

End Sub

Private Sub Command2_Click() ' button unindexed

On Error GoTo CallByNameError
CallByName Form1, "Command1_Click", VbMethod, 1

Exit Sub

CallByNameError:
MsgBox "Error " & Err.Number & " setting property." & _
vbCrLf & Err.Description
Debug.Print "Error " & Err.Number & " setting property." & _
vbCrLf & Err.Description
End
Resume Next ':(ead Code

End Sub



click button 1 you get

Command1 Clicked

click button 2 you get the error

Error 438 setting property.
Object doesn't support this property or method

TIA



On Tue, 23 Nov 2004 05:39:11 -0600, "David Young *** " < XXXX@XXXXX.COM >
 
 
 

Question on calls Sorry to keep asking questions

Post by RGF2aWQgWW » Wed, 24 Nov 2004 22:13:01

XXXX@XXXXX.COM " wrote:

I'll repeat this from my first reply.
"...the procedure to be called must be declared as Public."

Public Sub Command1_Click(Index As Integer)
MsgBox "Command1 clicked"
End Sub

David

 
 
 

Question on calls Sorry to keep asking questions

Post by Rick Roths » Wed, 24 Nov 2004 22:37:22

> >> >> Does not Work
a
function
an
CallByName,
Now,
to
the
index

Okay, I just did a little reading up on CallByName (I have not
personally had the occasion to use it before)... it does work, but you
laid it out wrong. Try it this way...

CallByName Form1, "Command1_Click", VbMethod, 0

where the Index of the control array is passed as the last argument (not
within parentheses on the Sub's name as you showed initially). By the
way, the Command1_Click event must be made Public (you showed that in
your first posting); if it is not, you get an error.

Rick - MVP
 
 
 

Question on calls Sorry to keep asking questions

Post by Bob Butle » Wed, 24 Nov 2004 23:17:40


Drop the CallByName and just force a click directly:

Form1.Controls("Command1")(0).Value = True


--
Reply to the group so all can participate
VB.Net... just say "No"