这是我的程序,目前问题是点击"输入完毕"按钮后,画不出线,实在不知道哪出了问题,请帮我看看吧,先谢过了啊!
Option Explicit Private Type POINTAPI x As Double y As Double z As Double End Type Dim p() As POINTAPI
Private Sub UserForm_Initialize() ReDim p(0) As POINTAPI End Sub
Private Sub CommandButton1_Click() ' 确保文本框的值不为空 Dim item As MSForms.Control For Each item In UserForm1.Controls If TypeOf item Is TextBox Then If Len(item.Text) = 0 Then MsgBox "请输入定位点!", vbCritical Exit Sub End If End If Next item '存点 If p(0).x <> 0 Then ReDim Preserve p(UBound(p) + 1)
p(UBound(p)).x = Val(TextBox1.Text) p(UBound(p)).y = Val(TextBox2.Text) p(UBound(p)).z = Val(TextBox3.Text)
TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = ""
End Sub
Private Sub CommandButton2_Click() ' 确保文本框的值不为空 Dim item As MSForms.Control For Each item In UserForm1.Controls If TypeOf item Is TextBox Then If Len(item.Text) = 0 Then MsgBox "请输入定位点!", vbCritical Exit Sub End If End If Next item ' 绘制直线 Dim i As Integer Dim FormPnt(0 To 2) As Double Dim ToPnt(0 To 2) As Double For i = 2 To UBound(p) FormPnt(0) = p(i - 1).x FormPnt(1) = p(i - 1).y FormPnt(2) = p(i - 1).z ToPnt(0) = p(i).x ToPnt(1) = p(i).y ToPnt(2) = p(i).z ThisDrawing.ModelSpace.AddLine FormPnt, ToPnt Next End '结束程序 End Sub
|