troubleshooting Question

visual basic 6 macro, the clipboard & third-party software add-on

Avatar of jruhe
jruheFlag for United States of America asked on
ProgrammingVisual Basic Classic
8 Comments1 Solution624 ViewsLast Modified:
Hi all,

I'm having an issue with a macro I wrote to get an ID from a third-party product.  I need the ID from the third-party screen (form) to figure out which record I'm on, because there is no data layer in the SDK.  Basically, I created a DLL that adds an option to the product's menu.  When the user clicks the new option on the menu, the program moves the cursor (using Alt-G) to the first field on the form, then "presses" Ctrl-C.  This works great if it is isolated--I can use ctrl-v to paste the contents of the ID field after it runs.  However, as soon as I add anything else to it, like MsgBox Clipboard.GetText, for example, it doesn't work.  Since my whole reason to do the "macro" exercise is to capture the info in the clipboard, I really need to fix this.  Code follows, but please read my last comment, below.

The code is here in a sub of a Functions.bas module:
    Clipboard.Clear
    ' Alt-G:
    Call keybd_event(vbKeyMenu, 0, 0, 0)
    Call keybd_event(vbKeyG, 0, 0, 0)
    Call keybd_event(vbKeyG, 0, KEYEVENTF_KEYUP, 0)
    Call keybd_event(vbKeyMenu, 0, KEYEVENTF_KEYUP, 0)
    Call keybd_event(vbKeyControl, 0, 0, 0)
    ' Ctrl-C:
    Call keybd_event(vbKeyC, 0, 0, 0)
    Call keybd_event(vbKeyC, 0, KEYEVENTF_KEYUP, 0)
    Call keybd_event(vbKeyControl, 0, KEYEVENTF_KEYUP, 0)

And in the Globals:
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

And in the declarations of the Functions module:
Declare Function apiFindWindow Lib "user32" Alias "FindWindowA" _
   (ByVal lpclassname As Any, ByVal lpCaption As Any) As Long

Final Comment:
I noticed that when it works (if it runs by itself without any code after it), my cursor is where it should be -- in the ID field -- and the whole field is selected.  When I run it with my "msgbox" command (or any command) after it, the focus is not on the ID field.    I'm not sure if this matters but I figured I'd include it in case it helps.

Thanks,
jr
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros