emmacui 发表于 2008-3-29 21:16:00

[求助]跪求好心人帮帮我这个小菜鸟,看看那里出错了

<p>Public Function AddLineXY(ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double) As AcadLine</p><p>Dim pt1(2) As Double<br/>Dim pt2(2) As Double<br/>pt1(0) = x1: pt1(1) = y1: pt1(2) = 0<br/>pt2(0) = x2: pt2(1) = y2: pt2(2) = 0<br/>For i = 1 To 49<br/>&nbsp; x1 = MSFlexGrid1.TextMatrix(i, 1)<br/>&nbsp; y1 = MSFlexGrid1.TextMatrix(i, 2)<br/>&nbsp; x2 = MSFlexGrid1.TextMatrix(i + 1, 1)<br/>&nbsp; y2 = MSFlexGrid1.TextMatrix(i + 1, 1)<br/>Next i<br/>&nbsp; <br/>Set AddLineXY = AddLine(pt1, pt2)</p><p></p><p>End Function</p><p></p><p><br/>Public Sub TestLine()<br/>&nbsp;&nbsp;&nbsp; Dim ptSt(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim ptEn(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; ptSt(0) = 100: ptSt(1) = 100: ptSt(2) = 0<br/>&nbsp;&nbsp;&nbsp; ptEn(0) = 150: ptEn(1) = 100: ptEn(2) = 0</p><p>&nbsp;&nbsp;&nbsp; '(1)<br/>&nbsp;&nbsp;&nbsp; AddLine ptSt, ptEn<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '(2)<br/>&nbsp;&nbsp;&nbsp; AddLineXY 100, 120, 150, 120<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '(3)<br/>&nbsp;&nbsp;&nbsp; AddLineReXY ptSt, 50, 50<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; '(4)<br/>&nbsp;&nbsp;&nbsp; AddLineReAL ptSt, 3, 50<br/>End Sub</p><p>Private Sub Command1_Click()<br/>On Error Resume Next<br/>Set AcadApp = GetObject(, "AutoCAD.Application")<br/>If Err Then<br/>Err.Clear<br/>Set AcadApp = CreateObject("AutoCAD.Application")<br/>If Err Then<br/>MsgBox Err.Description<br/>Exit Sub<br/>End If<br/>End If<br/>AcadApp.WindowTop = 0<br/>AcadApp.WindowLeft = 400<br/>AcadApp.Width = 600<br/>AcadApp.Height = 800<br/>AcadApp.Visible = True<br/>AcadApp.Documents.Add<br/>Set AcadDoc = AcadApp.ActiveDocument<br/>AcadDoc.WindowState = acMax<br/>End Sub</p><p>Private Sub Form_Load()<br/>Text1.Move -10000, -10000, 1, 1<br/>MSFlexGrid1.Rows = 50: MSFlexGrid1.Cols = 3<br/>s = Array("500", "1300", "1300")<br/>y = Array("点号", "X坐标", "Y坐标")<br/>For i = 0 To 2<br/>&nbsp; MSFlexGrid1.ColWidth(i) = s(i): MSFlexGrid1.TextMatrix(0, i) = y(i)<br/>Next i<br/>For i = 1 To 49<br/>&nbsp;&nbsp; MSFlexGrid1.TextMatrix(i, 0) = i<br/>Next i<br/>End Sub</p><p>Private Sub MSFlexGrid1_EnterCell()<br/>MSFlexGrid1.CellBackColor = vbBlue<br/>MSFlexGrid1.CellForeColor = vbWhite<br/>Text1.Text = MSFlexGrid1.Text<br/>Text1.SelStart = 0<br/>Text1.SelLength = Len(Text1.Text)<br/>End Sub</p><p>Private Sub MSFlexGrid1_LeaveCell()<br/>MSFlexGrid1.CellBackColor = vbWhite<br/>MSFlexGrid1.CellForeColor = vbBlue<br/>End Sub</p><p>Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)<br/>Text1.SetFocus<br/>End Sub</p><p>Private Sub Text1_Change()<br/>MSFlexGrid1.Text = Text1.Text<br/>End Sub</p><p>Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)<br/>Select Case KeyCode<br/>Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown<br/>KeyCode = 0<br/>End Select<br/>End Sub</p><p>我是用一个表格控件输入XY坐标 然后画出直线,可是CAD打开后连个点都看不到,狂郁闷中,我哪里弄错了?求好心的强人们指点?</p><p>我是用VB编的</p>

azjmjsj 发表于 2008-3-30 16:35:00

<p>帮你改了一下,已测试可成功绘制直线</p><p>Private Sub Command1_Click()<br/>On Error Resume Next<br/>Set Acadapp = GetObject(, "AutoCAD.Application")<br/>If Err Then<br/>Err.Clear<br/>Set Acadapp = CreateObject("AutoCAD.Application")<br/>If Err Then<br/>MsgBox Err.Description<br/>Exit Sub<br/>End If<br/>End If<br/>Acadapp.WindowTop = 0<br/>Acadapp.WindowLeft = 400<br/>Acadapp.Width = 600<br/>Acadapp.Height = 800<br/>Acadapp.Visible = True<br/>Acadapp.Documents.Add<br/>Set AcadDoc = Acadapp.ActiveDocument<br/>AcadDoc.WindowState = acMax</p><p>&nbsp;&nbsp;&nbsp; Dim ptSt(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim ptEn(0 To 2) As Double<br/>&nbsp;&nbsp;&nbsp; ptSt(0) = 100: ptSt(1) = 100: ptSt(2) = 0<br/>&nbsp;&nbsp;&nbsp; ptEn(0) = 150: ptEn(1) = 100: ptEn(2) = 0<br/>&nbsp;&nbsp;&nbsp; AcadDoc.ModelSpace.AddLine ptSt, ptEn<br/>&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp; Dim pt1(2) As Double<br/>&nbsp;&nbsp;&nbsp; Dim pt2(2) As Double<br/>&nbsp;&nbsp;&nbsp; For i = 1 To&nbsp;49<br/>&nbsp;&nbsp;&nbsp; x1 = MSFlexGrid1.TextMatrix(i, 1)<br/>&nbsp;&nbsp;&nbsp; y1 = MSFlexGrid1.TextMatrix(i, 2)<br/>&nbsp;&nbsp;&nbsp; x2 = MSFlexGrid1.TextMatrix(i + 1, 1)<br/>&nbsp;&nbsp;&nbsp; y2 = MSFlexGrid1.TextMatrix(i + 1, 2)<br/>&nbsp;&nbsp;&nbsp; pt1(0) = x1: pt1(1) = y1: pt1(2) = 0<br/>&nbsp;&nbsp;&nbsp; pt2(0) = x2: pt2(1) = y2: pt2(2) = 0<br/>&nbsp;&nbsp;&nbsp; AcadDoc.ModelSpace.AddLine pt1, pt2<br/>&nbsp;&nbsp;&nbsp; Next i<br/>&nbsp;&nbsp;&nbsp; <br/>Acadapp.zoomextents<br/>End Sub</p><p>*************************************************************</p><p>西北凡人-----http://www.abofanyi.com/blog</p>

emmacui 发表于 2008-3-30 21:48:00

<p>非常感谢!!!你人真是太好了 </p>
页: [1]
查看完整版本: [求助]跪求好心人帮帮我这个小菜鸟,看看那里出错了