Hello Guest it is March 28, 2024, 09:45:17 AM

Author Topic: How to attach VB script to button  (Read 20083 times)

0 Members and 1 Guest are viewing this topic.

How to attach VB script to button
« on: September 13, 2007, 02:55:46 PM »
I'm in Screen4, I've created a new button.  However, after reviewing Wiki, I still do not have a clue as to how to attach a VB macro to the button's press event.

Can someone list code that will toggle "Enable 1" on and off when the button is pressed?

Given that I now have "toggle Enable 1" VB code in a macro, how do I attach it to the button's press event?

I need specific instructions as I can't find the answers in Wiki.  Too confused I guess.

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: How to attach VB script to button
« Reply #1 on: September 13, 2007, 03:01:39 PM »
In screen 4 you click on the button. You can choose system function, oem code, g code, or VB script function edited in Mach 3, Choose the VB script function. Once you have mach open with the edited screen, look at the top tabs, operator, edit button script. The button you added should now be blinking with the others that are VB buttons. Click on it and insert your code, close and save. That should do it.

Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: How to attach VB script to button
« Reply #2 on: September 13, 2007, 03:34:25 PM »
Yes.  I follow you completely.  Thanks.  I just didn't understand the procedure.

Regarding the actual button macro, is there a toggle function?

If not, how do you test for "Enable 1" on or off?

I found this at Wiki:

ActivateSignal(Enable1) and DeActivateSignal(Enable1)

However, when the button is pressed, "Enable 1" needs to toggle from one to the other.  Will the following work?

AuxPwr = GetParam("Enable1")
If NOT AuxPwr Then
     ActivateSignal(Enable1)
Else
     DeActivateSignal(Enable1)
End If

I tried this in the diagnostics page, but the Enable 1 LED did not blink.  Do I need to turn the Enable 1 LED on and off or will the fact that the signal is turning on and off affect the LED?

Am I using the correct functions?  The correct syntax?

Help!

« Last Edit: September 13, 2007, 04:07:19 PM by coyotegd »

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: How to attach VB script to button
« Reply #3 on: September 13, 2007, 05:26:34 PM »
Enable 1 LED is OEM code 846. Place and led on your screen and assign it oem code 846

Get OEMLed (846)
 If OemLed(846,1) Then
  DeActivateSignal(Enable1)
Else
   ActivateSignal(Enable1)
EndIf

Tyr this, I'm no VB guru so be careful. I havent had time to try it.

 
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!

Offline Hood

*
  •  25,835 25,835
  • Carnoustie, Scotland
    • View Profile
Re: How to attach VB script to button
« Reply #4 on: September 13, 2007, 06:00:28 PM »
very rusty with VB, in fact I dont think it could even be classed as rust because the little VB I did know would hardly be enough to turn to rust :D
Anyway what you might want to do is use the macro pump to switch your enables. Put a User LED on the screen and a button to toggle it. You tell the macropump to look at the user LED  then you can toggle the LED by putting VB in the button something like
If GetUserLED (***) Then
     SetUserLED ***, 0
Else
     SetUserLED ***, 1
End If


Hope this helps cause I dont have a clue what I have just written :D

Hood

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: How to attach VB script to button
« Reply #5 on: September 13, 2007, 06:10:26 PM »
Nope, my version doesn't work.  :( I will try to play with it later if someone else doesn't get you sorted soon.

Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: How to attach VB script to button
« Reply #6 on: September 13, 2007, 07:56:16 PM »
I think I need to clarify what I am trying to do.  I have created a screen (just the diagnostics screen with an additional button) that includes an "Aux Pwr Toggle" button.  I want to make the Enable 1 output active, which will then trigger a relay that supplies 120VAC to an outlet on the back of my Mill's driver box.

I would like to create a macro for the "Aux Pwr Toggle" button that does two things: (1) it makes Enable 1 output active and toggles it on and off; and (2) when Enable 1 is active Enable 1 LED on the diagnostics screen blinks.  I don't know if blinking is automatic or not.  I hope it is.

I can't get a my button's macro to do this.  Can someone please supply the necessary code.

Thanks you

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: How to attach VB script to button
« Reply #7 on: September 13, 2007, 08:39:13 PM »
OK, Got some help from the Guru himself. This works, just make sure tah enable 1 is enabled in ports and pins. I tested it hear and it works a treat.  :)

test = GetOEMLed (846)
If (test = true) Then
  DeActivateSignal(Enable1)
Else
   ActivateSignal(Enable1)
End If

Brett

;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!
Re: How to attach VB script to button
« Reply #8 on: September 13, 2007, 09:17:05 PM »
Bingo.  Thank you.  I've got it working, but I changed from "Enable 1" output to "Output 6".  When I start Mach3, "Enable 1" begins active, and although I know I could use a start-up macro to turn "Enable 1" off by placing the start-up macro's name in the "Initialization String" textbox on the "General Config..." page, I decided to use the following code, and it works great:

Code: [Select]
Option Explicit
Dim Test As Boolean
Test = GetOEMLED (79)
If (Test = True) Then
DeActivateSignal(Output6)
Else
ActivateSignal(Output6)
End If

I need to work on my understanding of Mach3's functions, OEM codes, and user created stuff.  Once I know those, my VB is pretty good, and I'll pick up on how to implement macros.  I found the following to work exactly like the code above:

Code: [Select]
If GetOEMLED (79) Then
DeActivateSignal(Output6)
Else
ActivateSignal(Output6)
End If

It's interesting to me and seems a bit unorthodox to check the LED rather than the signal itself to see if the signal is active or not, but as long as it works, it's fine with me.  I see that by activating the output, the LED turns on automatically.  That is, I'm not required to activate the output and turn on the LED too.
« Last Edit: September 13, 2007, 09:30:14 PM by coyotegd »

Offline Chaoticone

*
  • *
  •  5,624 5,624
  • Precision Chaos
    • View Profile
Re: How to attach VB script to button
« Reply #9 on: September 13, 2007, 09:22:41 PM »
Glad you got it.  :)

Brett
;D If you could see the things I have in my head, you would be laughing too. ;D

My guard dog is not what you need to worry about!