VB 实现测量窗体上两点之间的距离

VB 实现测量窗体上两点之间的距离,第1张

Dim x1 As Single, y1 As Single, 迹者x2 As Single, y2 As Single, m As Single, n As Single, L As Single

Private Sub Form_Load()

Line1.Visible = False

End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then

    x1 = X

    y1 = Y

End If

End Sub

Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)

If Button = 1 Then

    Line1.x1 = x1

    Line1.y1 = y1

    Line1.x2 = X

    Line1.y2 = Y

    Line1.Visible = True

End If

End Sub

Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)

If 姿磨薯Button = 1 Then

    Line1.Visible = False

    x2 = X

    y2 = Y

    If m = 0 Then

        m = Me.ScaleX(Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2), 1, 3)

        MsgBox "标尺的像素长度m=" & m

    ElseIf n = 0 Then

        n = Me.ScaleX(Sqr((x2 - x1) ^ 2 + (y2 - y1) ^ 2), 1, 3)

        L = 5 * n / m

        MsgBox "两点之间的像素长度n=" & n & 游巧vbCrLf & "两点之间的标尺距离L=" & L & "mm"

        m = 0

        n = 0

        L = 0

    End If

End If

End Sub

上述代码用到的唯一一个控件是Line1

代码改为:Private Sub Form_Click()Dim a, b, c, d As StringDim sum, aver As Longa = Val(InputBox("请输入第一个数"))

b = InputBox("请输入第二个数")

c = InputBox("请输入第三个数")

d = InputBox("请输入第四个数")

sum = a + b + c + d

aver = sum / 4

Print "所输入的4个数字分别是"a, b, c, d

Print "哗芹4个数字的和为"者镇sum

Print "乱嫌毕4个数字的平均值为"averEnd Sub VB6.0下调试通过。

Option Explicit

Dim a() '定义数组

Dim i As Integer

Private Sub Command1_Click()

On Error GoTo errhandle

Dim item

For Each item In a '打印出厅腔余数组元素

Print item

Next

Exit Sub

errhandle:

MsgBox "请先给数扮滚组赋值", 48 + 0, "错误"

End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then '如果按的是回车键

ReDim Preserve a(i) '重新定义动态数圆薯组

a(i) = Val(Text1) '给数组赋值

i = i + 1

Text1 = ""

End If

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12354634.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存