VB调用CAD画图问题
有一个调用VB画图的程序,可是画出的不是多边形,而是有很多直线会交叉如何解决,望大虾们指点。PrivateSubCommand1_Click()DimXLAPPAsExc...
有一个调用VB画图的程序,可是画出的不是多边形,而是有很多直线会交叉 如何解决,望大虾们指点。Private Sub Command1_Click()
Dim XLAPP As Excel.Application
Set XLAPP = New Excel.Application
Set XLAPP = CreateObject("excel.application")
Dim BOOK_JSMJ As Excel.Workbook
Dim SHEET_JSMJ As Excel.Worksheet
Dim X(50), Y(50) As Double
Set BOOK_JSMJ = XLAPP.Workbooks.Open("E:\张三\计算多边形面积")
Set SHEET_JSMJ = BOOK_JSMJ.Worksheets("sheet1")
SHEET_JSMJ.Activate
Dim n As Integer
Dim P1(0 To 2) As Double
Dim P2(0 To 2) As Double
Dim MJ, ZC As Double
'--------------------------------
Dim myDoc As AcadDocument
Dim myMos As AcadModelSpace
Dim myPas As AcadPaperSpace
Dim LINE As AcadLine
Dim TEXT As AcadText
Dim myacadApp As AcadApplication
Set myacadApp = New AcadApplication
Set myacadApp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set myacadApp = CreateObject("AutoCAD.Application")
If Err Then
MsgBox Err.Description
Exit Sub
End If
End If
Set myDoc = myacadApp.ActiveDocument
myacadApp.Visible = True
n = Val(Form1.Text1(0).TEXT)
For j = 1 To n + 1 '给各顶点赋值
X(j) = SHEET_JSMJ.Cells(j + 1, 2)
Y(j) = SHEET_JSMJ.Cells(j + 1, 3)
Next
X(n + 1) = X(1): Y(n + 1) = Y(1) '多边形必须是封闭的
MJ = 0: ZC = 0 '循环起点值为零
For j = 1 To 5 '计算多边形面积和周长
MJ = MJ + X(j) * Y(j + 1) - Y(j) * X(j + 1)
ZC = ZC + Sqr((X(j) - X(j + 1)) * (X(j) - X(j + 1)) + _
(Y(j) - Y(j + 1)) * (Y(j) - Y(j + 1)))
Next
MJ = MJ / 2
MJ = Int(MJ * 1000 + 0.5) / 1000
ZC = Int(ZC * 1000 + 0.5) / 1000
Form1.Text1(0) = n
Form1.Text1(1) = MJ
Form1.Text1(2) = ZC
If Form1.Check1.Value = 1 Then '在CAD绘图多边形
For j = 1 To n
P1(0) = Int(X(j))
P1(1) = Int(Y(j))
P1(2) = Int(0)
P2(0) = Int(X(j + 1))
P2(1) = Int(Y(j + 1))
P2(2) = Int(0)
Set LINE = myDoc.ModelSpace.AddLine(P1, P2)
ZoomAll
Next
P2(0) = (X(2) + X(3)) / 2: P2(1) = X(2) - 4
Set TEXT = myDoc.ModelSpace.AddText("S=" & MJ, P2, 3) '标注面积
P2(1) = P2(1) - 4:
Set TEXT = myDoc.ModelSpace.AddText("L=" & ZC, P2, 3) '标注周长
ZoomAll
End If
End Sub
Sub jisuan()
End Sub
老师提示说只需要稍微修改下就可以了,具体位置大概在n = Val(Form1.Text1(0).TEXT)
For j = 1 To n + 1 '给各顶点赋值
之后的内容。
请求大神帮忙啊
具体的EXCEL文件内容
坐标 X Y
D1 20 20
D2 40 20
D3 20 40
D4 40 40
D5 30 50
最好能在此程序上直接修改,谢谢了,回答对的再追加50分 展开
Dim XLAPP As Excel.Application
Set XLAPP = New Excel.Application
Set XLAPP = CreateObject("excel.application")
Dim BOOK_JSMJ As Excel.Workbook
Dim SHEET_JSMJ As Excel.Worksheet
Dim X(50), Y(50) As Double
Set BOOK_JSMJ = XLAPP.Workbooks.Open("E:\张三\计算多边形面积")
Set SHEET_JSMJ = BOOK_JSMJ.Worksheets("sheet1")
SHEET_JSMJ.Activate
Dim n As Integer
Dim P1(0 To 2) As Double
Dim P2(0 To 2) As Double
Dim MJ, ZC As Double
'--------------------------------
Dim myDoc As AcadDocument
Dim myMos As AcadModelSpace
Dim myPas As AcadPaperSpace
Dim LINE As AcadLine
Dim TEXT As AcadText
Dim myacadApp As AcadApplication
Set myacadApp = New AcadApplication
Set myacadApp = GetObject(, "AutoCAD.Application")
If Err Then
Err.Clear
Set myacadApp = CreateObject("AutoCAD.Application")
If Err Then
MsgBox Err.Description
Exit Sub
End If
End If
Set myDoc = myacadApp.ActiveDocument
myacadApp.Visible = True
n = Val(Form1.Text1(0).TEXT)
For j = 1 To n + 1 '给各顶点赋值
X(j) = SHEET_JSMJ.Cells(j + 1, 2)
Y(j) = SHEET_JSMJ.Cells(j + 1, 3)
Next
X(n + 1) = X(1): Y(n + 1) = Y(1) '多边形必须是封闭的
MJ = 0: ZC = 0 '循环起点值为零
For j = 1 To 5 '计算多边形面积和周长
MJ = MJ + X(j) * Y(j + 1) - Y(j) * X(j + 1)
ZC = ZC + Sqr((X(j) - X(j + 1)) * (X(j) - X(j + 1)) + _
(Y(j) - Y(j + 1)) * (Y(j) - Y(j + 1)))
Next
MJ = MJ / 2
MJ = Int(MJ * 1000 + 0.5) / 1000
ZC = Int(ZC * 1000 + 0.5) / 1000
Form1.Text1(0) = n
Form1.Text1(1) = MJ
Form1.Text1(2) = ZC
If Form1.Check1.Value = 1 Then '在CAD绘图多边形
For j = 1 To n
P1(0) = Int(X(j))
P1(1) = Int(Y(j))
P1(2) = Int(0)
P2(0) = Int(X(j + 1))
P2(1) = Int(Y(j + 1))
P2(2) = Int(0)
Set LINE = myDoc.ModelSpace.AddLine(P1, P2)
ZoomAll
Next
P2(0) = (X(2) + X(3)) / 2: P2(1) = X(2) - 4
Set TEXT = myDoc.ModelSpace.AddText("S=" & MJ, P2, 3) '标注面积
P2(1) = P2(1) - 4:
Set TEXT = myDoc.ModelSpace.AddText("L=" & ZC, P2, 3) '标注周长
ZoomAll
End If
End Sub
Sub jisuan()
End Sub
老师提示说只需要稍微修改下就可以了,具体位置大概在n = Val(Form1.Text1(0).TEXT)
For j = 1 To n + 1 '给各顶点赋值
之后的内容。
请求大神帮忙啊
具体的EXCEL文件内容
坐标 X Y
D1 20 20
D2 40 20
D3 20 40
D4 40 40
D5 30 50
最好能在此程序上直接修改,谢谢了,回答对的再追加50分 展开
4个回答
展开全部
你没有按多边形各顶点的顺序依次给出坐标,程序画出来的当然会交叉,你用的是VB 什么版本的,VB 6.0程序无法执行,显示的都是错误
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用Thgis软件,再复杂的图形都能轻松、快捷、精确地绘制,面积自动生成。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2010-12-13
展开全部
相关代码已发,请速分.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询