在VBA CAD二次开发中,sub语句里能嵌套function函数吗?运行程序时提醒我没有End sub 呢?下边是我的程序 10
PrivateSubCommandButton1_Click()PrivateFunctionAddLWPlineArc(ByValptCenAsVariant,ByVa...
Private Sub CommandButton1_Click()Private Function AddLWPlineArc(ByVal ptCen As Variant, ByVal radius As Double, ByVal angleSt As Double, ByVal angleEn As Double, ByVal width As Double) As AcadLWPolyline
Dim objPline As AcadLWPolyline
Dim ptCen(0 To 1) As Variant
Dim radius As Double
Dim angleSt As Double
Dim angleEn As Double
Dim width As Double
ptCen(0) = Val(TextBox8.Text)
ptCen(1) = Val(TextBox7.Text)
radius = Val(TextBox3.Text)
angleSt = Val(TextBox4.Text)
angleEn = Val(TextBox5.Text)
wdth = Val(TextBox6.Text)
Dim ptArr(0 To 3) As Double
ptArr(0) = ptCen(0) + radius * Cos(angleSt)
ptArr(1) = ptCen(1) + radius * Sin(angleSt)
ptArr(2) = ptCen(0) + radius * Cos(angleEn)
ptArr(3) = ptCen(1) + radius * Sin(angleEn)
Set objPline = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptArr)
objPline.ConstantWidth = width
If angleEn < angleSt Then
angleSt = angleSt - 8 * Ant(1)
End If
objPline.SetBulge 0, Tan((angleEn - angleSt) / 4)
objPline.SetBulge 1, 0
objPline.Update
Set AddLWPlineArc = objPline
End Function
要加上end sub 时发现end function只能在最后一行,end sub加哪啊 展开
Dim objPline As AcadLWPolyline
Dim ptCen(0 To 1) As Variant
Dim radius As Double
Dim angleSt As Double
Dim angleEn As Double
Dim width As Double
ptCen(0) = Val(TextBox8.Text)
ptCen(1) = Val(TextBox7.Text)
radius = Val(TextBox3.Text)
angleSt = Val(TextBox4.Text)
angleEn = Val(TextBox5.Text)
wdth = Val(TextBox6.Text)
Dim ptArr(0 To 3) As Double
ptArr(0) = ptCen(0) + radius * Cos(angleSt)
ptArr(1) = ptCen(1) + radius * Sin(angleSt)
ptArr(2) = ptCen(0) + radius * Cos(angleEn)
ptArr(3) = ptCen(1) + radius * Sin(angleEn)
Set objPline = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptArr)
objPline.ConstantWidth = width
If angleEn < angleSt Then
angleSt = angleSt - 8 * Ant(1)
End If
objPline.SetBulge 0, Tan((angleEn - angleSt) / 4)
objPline.SetBulge 1, 0
objPline.Update
Set AddLWPlineArc = objPline
End Function
要加上end sub 时发现end function只能在最后一行,end sub加哪啊 展开
2个回答
展开全部
不能嵌套,只能引用。可以把函数写在过程下面,然后在SUB过程中使用此函数。
更多追问追答
追问
能不能帮我改改这个程序,写在过程下面是什么意思,初学者,求指导
追答
你这个要函数作什么,不需要函数啊,程序改为:
Private Sub CommandButton1_Click()
Dim objPline As AcadLWPolyline
Dim ptCen(0 To 1) As Variant
Dim radius As Double
Dim angleSt As Double
Dim angleEn As Double
Dim width As Double
ptCen(0) = Val(TextBox8.Text)
ptCen(1) = Val(TextBox7.Text)
radius = Val(TextBox3.Text)
angleSt = Val(TextBox4.Text)
angleEn = Val(TextBox5.Text)
width = Val(TextBox6.Text)
Dim ptArr(0 To 3) As Double
ptArr(0) = ptCen(0) + radius * Cos(angleSt)
ptArr(1) = ptCen(1) + radius * Sin(angleSt)
ptArr(2) = ptCen(0) + radius * Cos(angleEn)
ptArr(3) = ptCen(1) + radius * Sin(angleEn)
Set objPline = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptArr)
objPline.ConstantWidth = width
If angleEn < angleSt Then
angleSt = angleSt - 8 * Ant(1)
End If
objPline.SetBulge 0, Tan((angleEn - angleSt) / 4)
objPline.SetBulge 1, 0
objPline.Update
End sub
试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询