Dim Answer
Dim newPos As Double
Dim arch As String
Dim a As Integer
Dim txt1 As String
Dim txt2 As String
Dim stxt1 As String
Dim stxt2 As String
Dim x1 As Variant
Dim y1 As Variant
Dim x2 As Variant
Dim y2 As Variant
Dim xf1 As Variant
Dim yf1 As Variant
Dim xf2 As Variant
Dim yf2 As Variant

Dim l1 As Integer
Dim l2 As Integer
Dim resx As Variant
Dim resy As Variant
Dim estx As String
Dim esty As String
Dim cuch As Variant

arch=FileName()

	If arch="No File Loaded." Then
		message"Debe abrir un archivo antes"
	Else 
	
		TeachFile = "EMBER.nc" 
		Dim Err As Integer 
		Err = OpenTeachFile(TeachFile) 
		If Err = 0 Then 
			MsgBox("Unable To Open: " & Teachfile) 
		Else  
			Code("G55") 
			Code("G00 X0.000 Y0.000 Z0.000") 
			DoOEMButton(234) 'OUT 4 Off

		End If 
		CloseTeachFile()	
		
		a=1
		Open arch For Input As #1 
			Do While Not EOF(1) 	
   				
 				Line Input #1, TextLine 			
 				If a=1 Then
 					txt1=TextLine
 					x1=""
 					x2=""
 					y1=""
 					y2=""
 					l1=Len(txt1)  					
 					c=0
 					d=0 					
 					For i=1 To (l1)
 						stxt1=Mid(txt1,i,1)				
						
 						If stxt1="X" Or stxt1="x" Then
 							c=1 							
 						End If
 						
 						If stxt1="Y" Or stxt1="y" Then
 							c=2
 							d=1 							
 						End If
 						
 						If d=1 Then
 							If stxt1="Z" Or stxt1="z" Or stxt1="F" Or stxt1="f" Or stxt1="A" Or stxt1="S" Or stxt1="s" Or stxt1="M" Then
 								c=0
 							End If 						
 						End If
 						
 						
 						If c=1 Then
 							If stxt1="X" Or stxt1="x" Then
 							Else
 								x1=(x1 & stxt1) 								
 							End If
 						End If
 						
 						If c=2 Then
 							If stxt1="Y" Or stxt1="y" Then
 							Else
 								y1=(y1 & stxt1) 								
 							End If
 						End If 						
 					Next i					
 								
 					a=2
 				Else
 					txt1=TextLine
 					l1=Len(txt1) 
  					c=0
 					d=0 					
 					For i=1 To (l1)
 						stxt1=Mid(txt1,i,1)						

 						
 						If stxt1="X" Or stxt1="x" Then
 							c=1 							
 						End If
 						
 						If stxt1="Y" Or stxt1="y" Then
 							c=2
 							d=1 							
 						End If
 						
 						If d=1 Then
 							If stxt1="Z" Or stxt1="z" Or stxt1="F" Or stxt1="f" Or stxt1="A" Or stxt1="S" Or stxt1="s" Or stxt1="M" Then
 								c=0
 							End If 						
 						End If
 						 						
 						If c=1 Then
 							If stxt1="X" Or stxt1="x" Then
 							Else
 								x2=(x2 & stxt1) 								
 							End If
 						End If
 						
 						If c=2 Then
 							If stxt1="Y" Or stxt1="y" Then
 							Else
 								y2=(y2 & stxt1) 								
 							End If
 						End If
  					Next i
					a=1		

 				End If 
 				
 				If x2="" Or x1="" Or y1="" Or y2="" Then 						
 				
 				Else
 					xf1=x1
 					yf1=y1
 					xf2=x2
 					yf2=y2 					
 					resy=yf2-yf1 			
 					resx=xf2-xf1		
					 					
 					If resx=0 Then
 						estx="vert"
 					End If
 				
 					If resx<0 Then
 						estx="neg"
 					End If
 				
 					If resx>0 Then
 						estx="pos"
 					End If				
 				
 					If resy=0 Then
 						esty="hor"
 					End If
 				
 					If resy<0 Then
 						esty="neg"
 					End If
 				
 					If resy>0 Then
 						esty="pos"
 					End If 				
 				
 					If estx="vert" And esty="pos" Then
 						cuch=0
 					End If
 				
 					If estx="vert" And esty="neg" Then
 						cuch=180
 					End If
 				
 					If estx="pos" And esty="hor" Then
 						cuch=90
 					End If
 				
 					If estx="neg" And esty="hor" Then
 						cuch=270
 					End If
 				
 					If estx="pos" And esty="pos" Then
 						cuch=Atn((x2-x1)/(y2-y1))
 					End If

					If estx="pos" And esty="neg" Then
 						cuch=Atn(((x2-x1)/(y1-y2))+90)
 					End If
 				
 					If estx="neg" And esty="neg" Then
 						cuch=Atn(((x1-x2)/(y1-y2))+180)
 					End If
 				
 					If estx="neg" And esty="pos" Then
 						cuch=Atn(((x1-x2)/(y2-y1))+270)
 					End If
 					
 					Err = AppendTeachFile(TeachFile)  
					If Err = 0 Then 
						MsgBox("Unable To Open: " & TeachFile)
					Else 	
					 	If cuch<10 Then
					 		Code("G1X" & xf1 & "Y" & yf1) 
	 						Code("G1Z" & cuch)
	 						DoOEMButton(233) 'OUT 4 ON	 						
	 						Code("G1X" & xf2 & "Y" & yf2)
	 					Else
	 						DoOEMButton(234) 'OUT 4 Off
	 						Code("G1X" & xf1 & "Y" & yf1) 	 						
	 						Code("G1Z" & cuch)
	 						DoOEMButton(233) 'OUT 4 ON	
	 						Code("G1X" & xf2 & "Y" & yf2)
	 					
	 					End If
	 				End If	 
	 				CloseTeachFile() 					
 					
 				End If		
  			Loop 
  		Close #1    
  	End If                                         
