当前位置: 高中信息技术 / 综合题
  • 1. (2019高二下·嘉兴期末) 在平面坐标系中,A点坐标为(25,35),编写VB程序,计算一组给定点中,距离A点的最小距离。在文本框Text1中依次输入一组给定的坐标值,如3个点的坐标(10,15)、(45,18)、(32,40)输入示例如图所示,坐标值以逗号分隔、逗号结尾,单击“计算”按钮Command1后,程序运行结果显示在Label3中。

    实现上述功能的VB程序如下,请在划线处填入合适代码。

    Private Sub Command1_Click()

      Dim i As Integer, n As Integer

      Dim x As Single, y As Single, x1 As Single, y1 As Single

      Dim d As Single, min As Single

      Dim s As String, t As String

      s = Text1.Text:   x = 25: y = 35                       'A点坐标

      n = 0: min = -1: t = ""

      For i = 1 To

        If Mid(s, i, 1) = "," Then

          n = n + 1

          If Then

             x1 = Val(t)

          Else

             y1 = Val(t)

             d =

             If min = -1 Then min = d

             If d < min Then min = d

          End If

          t = ""

        Else

          t = t + Mid(s, i, 1)

        End If

      Next i

      Label3.Caption = Str(min)

    End Sub

微信扫码预览、分享更方便