循环中赋值出现的问题!
<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> <BR>For m = 1 To 30<BR> kk = kk + 1<BR> 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> <P>试试.for m=22 to 30</P>
<P>看看出现问题不?</P> <P>运行正常,包括for m=8 to 30也可以,好像这个 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> PathName = TextBox1.Text<BR> On Error Resume Next<BR> Set xlapp = GetObject(, "excel.application")<BR> If Err Then<BR> Err.Clear<BR> Set xlapp = CreateObject("excel.application")<BR> If Err Then<BR> Err.Clear<BR> MsgBox ("不能运行EXCEL,请检查是否安装了EXCEL")<BR> Exit Sub<BR> End If<BR> End If<BR> 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> Dim ts1 As AcadTextStyle<BR> 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> <BR>For m = CInt(TextBox4.Text - 1) To CInt(TextBox5.Text - 1)<BR> kk = kk + 1<BR> 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> Case Is = "中文"<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("a" & (m + 3)), pt1, 500)<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("b" & (m + 3)), pt2, 400)<BR>Set ts = ThisDrawing.ActiveTextStyle<BR>tsna = ts.fontFile<BR> Set ts1 = ThisDrawing.ActiveTextStyle<BR> ts1.fontFile = "HZTXT"<BR>ThisDrawing.ActiveTextStyle = ts1<BR>Set textobject = ThisDrawing.ModelSpace.AddText((xlapp.Worksheets("sheet1").range("d" & (m + 3)) & xlapp.Worksheets("sheet1").range("e" & (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" & (m + 3)), pt7, 550)<BR> Case Is = "中英文"<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("a" & (m + 3)), pt1, 500)<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("b" & (m + 3)), pt2, 400)<BR>Set ts = ThisDrawing.ActiveTextStyle<BR>tsna = ts.fontFile<BR> Set ts1 = ThisDrawing.ActiveTextStyle<BR> ts1.fontFile = "HZTXT"<BR>ThisDrawing.ActiveTextStyle = ts1<BR>Set textobject = ThisDrawing.ModelSpace.AddText((xlapp.Worksheets("sheet1").range("c" & (m + 3)) & xlapp.Worksheets("sheet1").range("d" & (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" & (m + 3)) & " " & xlapp.Worksheets("sheet1").range("f" & (m + 3))), pt4, 300)<BR>Set textobject = ThisDrawing.ModelSpace.AddText("0", pt6, 400)<BR>Set textobject = ThisDrawing.ModelSpace.AddText(xlapp.Worksheets("sheet1").range("g" & (m + 3)), pt7, 550)<BR> End Select<BR> Next<BR> xlapp.activeworkbook.Save<BR> xlapp.Workbooks.Close<BR> xlapp.Quit<BR> Set xlsheet = Nothing<BR> Set xlbook = Nothing<BR> Set xlapp = Nothing<BR>End Sub</P>
页:
[1]