none
关于 SUB过程的调用 RRS feed

  • 问题

  • 我是刚学习VB,想在下个事件中调用SUB这个过程,通过窗口输出x,y求S,T值。调用语句怎么写呢?

     Sub caclute_st(ByVal Xa As Double, ByVal Ya As Double, ByVal Xb As Double, ByVal Yb As Double, ByVal S As Double, ByVal T As Double)
            Dim deltaX As Double, deltaY As Double
            Const PI = 3.1415926
            deltaX = Xb - Xa
            deltaY = Yb - Ya
            S = Math.Sqrt(deltaX ^ 2 + deltaY ^ 2)
            If deltaX = 0 Then
                T = Math.Sign(deltaX) * 90
            Else
                T = Math.Atan(deltaY / deltaX) / PI * 180
                If deltaX < 0 Then
                    T = dms(T + 180)
                    Exit Sub
                End If
            End If
            T = dms(T - Int(T / 360) * 360)

    End Sub

    2010年4月15日 3:07

答案

  • Dim Xa As Double, Ya As Double, Xb As Double, Yb As Double

        Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
            Xa = e.X
            Ya = e.Y
        End Sub

        Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp

            Xb = e.X
            Yb = e.Y

            Dim S As Double, T As Double

            caclute_st(Xa, Ya, Xb, Yb, S, T)
        End Sub

     

    ByVal S As Double, ByVal T As Double,没法返回值,改成byref


    http://feiyun0112.cnblogs.com/
    2010年4月15日 3:27
    版主