11
VB and the development of wizards / Re: Mach3 script editor bug?
« on: February 09, 2013, 04:19:12 PM »Sorry - I know you just want a one shot answer but hopefully you'll see why I think I would be wrong to give you one. Maybe someone will come along and explain it better.I am actually very grateful that you are teaching me, it is much more useful than just posting the code. This way next time I have to write something similar I will understand how it works
Yes there is a difference 10/3 in decimal is a infinite number and 3.3333333333333 is not infinite.
BaseX is used in a sub to control the X axis on a lathe to take the final roughing cuts and two finish cuts of a profile.
print round(0.5,0) Displays 0. I would have guessed it would have displayed 1. print round(0.6,0) displays 1.
print round(1.5,0) Displays 2 and so does print round(2.5,0).
Print Round(-1.5,0) and Print Round(-2.5,0) both display -2
I am not sure exactly how far off the rounding function makes my variable as it goes threw my loop. I now understand values produced by rounding are not accurate. Rounding a variable in a loop can cause the difference to grow based on the size of the loop. Possibly rounding difference * num of loops and is not good for accuracy.
In the future I will just use rounding for displaying information to the operator.
Currently my code looks like this. I tested it with n what do you think?
Code: [Select]
Code "G0 X.4" 'Back away X
Code "G0 Z.01" 'Back away Z
Code "G0 X0" 'Zero X
Dim BaseX As Double
BaseX = .0004 'Make BaseX .01 larger than needed.
Do Until BaseX = 0
If BaseX <= 0.002 Then BaseX = BaseX - .001 'If down to last cuts take off .001 and subtract until 0
If BaseX > 0.0021 And BaseX < .012 Then BaseX = .002 'If within .01 of .002 then set to .002
If BaseX > 0.012 Then BaseX = BaseX - .010 'If far away rough .01
If BaseX < 0 Then BaseX = 0 'Catch if BaseX starts <.001 and > 0
Code "G1 X" & BaseX + 0.110 & " Z0.00 F10"
Code "G2 X" & BaseX + 0.190 & " Z-0.075 R-0.066 F10"
Code "G1 X" & BaseX + 0.130 & " Z-0.600 F10"
Code "G0 X.4" 'Back away X
Code "G0 Z0.01" 'Back away Y
Code "G0 X" & BaseX 'Sets x to the base to save time
Loop