<html>

<head>
<meta http-equiv="Content-Language" content="en-au">
<meta name="GENERATOR" content="Microsoft FrontPage 12.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>%WebGcode</title>
</head>
<%

FUNCTION fixcrlf ( theString)
  fixcrlf = REPLACE( theString, Chr(13), "<br>" ) & "<br>"
END FUNCTION

dim activefixture(3)
dim activetype (3)
dim activepart (3)
dim typenum (3)
dim optiontypename (100)
dim partnum (3)
dim optionpartname(500)
dim tooltable(50)
dim total(3)
dim fixturewarning(3)

dim tooltableID(3,25)

dim partID (3)
dim partname (3)
dim parttype (3)
dim  partdescription (3)
dim  partblank (3)
dim  partsetup (3)
dim  partfixture (3)
dim  partfixturenum (3)
dim  partZA (3)
dim  partZB (3)
dim  partZsafe (3)
dim  partXoffsetA (3)
dim  partYoffsetA (3)
dim  partZoffsetA (3)
dim  partXoffsetB (3)
dim  partYoffsetB (3)
dim  partZoffsetB (3)
dim  partvar14 (3)
dim  partvar14description (3)
dim  partvar15 (3)
dim  partvar15description (3)
dim  partvar16 (3)
dim  partvar16description (3)
dim  partvar17 (3)
dim  partvar17description (3)
dim  partvar18 (3)
dim  partvar18description (3)
dim  partvar19 (3)
dim  partvar19description (3)
dim  toolID (3,25)
dim  toolpartID (3,25)
dim  toolsequence (3,25)
dim  toolnumber (3,25)
dim  tooldescription (3,25)
dim  toolend (3,25)
dim  stepID (3,25)
dim  steptoolID (3,25)
dim  stepoperationID (3,25)
dim  stepsequence (3,25)
dim  operationID (3,25)
dim  operationname (3,25)
dim  operationdescription (3,25)
dim  operationtoolnumber (3,25)
dim  operationcode  (3,25)


' Open Database Connection Server.MapPath(".")
dbPath =  "E:/hshome/webcaddy/database/PartMaker.mdb"
Set Con = Server.CreateObject("ADODB.Connection")
Con.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath

activefixture(1) = TRIM( Request( "fixture" ) )
if activefixture(1) = "" then
  activefixture(1)= -1
  activefixture(2)= 2
  activefixture(3)= 3
else
  activefixture(2)= activefixture(1) + 1
  activefixture(3)= activefixture(1) + 2
end if
activetype(1) = TRIM( Request( "type" ) )
if activetype(1) = "" then
  activetype(1)= "%"
  activetype(2)= "%"
  activetype(3)= "%"
else
  activetype(2)= activetype(1) 
  activetype(3)= activetype(1) 
end if
activepart(1) = TRIM( Request( "part" ) )
activetype(2)= activetype(1) 
activetype(3)= activetype(1) 

selectpart = TRIM( Request( "selectpart" ) )
if selectpart = "" then
  selectpart="TRUE"
end if
%>

<%
IF session( "iDebugLevel" ) > 1 THEN %>
   Session Debug Level Set to:<%=session( "iDebugLevel" )%> <br>
   <%for i=1 to Request.Form.Count%>
   Form Key #<%=i%> = <%=Request.Form.Key(i)%> =>  <%=Request(Request.Form.Key(i))%><br>
   <%next%>
<%END IF%>

<%
'Commands are sent from the form in the last key
'90 = Update all fields in all tables for this part
sqlstring="Nothing"
FormCount = Request.Form.Count
IF FormCount > 0 THEN
  FormCommand = Request.Form.Key(FormCount)
  SELECT CASE FormCommand
    CASE 90 'Update all selections
      %>Updated selections<br><%
      selectpart = "TRUE"
      if request("manual") = "ON" then
        activefixture(1)= Request("SelFixture1")
        activefixture(2)= Request("SelFixture2")
        activefixture(3)= Request("SelFixture3")
      else
        activefixture(1)= Request("SelFixture1") + 0
        activefixture(2)= Request("SelFixture1") + 1
        activefixture(3)= Request("SelFixture1") + 2
      end if  
      if request("manual") = "ON" then
        activetype(1)= Request("Seltype1")
        activetype(2)= Request("Seltype2")
        activetype(3)= Request("Seltype3")
      else
        activetype(1)= Request("Seltype1")
        activetype(2)= Request("Seltype1")
        activetype(3)= Request("Seltype1")
      end if  
      if request("partmanual") = "ON" then
        activepart(1)= Request("Selpart1")
        activepart(2)= Request("Selpart2")
        activepart(3)= Request("Selpart3")
      else
        activepart(1)= Request("Selpart1")
        activepart(2)= Request("Selpart1")
        activepart(3)= Request("Selpart1")
      end if  
    CASE 91 'Post Code to file
      selectpart = "FALSE"
      activefixture(1)= Request("SelFixture1")
      activefixture(2)= Request("SelFixture2")
      activefixture(3)= Request("SelFixture3")
      activetype(1)= Request("Seltype1")
      activetype(2)= Request("Seltype2")
      activetype(3)= Request("Seltype3")
      activepart(1)= Request("selpart1")
      activepart(2)= Request("selpart2")
      activepart(3)= Request("selpart3")
      manual       = Request("manual")
      partmanual   = Request("partmanual")
    CASE ELSE
    %>None Implemented Command Selected<br><%
  END SELECT
END IF%>


<%
'Collect the available Type and Part Names 
For i= 1 to 3
  if activefixture(1)=-1 then 
    sqlString1 = "SELECT DISTINCT part_type FROM part " &_
                " ORDER BY part_type "
    sqlString2 = "SELECT DISTINCT part_name FROM part " &_
                 " ORDER BY part_name "
  else
    sqlString1 = "SELECT DISTINCT part_type FROM part " &_
                 "WHERE part_fixturenum = " & activefixture(i) + 1 - i &_
                 " ORDER BY part_type "
    sqlString2 = "SELECT DISTINCT part_name FROM part " &_
                 "WHERE part_fixturenum = " & activefixture(i)  + 1 - i &_
                 " AND part_type LIKE '" & activetype(i) & "' " &_
                 " ORDER BY part_name "
  end if            
  IF session( "iDebugLevel" ) > 0 THEN %>
    Session Debug Level Set to:<%=session( "iDebugLevel" )%> <BR>
    sqlString1: <%=sqlstring1%><br>
    sqlString2: <%=sqlstring2%><br>
  <%END IF
  SET RS = Con.Execute( sqlString1 )
  typenum(i) = 0
  WHILE NOT RS.EOF
    typenum(i) = typenum(i) + 1
    optiontypename (typenum(i)) = RS( "part_type")
    RS.MoveNext
    IF session( "iDebugLevel" ) > 0 THEN %>
      TypeNum: <%=typenum(i)%>  PartType:<%=parttype(typenum(i))%><br>
    <%END IF
  WEND
  SET RS = Con.Execute( sqlString2 )
  partnum(i) = 0
  WHILE NOT RS.EOF
    partnum(i)= partnum(i)+ 1
    optionpartname(partnum(i)) = RS( "part_name")
    RS.MoveNext
    IF session( "iDebugLevel" ) > 0 THEN %>
      TypeNum: <%=partnum(i)%>  PartType:<%=optionpartname(partnum(i))%><br>
    <%END IF
  WEND
Next
if activefixture(1)=-1 then activefixture(1)=1 end if
%>

<%
'Build Gcode
numofparts=0
for i = 1 to 3
  if NOT(activepart(i)="") then numofparts=i end if
  total(i)=0
Next
for i = 1 to numofparts
  sqlstring = "Select  part_ID, part_name, part_type, part_description, part_blank, part_setup, " &_
              "part_fixture, part_fixturenum, part_ZA, part_ZB, part_Zsafe, part_XoffsetA, " &_
              "part_YoffsetA, part_ZoffsetA, part_XoffsetB, part_YoffsetB, part_ZoffsetB, " &_ 
              "part_var14, part_var14description, part_var15, part_var15description,  " &_ 
              "part_var16, part_var16description, part_var17, part_var17description,  " &_ 
              "part_var18, part_var18description, part_var19, part_var19description,  " &_ 
              "tool_ID, tool_partID, tool_sequence, tool_number, tool_description, tool_end " &_
              "FROM part INNER JOIN tool ON part.part_ID = tool.tool_partID " &_
              "WHERE part_name = '" & activePart(i) & "'  AND " &_
              "tool_number < 99 " &_ 
              "ORDER BY tool_end, tool_sequence"
  IF session( "iDebugLevel" ) > 1 THEN %>
    sqlString: <%=sqlstring%><br>
  <%END IF
  SET RS = Con.Execute (sqlstring)
  j=0
WHILE NOT RS.EOF
  j=j+1
  partID(i) = RS("part_ID")
  partname(i) = RS("part_name")
  parttype(i) = RS("part_type")
  partdescription(i) = RS("part_description")
  partblank(i) = RS("part_blank")
  partsetup(i) = RS("part_setup")
  partfixture(i) = RS("part_fixture")
  fixturetest=RS("part_fixturenum")+i-1
  if activefixture(i) = fixturetest  then
    partfixturenum(i) = RS("part_fixturenum")+i-1
    fixturewarning(i) = "FALSE"
  else
    partfixturenum(i) = RS("part_fixturenum")+i-1
    fixturewarning(i) = "TRUE"
  end if
  partZA(i) = RS("part_ZA")
  partZB(i) = RS("part_ZB")
  partZsafe(i) = RS("part_Zsafe")
  partXoffsetA(i) = RS("part_XoffsetA")
  partYoffsetA(i) = RS("part_YoffsetA")
  partZoffsetA(i) = RS("part_ZoffsetA")
  partXoffsetB(i) = RS("part_XoffsetB")
  partYoffsetB(i) = RS("part_YoffsetB")
  partZoffsetB(i) = RS("part_ZoffsetB")
  partvar14(i) = RS("part_var14")
  partvar14description(i) = RS("part_var14description")
  partvar15(i) = RS("part_var15")
  partvar15description(i) = RS("part_var15description")
  partvar16(i) = RS("part_var16")
  partvar16description(i) = RS("part_var16description")
  partvar17(i) = RS("part_var17")
  partvar17description(i) = RS("part_var17description")
  partvar18(i) = RS("part_var18")
  partvar18description(i) = RS("part_var18description")
  partvar19(i) = RS("part_var19")
  partvar19description(i) = RS("part_var19description")
  toolID(i,j) = RS("tool_ID")
  toolpartID(i,j) = RS("tool_partID")
  toolsequence(i,j) = RS("tool_sequence")
  toolnumber(i,j) = RS("tool_number")
  tooldescription(i,j) = RS("tool_description")
  toolend(i,j) = RS("tool_end")
  total(i)=j
  RS.MoveNext
WEND
Next
If total(1)>=total(2) then
 If total(1) >= total(3) then
   maxtools=total(1)
 else
   maxtools=total(3)
 end if
else
 If total(2) >= total(3) then
   maxtools=total(2)
 else
   maxtools=total(3)
 end if
end if
toolchange=0
currenttool=-1
for j=1 to maxtools
  for i = 1 to 3
    if NOT (toolnumber(i,j)="") then
      if NOT (currenttool=toolnumber(i,j)) then
        currenttool=toolnumber(i,j)
        toolchange=toolchange+1
        tooltable(toolchange)=currenttool
      end if
      tooltableID(i,toolchange)=toolID(i,j)
    end if
  Next
Next    
totaltoolchanges=toolchange
%>
<body>

  <form action="PartMaker.asp" name=PartMaker Method=Post>
<%if selectpart = "TRUE" then %>
  <h1>Bridge Port Mill Code Maker</h1>
  </p>
  <table border="1" cellspacing="1" width="61%" id="AutoNumber1" height="98">
    <tr>
      <td width="21%" height="19">
      <p align="center">Manual Update:<br>
      <input type="checkbox" name="manual" value="ON" 
      <%if request("manual") = "ON" then%>
        checked
      <%end if%>
      ></td>
      <td width="25%" align="center" height="19">Position 3</td>
      <td width="25%" align="center" height="19">Position 2</td>
      <td width="29%" align="center" height="19">Position 1</td>
    </tr>
    <tr>
      <td width="21%" height="21">Fixture</td>
      <td width="25%" align="center" height="1"
      <%if fixturewarning(3)="TRUE" then%>
        bgcolor="#FF0000"
      <%end if%>
      >  
      <select size="1" name="selfixture3">
      <option selected value="<%=activefixture(3)%>"><%=activefixture(3)%></option>
      <option>3</option>
      <option>6</option>
      <option>9</option>
      <option>12</option>
      <option>15</option>
      <option>18</option>
      <option>21</option>
      </select></td>
      <td width="25%" align="center" height="1"
      <%if fixturewarning(2)="TRUE" then%>
        bgcolor="#FF0000"
      <%end if%>  
      >
      <select size="1" name="selfixture2">
      <option selected value="<%=activefixture(2)%>"><%=activefixture(2)%></option>
      <option>2</option>
      <option>5</option>
      <option>8</option>
      <option>11</option>
      <option>14</option>
      <option>17</option>
      <option>20</option>
      </select></td>
      <td width="29%" align="center" height="1"
      <%if fixturewarning(1)="TRUE" then%>        
      bgcolor="#FF0000"
      <%end if%>
      >  
      <select size="1" name="selfixture1">
      <option selected value="<%=activefixture(1)%>"><%=activefixture(1)%></option>
      <option>1</option>
      <option>4</option>
      <option>7</option>
      <option>10</option>
      <option>13</option>
      <option>16</option>
      <option>19</option>
      </select></td>
    </tr>
    <tr>
      <td width="21%" height="19">Type</td>
      <td width="25%" align="center" height="1">
      <select size="1" name="seltype3">
      <option selected value="<%=activetype(3)%>"><%=activetype(3)%></option>
      <option value="%">%</option>
      <%For i = 1 to typenum(3)%>
        <option value="<%=optiontypename (i)%>"><%=optiontypename (i)%></option>
      <%Next%>
      </select></td>
      <td width="25%" align="center" height="1">
      <select size="1" name="seltype2">
      <option selected value="<%=activetype(2)%>"><%=activetype(2)%></option>
      <option value="%">%</option>
      <%For i = 1 to typenum(2)%>
        <option value="<%=optiontypename (i)%>"><%=optiontypename (i)%></option>
      <%Next%>
      </select></td>
      <td width="29%" align="center" height="1">
      <select size="1" name="seltype1">
      <option selected value="<%=activetype(1)%>"><%=activetype(1)%></option>
      <option value="%">%</option>
      <%For i = 1 to typenum(1)%>
        <option value="<%=optiontypename (i)%>"><%=optiontypename (i)%></option>
      <%Next%>
      </select></td>
    </tr>
    <tr>
      <td width="21%" height="19">Part
      <input type="checkbox" name="partmanual" value="ON" 
      <%if request("partmanual") = "ON" then%>
        checked
      <%end if%>
      ></td>
      <td width="25%" align="center" height="1">
      <select size="1" name="selpart3">
      <option selected value="<%=activepart(3)%>"><%=activepart(3)%></option>
      <%For i = 1 to partnum(3)%>
        <option value="<%=optionpartname(i)%>"><%=optionpartname(i)%></option>
      <%Next%>
      </select></td>
      <td width="25%" align="center" height="1">
      <p align="center">
      <select size="1" name="selpart2">
      <option selected value="<%=activepart(2)%>"><%=activepart(2)%></option>
      <%For i = 1 to partnum(2)%>
        <option value="<%=optionpartname(i)%>"><%=optionpartname(i)%></option>
      <%Next%>
      </select></td>
      <td width="29%" align="center" height="1">
      <select size="1" name="selpart1">
      <option selected value="<%=activepart(1)%>"><%=activepart(1)%></option>
      <%For i = 1 to partnum(1)%>
        <option value="<%=optionpartname(i)%>"><%=optionpartname(i)%></option>
      <%Next%>
      </select></td>
    </tr>
<%else%>
  <input name="manual" type="hidden" value="<%=manual%>">
  <input name="selfixture1" type="hidden" value="<%=activefixture(1)%>">
  <input name="selfixture2" type="hidden" value="<%=activefixture(2)%>">
  <input name="selfixture3" type="hidden" value="<%=activefixture(3)%>">
  <input name="seltype1" type="hidden" value="<%=activetype(1)%>">
  <input name="seltype2" type="hidden" value="<%=activetype(2)%>">
  <input name="seltype3" type="hidden" value="<%=activetype(3)%>">
  <input name="partmanual" type="hidden" value="<%=partmanual%>">
  <input name="selpart1" type="hidden" value="<%=activepart(1)%>">
  <input name="selpart2" type="hidden" value="<%=activepart(2)%>">
  <input name="selpart3" type="hidden" value="<%=activepart(3)%>">
<%end if%>
<%currentend="A"%>
<%if selectpart = "TRUE" then %>
  <%For j = 1 to totaltoolchanges%>
    <tr>
      <td width="21%" height="19">Tool Change: <%=j%><br>
            <input type="checkbox" name="ToolDact<%=j%>" value="DEACT"
            <%if request("ToolDact" & j) = "DEACT" then%>
             checked
            <%end if%>
            ></td>
      <%For ii=-3 to -1%>
        <%i=abs(ii)%>
        <td width="25%" align="center" height="1">
        <%if NOT(tooltableID(i,j)="") then%>
          <%sqlstring = "SELECT operation_name, operation_description, operation_code, step_sequence " &_
                        "FROM operation INNER JOIN step ON operation.operation_ID = step.step_operationID " &_
                        "WHERE step_toolID = " & tooltableID(i,j) & " " &_ 
                        "ORDER BY step_sequence"

          IF session( "iDebugLevel" ) > 1 THEN %>
            sqlString: <%=sqlstring%><br>
          <%END IF%>
          <%SET RS = Con.Execute (sqlstring)%>
          <%if NOT (currentend=toolend(i,j))then%> 
            <font color="#FF0000">TURN PARTS OVER</font><br>
            <%currentend = toolend(i,j)%>
          <%end if%>
          <%OpNum=0%>
          <%While NOT RS.EOF%>
            <%OpNum=OpNum+1%>
            Op: <%=j%><%=i%><%=OpNum%> DeAct
            <input type="checkbox" name="OpDact<%=j%><%=i%><%=OpNum%>" value="DEACT"
            <%if request("OpDact" & j& i & OpNum) = "DEACT" then%>
             checked
            <%end if%>
            > 
            <br>
            <%RS.MoveNext%>
          <%WEND%>
        <%else%>
           No Operation
        <%end if%>
         </td>
      <%Next%>  
    </tr>
  <%Next%>
  </table>
<%else%>
  <%For j = 1 to totaltoolchanges%>
      <%For ii=-3 to -1%>
        <%i=abs(ii)%>
        <%if NOT(tooltableID(i,j)="") then%>
          <%sqlstring = "SELECT operation_name, operation_description, operation_code " &_
                        "FROM operation INNER JOIN step ON operation.operation_ID = step.step_operationID " &_
                        "WHERE step_toolID = " & tooltableID(i,j) & " " &_ 
                        "ORDER BY step_sequence"
          IF session( "iDebugLevel" ) > 1 THEN %>
            sqlString: <%=sqlstring%><br>
          <%END IF%>
          <%SET RS = Con.Execute (sqlstring)%>
          <%OpNum=0%>
          <%While NOT RS.EOF%>
            <%OpNum=OpNum+1%>
            <input type="hidden" name="OpDact<%=j%><%=i%><%=OpNum%>"
            value="<%=request("OpDact" & j& i & OpNum)%>">
            <%RS.MoveNext%>
          <%WEND%>
        <%end if%>
      <%Next%>  
  <%Next%>
<%end if%>
<input name="selectpart" type="hidden" value="<%=selectpart%>">
<input type="Submit" value="Update" name="90">
<input type="Submit" value="Post Code" name="91">
</form>
<font face="Courier">% Code Maker - <%=numofparts%> part Program <%=now()%><br>
% Part Names 1:<%=partname(1)%> 2:<%=partname(2)%> 3:<%=partname(3)%><br>
% Fixtures   1:<%=partfixturenum(1)%> 2:<%=partfixturenum(2)%> 3:<%=partfixturenum(3)%><br>
% Total Number of Tool changes required: <%=totaltoolchanges%><br>
% Total Tool Interactions: <%=total(1)+total(2)+total(3)%><br>
<%for i = 1 to totaltoolchanges%>
%   Tool change: <%=i%> using tool #: <%=tooltable(i)%><br>
<%Next%>
<%For i = 1 to numofparts %>
% N<%=i%>:<%=partname(i)%><br>
% D<%=i%>:<%=fixcrlf (partdescription(i))%>
% B<%=i%>:<%=fixcrlf (partblank(i))%>
% S<%=i%>:<%=fixcrlf (partsetup(i))%>
% F<%=i%>:<%=fixcrlf (partfixture(i))%>
% <br>
<%Next%>
%Initialisation Codes<br>
G21 % mm coordinate System <br>
G17 % X-Y plane selected<br>
G50 % Turn any scaling off<br>
G92.1 % turn off any previous offsets<br>
G64 % Set Constant Velocity Mode<br>
G90 % Absolute Co-ordinate Mode<br>
#4060=1 %Initialise Tool Radius<br>
% ***  START Making Parts ***<br>
<%currentend="A"%>
<%For j = 1 to totaltoolchanges%>
  <%if request("ToolDact" & j) = "DEACT" then%>
    % Tool change <%=j%> de-activiated<br>
  <%else%>
    %**************************<br>
    M06 T <%=tooltable(j)%><br>
    %**************************<br>
    <%For i = 1 to numofparts %>
      <%if NOT(tooltableID(i,j)="") then%>
        <%sqlstring = "SELECT operation_name, operation_description, operation_code " &_
                      "FROM operation INNER JOIN step ON operation.operation_ID = step.step_operationID " &_
                      "WHERE step_toolID = " & tooltableID(i,j) & " " &_ 
                      "ORDER BY step_sequence"
        IF session( "iDebugLevel" ) > 1 THEN %>
          sqlString: <%=sqlstring%><br>
        <%END IF%>
        <%SET RS = Con.Execute (sqlstring)%>
        <%if NOT (currentend=toolend(i,j))then%>
          % ***  TURN PARTS OVER   ***<br>
          % *************************<br>
          <%currentend = toolend(i,j)%>
        <%end if%>
        %Part:<%=partname(i)%>(<%=toolend(i,j)%>) Tool Change:<%=j%> Tool #: <%=tooltable(j)%><br>
        #10 = <%=(partZA(i))%> % ZA:<br>
        #11 = <%=(partZB(i))%> % ZB:<br>
        #12 = <%=(partZsafe(i))%> % ZSafe:<br>
        #14 = <%=(partvar14(i))%> % Var14: <%=partvar14description(i)%><br>
        #15 = <%=(partvar15(i))%> % Var15: <%=partvar15description(i)%><br>
        #16 = <%=(partvar16(i))%> % Var16: <%=partvar16description(i)%><br>
        #17 = <%=(partvar17(i))%> % Var17: <%=partvar17description(i)%><br>
        #18 = <%=(partvar18(i))%> % Var18: <%=partvar18description(i)%><br>
        #19 = <%=(partvar19(i))%> % Var19: <%=partvar19description(i)%><br>
        G59 P<%=partfixturenum(i)%><br>
        % Set job reference point<br>
        <%if toolend(i,j) = "A" then%>
          G92.1<br>
          G00 X<%=partXoffsetA(i)%> Y<%=partYoffsetA(i)%> Z<%=partZsafe(i)+partZoffsetA(i)%><br>
          G92 X0 Y0 Z<%=partZsafe(i)-partZA(i)%><br>
        <%else%>
          G92.1<br>
          G00 X<%=partXoffsetB(i)%> Y<%=partYoffsetB(i)%> Z<%=partZsafe(i)+partZoffsetB(i)%><br>
          G92 X0 Y0 Z<%=partZsafe(i)-partZB(i)%><br>
        <%end if%>
        <%OpNum=0%>
        <%While NOT RS.EOF%>
          <%OpNum=OpNum+1%>
          <%if request("OpDact" & j & i & OpNum) = "DEACT" then%>
            % *** Operation Code <%=RS("Operation_Name")%> DE-ACTIVATED ***<br>
          <%else%>
            % *** Execute Operation Code <%=RS("Operation_Name")%> here: ***<br>
            % <%=fixcrlf ( RS("Operation_description"))%>
            <%=fixcrlf ( RS("operation_code"))%>
          <%end if%>
          <%RS.MoveNext%>
        <%WEND%>
      <%else%>
      % *** No Operation Code for Part:<%=partname(i)%>(<%=toolend(i,j)%>) Tool Change:<%=j%> Tool #: <%=tooltable(j)%><br>
      <%end if%>
      G00 G53 Z0<br>
    <%Next%>
  <%end if%>
<%Next%>
M5  %Turn Spindle Off<br>
G50 <br>
G92.1<br>
G00 G53 X0 Y0 Z0<br>
% *** Program END ****<br>
M30<br>
</font> 
</body>
</html>