|
В данном примере вам понадобятся следующие
элементы: ComboBox, TextBox, Label, CommandButton. В ComboBox
программа добавляет так называемые шаблоны,
Label отображает текущее состояние
выполнения кода, в TextBox'е содержится
непосредственно текст, являющийся кодом
программы, ну а CommandButton... и так понятно.
Как ни жаль, но всех возможностей функции EbExecuteLine
я не знаю. Как говорится, вам и карты в руки.
Чуть не забыл. Вам понадобится дополнительный
модуль в вашей программе. 'КОД МОДУЛЯ
Public Function secret() As String
secret = "this is a secret subroutine"
End Function
Public Sub secret2()
MsgBox "this is a secret subroutine 2"
End Sub
'КОД ФОРМЫ
Option Compare Text
Option Explicit
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
Function FExecuteCode(stCode As String, Optional fCheckOnly As Boolean) As Boolean
FExecuteCode = EbExecuteLine(StrPtr(stCode), 0&, 0&, Abs(fCheckOnly)) = 0
End Function
Private Sub Combo1_Click()
Text1.Text = Combo1.List(Combo1.ListIndex)
End Sub
Private Sub Command1_Click()
Dim res As Boolean
res = FExecuteCode(Text1.Text)
Label1.Caption = "Status = " & res
End Sub
Private Sub Form_Load()
Combo1.AddItem "?secret"
Combo1.AddItem "msgbox secret"
Combo1.AddItem "secret2"
Combo1.AddItem "For x=0 to 5:?" & Chr$(34) & "hello " &
Chr$(34) & "&x:next:beep"
Combo1.AddItem "sendkeys " & Chr$(34) & "{TAB}" & Chr$(34)
& ":sendkeys " & Chr$(34) & "{up}" & Chr$(34)
Combo1.AddItem "shell " & Chr$(34) & "calc.exe" & Chr$(34)
& ",vbNormalFocus"
Combo1.AddItem "shell " & Chr$(34) & "c:\windows\explorer.exe
::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" & Chr$(34) &
",vbNormalFocus"
Combo1.AddItem "form1.text1.visible=false"
Combo1.AddItem "form1.text1.visible=true"
Combo1.AddItem "form1.combo1.listindex=1"
Combo1.AddItem "msgbox app.Title"
Combo1.AddItem "form1.combo1.listindex=1:form1.command1.value=true"
Combo1.ListIndex = 0
Show
End Sub
|
|