Hi everyone, I wrote this script to zero all the axis. 
When I try it step by step in the VB script editor everything works fine but when I try it in Mach3 hitting the "Auto Tool Zero" button it's working weirdly. 
So I have two G31 moves for each axis, a "fast" feed rate move then retract and a second one very slow. 
Here is the problem, On the X and Y axis, when the script perform the fast move it's actually in the wrong direction. All the others moves are in the correct direction. The Z axis moves (fast and slow) are also ok.
I can't find the problem by myself, please help 

Here is the code that I wrote taking inspiration from a few different one found online:
ToolRadius = GetOemDRO(1112)/2
PlateOffset = 20
CurrentFeed = GetOemDRO(818)
CurrentAbsInc = GetOemLED(48)
CurrentGmode = GetOemDRO(819)
CurrentFeedOverride = GetOEMDRO(821)
   'X 1st Pass at fast rate
   Message "X axis 1st pass"
   If GetOemLed (825) = 0 Then
      DoOemButton (1008)
      Code "G4 P0.5"
      SetOemDRO (821,100)
      Code "G90 G31 X20 F600"
      While IsMoving()
      Wend
      XProbePos = GetVar(2000)
      If Abs(XprobePos) <= Abs(20) - 0.1 Then
         Code "G0 X" &XProbePos
         While IsMoving()
         Wend
         Call SetDro (0,0)
         Code "G4 P0.25"
         Code "G1 X-1 F1000"
         While IsMoving()
         Wend
         Message "X axis 2nd pass"
      Else
         Code "G53 G0 X" &x
         While IsMoving()
         Wend
         Message "Material not found, check connection and try again"
         Code "F" &CurrentFeed
         SetOemDRO (821,CurrentFeedOverride)
         If CurrentAbsInc = 0 Then Code "G91"
         If CurrentGMode = 0 Then Code "G0"
         End If
   Else
   Message "Probe is grounded, check connection and try again"
   End If
   'X 2nd pass at slow rate
   DoOEMButton (1008)
   Code "G4 P0.5"
   Code "G31 X2 F30"
   While IsMoving()
   Wend
   XProbePos = GetVar(2000)
   If Abs(XprobePos) <= Abs(2) - 0.1 Then
      Code "G0 X" &XProbePos
      While IsMoving()
      Wend
      Call SetDro (0,-ToolRadius)
      Code "G4 P0.25"
      Message "X axis is now zeroed"
      Code "G91 G0 X-10"
      Code "G0 Y-20"
      Code "G0 X20"   
      While IsMoving()
      Wend
   Else
      Code "G53 G0 X" &x
      While IsMoving()
      Wend
      Message "Material not found, check connection and try again"
   End If
   'Y 1st Pass at fast rate
   Message "(Y axis 1st pass)"
   If GetOemLed (825) = 0 Then
      DoOemButton (1009)
      Code "G4 P0.5"
      Code "G90 G31 Y20 F600"
      While IsMoving()
      Wend
      YProbePos = GetVar(2001)
      If Abs(YprobePos) <= Abs(20) - 0.1 Then
         Code "G0 Y" &YProbePos
         While IsMoving()
         Wend
         Call SetDro (1,0)
         Code "G4 P0.25"
         Code "G1 Y-1 F1000"
         While IsMoving()
         Wend
         Message "Y axis 2nd pass"
      Else
         Code "G53 G0 Z0"
         Code "G53 G0 Y" & y & "X" & x
         Code "G53 G0 Z" & z
         While IsMoving()
         Wend
         Message "Material not found, check connection and try again"
         Code "F" &CurrentFeed
         SetOemDRO (821,CurrentFeedOverride)
         If CurrentAbsInc = 0 Then Code "G91"
         If CurrentGMode = 0 Then Code "G0"
         End If
   Else
   Message "Probe is grounded, check connection and try again"
   Code "F" &CurrentFeed
   SetOemDRO (821,CurrentFeedOverride)
   If CurrentAbsInc = 0 Then Code "G91"
   If CurrentGMode = 0 Then Code "G0"
   End If
   'Y 2nd pass at slow rate
   DoOEMButton (1009)
   Code "G4 P0.5"
   Code "G31 Y2 F30"
   While IsMoving()
   Wend
   YProbePos = GetVar(2001)
   If Abs(YprobePos) <= Abs(2) - 0.1 Then
      Code "G0 Y" &YProbePos
      While IsMoving()
      Wend
      Call SetDro (1,-ToolRadius)
      Code "G4 P0.25"
      Message "Y axis is now zeroed"
      Code "G91 G0 Y-5"
      Code "G0 Z50"
      Code "G90 G0 X20 Y20"   
      While IsMoving()
      Wend
   Else
      Code "G53 G0 Z0"
      Code "G53 G0 Y" & y & "X" & x
      Code "G53 G0 Z" & z
      While IsMoving()
      Wend
      Message "Material not found, check connection and try again"
      Code "F" &CurrentFeed
      SetOemDRO (821,CurrentFeedOverride)
      If CurrentAbsInc = 0 Then Code "G91"
      If CurrentGMode = 0 Then Code "G0"
   End If