|
-
Jun 24th, 2002, 05:46 AM
#1
Thread Starter
Frenzied Member
Fire a sub by its name (in string)
Hi,
as you can see, ive an another nice question, so ive a sub, and ive the subs name in a string ->
String = "Form1.MySub"
and i'm want to fire THAT sub, so only on Form1.. but how can i do it?
have you any idea?
Thx,Jim.
-
Jun 24th, 2002, 05:52 AM
#2
Not NoteMe
look at the function CallByName.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 24th, 2002, 05:59 AM
#3
Thread Starter
Frenzied Member
CallByName Form1, "MySub", VbMethod, "Yeah! :>"

thanks man!
anyway if ive the form objects name in a string, how can i get the form Object to use with callbyname?
-
Jun 24th, 2002, 06:22 AM
#4
Not NoteMe
I think you'd have to use a select case or something like that.
Or you could loop through all the forms, and look for the one with the correct name.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
-
Jun 24th, 2002, 07:09 AM
#5
Thread Starter
Frenzied Member
Originally posted by SLH
Or you could loop through all the forms, and look for the one with the correct name.
cool idea, thanks 
jim.
-
Jun 24th, 2002, 07:16 AM
#6
Something i found a while back. have fun
VB Code:
'****** In a form
Option Compare Text
Option Explicit
'VB6 IDE
Private Declare Function EbExecuteLine Lib "vba6.dll" (ByVal pStringToExec As Long, ByVal Foo1 As Long, ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
' For VB5 IDE
'Declare Function EbExecuteLine Lib "vba5.dll" (ByVal pStringToExec As Long, ByVal Foo1 As Long, ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
' FOR Access 97/VBE.dll clients like Word 97 and Excel 97
'Declare Function EbExecuteLine Lib "vba332.dll" (ByVal pStringToExec As Long, ByVal Foo1 As Long, ByVal Foo2 As Long, ByVal fCheckOnly As Long) As Long
Private Sub Combo1_Change()
End Sub
Private Sub Combo1_Click()
Text1.Text = Combo1.Text
End Sub
Private Sub Command1_Click()
If ExecuteLine(Text1.Text) = True Then
Label1.Caption = "Text successfully run"
Else
Label1.Caption = "Failed to run the code"
End If
End Sub
Private Function ExecuteLine(ByVal strCode As String, Optional ByVal blnCheckOnly As Boolean = False) As Boolean
ExecuteLine = EbExecuteLine(StrPtr(strCode), 0&, 0&, Abs(blnCheckOnly))
End Function
Private Sub Form_Load()
With Combo1
.AddItem "HiddenProc1"
.AddItem "?HiddenProc2"
.AddItem "x = MsgBox (" & Chr(34) & "Hello World!" & Chr(34) & ", vbExclamation + vbOkCancel, " & Chr(34) & "Test MsgBox" & Chr(34) & "): MsgBox x"
.ListIndex = 0
End With
Command1.Caption = "Execute"
Label1.Caption = "Nothing run yet..."
End Sub
'****** In a module
Option Explicit
Public Sub HiddenProc1()
Dim intCounter As Integer
For intCounter = 0 To 10
Debug.Print intCounter
Next
End Sub
Public Function HiddenProc2() As String
HiddenProc2 = "This is what HiddenProc2 returns"
End Function
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
|