weixin7944 发表于 2006-8-10 14:12:00

循环中赋值出现的问题!

<P>Dim pt As Variant<BR>Dim kk As Integer<BR>kk = -1<BR>Dim m As Integer<BR>Dim pt1(2) As Double<BR>pt = ThisDrawing.Utility.GetPoint(, "请输入插入点!")<BR>&nbsp; <BR>For m =&nbsp;1 To&nbsp;30<BR>&nbsp;&nbsp;&nbsp; kk = kk + 1<BR>&nbsp;pt1(0) = pt(0) + 488: pt1(1) = pt(1) - 884 - (1500 * kk): pt1(2) = 0<BR>.......</P>
<P>NEXT</P>
<P>当kk=1~22时,该程序运行正常;但是当kk=23,24,25,26,27,28,29,30时程序出现问题,pt1的坐标不再改变,此时pt1的坐标与kk=22时的坐标相同。真的很奇怪,请问高手这究竟是因为什么?谢谢!</P>

fjfhgdwfn 发表于 2006-8-10 14:26:00

<P>试试.for m=22 to 30</P>
<P>看看出现问题不?</P>

weixin7944 发表于 2006-8-10 19:05:00

<P>运行正常,包括for m=8 to 30也可以,好像这个&nbsp;pt1(0) = pt(0) + 488: pt1(1) = pt(1) - 884 - (1500 * kk): pt1(2) = 0等式只能计算22次,真的很奇怪!</P>
<P>完整的程序如下:</P>
<P>Private Sub CommandButton4_Click()<BR>If (TextBox4.Text = "" Or TextBox5.Text = "") Then<BR>MsgBox "请输入起始位置!"<BR>Exit Sub<BR>End If<BR>Dim PathName As String<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PathName = TextBox1.Text<BR>&nbsp;On Error Resume Next<BR>&nbsp; Set xlapp = GetObject(, "excel.application")<BR>&nbsp; If Err Then<BR>&nbsp; Err.Clear<BR>&nbsp; Set xlapp = CreateObject("excel.application")<BR>&nbsp; If Err Then<BR>&nbsp; Err.Clear<BR>&nbsp; MsgBox ("不能运行EXCEL,请检查是否安装了EXCEL")<BR>&nbsp; Exit Sub<BR>&nbsp; End If<BR>&nbsp; End If<BR>&nbsp;xlapp.Workbooks.Open PathName<BR>Dim pt As Variant<BR>Dim kk As Integer<BR>kk = -1<BR>Dim m As Integer<BR>Dim textobject As AcadText<BR>Dim ts As AcadTextStyle<BR>&nbsp;&nbsp;&nbsp; Dim ts1 As AcadTextStyle<BR>&nbsp;&nbsp;&nbsp; Dim tsna As String<BR>Dim pt1(2) As Double<BR>Dim pt2(2) As Double<BR>Dim pt3(2) As Double<BR>Dim pt4(2) As Double<BR>Dim pt5(2) As Double<BR>Dim pt6(2) As Double<BR>Dim pt7(2) As Double<BR>frmMain.Hide<BR>pt = ThisDrawing.Utility.GetPoint(, "请输入插入点!")<BR>&nbsp; <BR>For m = CInt(TextBox4.Text - 1) To CInt(TextBox5.Text - 1)<BR>&nbsp;&nbsp;&nbsp; kk = kk + 1<BR>&nbsp;pt1(0) = pt(0) + 488: pt1(1) = pt(1) - 884 - (1500 * kk): pt1(2) = 0<BR>pt2(0) = pt(0) + 1662: pt2(1) = pt(1) - 890 - (1500 * kk): pt2(2) = 0<BR>pt3(0) = pt(0) + 10548: pt3(1) = pt(1) - 752 - (1500 * kk): pt3(2) = 0<BR>pt4(0) = pt(0) + 10589: pt4(1) = pt(1) - 1250 - (1500 * kk): pt4(2) = 0<BR>pt5(0) = pt(0) + 10603: pt5(1) = pt(1) - 884 - (1500 * kk): pt5(2) = 0<BR>pt6(0) = pt(0) + 25479: pt6(1) = pt(1) - 984 - (1500 * kk): pt6(2) = 0<BR>pt7(0) = pt(0) + 26467: pt7(1) = pt(1) - 965 - (1500 * kk): pt7(2) = 0<BR>Select Case (ComboBox2.Text)<BR>&nbsp;&nbsp;&nbsp; Case Is = "中文"<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("a" &amp; (m + 3)), pt1, 500)<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("b" &amp; (m + 3)), pt2, 400)<BR>Set ts = ThisDrawing.ActiveTextStyle<BR>tsna = ts.fontFile<BR>&nbsp;&nbsp;&nbsp; Set ts1 = ThisDrawing.ActiveTextStyle<BR>&nbsp;&nbsp;&nbsp; ts1.fontFile = "HZTXT"<BR>ThisDrawing.ActiveTextStyle = ts1<BR>Set textobject = ThisDrawing.ModelSpace.AddText((xlapp.Worksheets("sheet1").range("d" &amp; (m + 3)) &amp; xlapp.Worksheets("sheet1").range("e" &amp; (m + 3))), pt5, 500)<BR>ThisDrawing.Regen acActiveViewport<BR>ts.fontFile = tsna<BR>ThisDrawing.ActiveTextStyle = ts<BR>Set textobject = ThisDrawing.ModelSpace.AddText("0", pt6, 400)<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("g" &amp; (m + 3)), pt7, 550)<BR>&nbsp;&nbsp;&nbsp; Case Is = "中英文"<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("a" &amp; (m + 3)), pt1, 500)<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("b" &amp; (m + 3)), pt2, 400)<BR>Set ts = ThisDrawing.ActiveTextStyle<BR>tsna = ts.fontFile<BR>&nbsp;&nbsp;&nbsp; Set ts1 = ThisDrawing.ActiveTextStyle<BR>&nbsp;&nbsp;&nbsp; ts1.fontFile = "HZTXT"<BR>ThisDrawing.ActiveTextStyle = ts1<BR>Set textobject = ThisDrawing.ModelSpace.AddText((xlapp.Worksheets("sheet1").range("c" &amp; (m + 3)) &amp; xlapp.Worksheets("sheet1").range("d" &amp; (m + 3))), pt3, 500)<BR>ThisDrawing.Regen acActiveViewport<BR>ts.fontFile = tsna<BR>ThisDrawing.ActiveTextStyle = ts<BR>Set textobject = ThisDrawing.ModelSpace.AddText((xlapp.Worksheets("sheet1").range("e" &amp; (m + 3)) &amp; " " &amp; xlapp.Worksheets("sheet1").range("f" &amp; (m + 3))), pt4, 300)<BR>Set textobject = ThisDrawing.ModelSpace.AddText("0", pt6, 400)<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("g" &amp; (m + 3)), pt7, 550)<BR>&nbsp;&nbsp;&nbsp; End Select<BR>&nbsp;&nbsp;&nbsp;&nbsp; Next<BR>&nbsp; xlapp.activeworkbook.Save<BR>&nbsp; xlapp.Workbooks.Close<BR>&nbsp; xlapp.Quit<BR>&nbsp; Set xlsheet = Nothing<BR>&nbsp; Set xlbook = Nothing<BR>&nbsp; Set xlapp = Nothing<BR>End Sub</P>
页: [1]
查看完整版本: 循环中赋值出现的问题!