Help from the group, This is a older program that I finally found time to pick-up again. Basically I wanted to create a text file that finds the midpoint of a set of station values and write those stations to a text file. The end product will insert a block at station and offset when done. The problem is getting the correct output values in a text file. The inserted block is a runway centerline paint stripe block with a insert point on the left side stripe. Runway stripes are marked starting at both ends and working to the midpoint of the runway. that's where I'm having trouble. the test for the midpoint looks like it should work but it stops one full station short on one end and goes one station too long in the other direction. each stripe is spaced 200' apart. start of runway is (textbox1) = 1000, end runway is (textbox2) = 6200, total distance of runway is 5200' station value for the midpoint = 5200 length of runway + 1000 for start station given a midpoint station of 3600. also when the routine ends it reports a end file name or number. ? how do I end closing the file without this error. can't see where I'm going wrong. This is the clstripe.txt output file 1310,0 1710,0 2110,0 2510,0 2910,0 3310,0 , this should be last station 3710,0 , wrong should not be here 5770,0 5570,0 5370,0 5170,0 4970,0 4770,0 4570,0 4370,0 4170,0 3970,0 , this should be 3770,0 I placed a sample drawing in the AutoDesk.AutoCAD.customer-files "marking-test" under distance test. As always thank you to the group for your help. John Coon Private Sub CommandButton2_Click() Dim strstart, strend, strspacing, stroffset, fromend, newstart, newend, increment As Double Dim midpoint As Double strstart = TextBox1.Text ' 1000 strend = TextBox2.Text ' 6200 stroffset = 0 strspacing = 200 fromend = (-430) newstart = strstart + 310 newend = strend + fromend midpoint = (strend - strstart) / 2 + 1000 Open "C:\temp\clstripe.txt" For Output As #1 'Open file for output For increment = newstart To newend Step strspacing Print #1, increment & "," & stroffset 'Write right side comma-delimited If increment > midpoint Then increment = newend - 200 strspacing = (-200) newend = newend - 200 If increment < midpoint Then Close #1 End If Else: increment = increment + 200 End If Next increment Close #1 'Close file End Sub
John, Try this. You had more going on inside the For..Next Loop than you needed, plus the Print was in the wrong place. strstart = 1000 strend = 6200 stroffset = 0 strspacing = 200 fromend = -430 newstart = strstart + 310 newend = strend + fromend + strspacing midpoint = ((strend - strstart) / 2) + strstart Open "C:\temp\clstripe.txt" For Output As #1 'Open file for output For increment = newstart To newend Step strspacing If increment > midpoint Then increment = newend - 200 newend = newend - 200 If increment < midpoint Then Close #1 Exit For End If End If Print #1, increment & "," & stroffset 'Write right side comma-delimited Next increment Jeff
Jeff, Once again Jeff to the rescue. Thanks Man! I read the Exit for help...... It worked like a charm. I'll remember that the next time. where you changed the ((strend - strstart) / 2) + strstart. that will make the routine work with all start station input. what a bonehead I am at times. I also see where moving the print statement works without a hitch. Thanks, Have a great day John