|
-
Apr 30th, 2002, 11:31 AM
#1
Thread Starter
New Member
For VBScript Jocks
I'm a VB programmer that needs to call various VB commands dynamically from a database (to avoid hardcoding into a huge Select statement), and the only way I could find to do this is with the ScriptControl, to which you can pass a string and it will execute the line. One of the commands I need to execute is the 'keybd_event' API call that I have declared normally in my local project in a bas file. Here's the declare, no problem so far.
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Running keybd_event directly in my code works fine, with the following syntax where ParamVal is the KeyCode to be sent to the program.
keybd_event CByte(ParamVal), 15, 0, 0
I want to store it as a string in a database and then call it with the ScriptControl when necessary. According to MS documentation at msdn.microsoft.com, there's two ways to do this: the Run method and the ExecuteStatement method.
Both require declaration of a reference to the ScriptControl in the project after adding it as a component. Let's use:
Dim x as new ScriptControl
The differenct between the Run and ExecuteMethodStatements is the location of the procedure to be executed. To use Run the code has to be added to the ScriptControl's memory with the AddCode method. ExecuteStatement, on the other hand, executes a procedure that is local to the application in which the ScriptControl is declared so you don't have to use AddCode. Neither method seems to work, though.
The problem with Run is that I can't get the AddCode method to declare the API. It stumbles on the "user32" portion and no syntax I've tried will get past the error. I've tried ""user32"" and chr(34) & chr(34) on both sides of "user32". So I can't seem to set up an API declaration within the ScriptControl.
ExecuteStatement should work according to the documentation but it cannot seem to recognize 'keybd_event' within the following simle Sub that sends a KeyDown event:
Sub KbEventDown(ParamVal As Variant)
keybd_event CByte(ParamVal), 15, 0, 0
End Sub
The syntax I used that fails to make the call is:
X.ExecuteStatement "KbEventDown(" & ParamVal & ")"
At runtime, sending a 't' to the program evaluates to:
"KbEventDown(84)"
and results in the following error:
Microsoft VBScript runtime error: Type mismatch: 'KbEventDown'
Anybody know what's wrong here? Is it no possible to run an API call through VBScript?
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
|