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.
Printable View
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.
look at the function CallByName.
CallByName Form1, "MySub", VbMethod, "Yeah! :>"
:D
thanks man!
anyway if ive the form objects name in a string, how can i get the form Object to use with callbyname?
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.
cool idea, thanks :)Quote:
Originally posted by SLH
Or you could loop through all the forms, and look for the one with the correct name.
jim.
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