it is a bit of a dry read but thankfully [crtl]-F works in it.
http://www.machsupport.com/wp-content/uploads/2013/02/VBScript_Commands.pdfHope fully the comments explain a bit of what is going on here then. A single quote ' is the standard ascii character for comments in mach3 so ill use them for comments. Hopefully the spaces make it a bit easier to read too.
sub tap(byval zstart as double,byval zend as double,byval zinc as double,byval dwell as double,byval speed as double) ' sub is asking for the start height, end height, the increment distance, dwell time and speed of movement to be given to it.
dim zpos as double ' i am defining a variable called zpos and the current z location so that i do not edit the variable i am given at the start
zpos = zstart ' set zpos to be zstart if zstart is too high up it will take a while so set it close to the material.
while zpos >= zend ' will continue the loop until the desired position is less than or equal to the end position
code "g01 z " & zpos & " f " & speed ' Gcode to move to current z location at specified speed
while IsMoving() ' IsMoving() is true while the cnc is in motion, it is needed since your dwell sleep would start as soon the movement starts if this was not blocking
sleep(10) ' pause for small amount of time, you will acutlaly dwell there for your dwell time and an extra amount of time any where between 0 and 10ms
wend
sleep(dwell) ' your dwell time
if zpos = zend then ' checks to see if it is at the final location, and if so it decrements it one more to make while loop stop
zpos = zend - 1
elseif zpos > zend then ' if zpos is still greater than zend
zpos = zpos - zinc ' change zpos by the defined amount
if zpos <= zend then ' check to see if zpos was decremented too far and if it was set it to the end value
zpos = zend
endif
endif
wend
end sub