P.I. Engineering User Forum

Product Support, Technical Questions and Answers, and Examples for P.I. Engineering Products

You are not logged in.

#1 2016-03-16 11:31:33

Niezingerly
Member
Registered: 2016-03-16
Posts: 9

VB.NET question...

Good Morning.

I have used X-Keys for a lot of years, but I have only ever used it to "record" key-strokes.

I have never used it to execute VB.NET functions.

I read in the Advanced Programming that full VB.NET usage is possible.

I am no VB.NET programmer, so my question might sound foolish.  Sorry.


So, I'd like to have the X-Key button (that I push) to "wait" until a specified task is completed.

I have a button set to open a new session of a CAM software (Mastercam).

As it is right now, I have a timed delay, waiting for the software to fully open, and then I am calling a simple VBScript, to pop a note up on the screen, to tell the operator what to do next.

Well, depending on how slow or fast my computer is running, the delay is sometimes not enough, and before Mastercam is fully opened, the timed delay has run out, and it pops up the Screen note "too soon". 

So, I'd like to know if there is a way to make the execution of the X-Key functions have to "wait" until the software has fully opened.


In the past, I have used the "On Pressed" and "On Released" capability in the X-Key, but it does really not fit what I am trying to do...


Thank you very much.

Offline

#2 2016-03-16 14:15:03

PIE Amber
Technical Software Developer
From: Williamston, MI
Registered: 2016-01-21
Posts: 196
Website

Re: VB.NET question...

This is actually a fairly complex question, as the best way to do this would require the software you are using to somehow communicate with MacroWorks 3.1 back, rather than just accepting input. That's not something easily done, though sometimes it's possible if they have an API of their own. I wouldn't recommend going down that path, for those with limited VB experience.

However, there may be a way to "cheat" since all you need to know is if the application is open. It's still complex, but likely much more doable. You'd need to execute a loop that checks if your window is in focus repeatedly,  until it gets that it IS in focus, and then execute the rest of your command. For example (not real code, please check outside VB references as well as our Advanced Help for the real syntax):

Case 1001
    If Pressed
        [Shortcut to open program]
        'Call your own subroutine which checks if the app is open
        MySubroutine()


Then, somewhere else in the file you need to create your own subroutine that continually checks if your application is the active app:

Public Sub MySubroutine()
      'Your code here
End Sub

And within there you could try to check our "ActiveApp" variable in a loop and perform the rest of your programming if your app is in focus.

Note 1: ActiveApp is updated every time the program focus in Windows changes. To get the right text to use for your application, try programming an application-specific layer for the app (just to mine the code). What we are doing there is checking this variable on button press. You want to check it, too, but in your loop.

Note 2: Sometimes Windows opens apps behind other apps. For that reason you may also want to use the "WindowToFront" command from the Advanced Help file in your loop.

Note 3: Since you are new to VB, I recommend consulting syntax resources regularly as you are building your code (and be sure to save backups, just in case). This is one of my favorite resources for seeing code in context: Dot Net Perls


Amber from P.I. Engineering

Offline

#3 2016-03-16 15:04:56

Niezingerly
Member
Registered: 2016-03-16
Posts: 9

Re: VB.NET question...

Amber, thank you very much.

I figured it was not going to be as easy as I hoped, but this does guide me along.

As a side note, Mastercam does have an API.  A long standing goal of mine is to get my X-Key much more integrated with Mastercam.

Thank you for your help.

Also, thank you for the resource.

I have been looking for something, and hopefully I can grasp what is on that site.

Thanks again...

Offline

Board footer

Powered by FluxBB