在VB里,怎么像在C语言定义自己函数?格式是什么?比如说比较两个数的大小,返回大数,如下:
       Function max(a As Double, b As Double)
                        If (a < b) Then
下一步怎么办?怎么返回值?

解决方案 »

  1.   

    function max(a as variant,b as variant)as variant
        if isnumeric(a) and isnumeric(b) then
             max=iif(a<b,b,a)
        elseif typename(a)="String" and typename(b)="String" then
             dim i as integer
             i=1 
             do while i<=len(a) or i<=len(b)
                  if mid(a,i,1)<mid(b,i,1) then
                          max=b
                          exit function
                  elseif mid(a,i,1) >mid(b,i,1) then
                          max=a
                          exit function
                  esleif mid(a,i,1) =mid(b,i,1) then
                          i=i+1
                  end if
               loop
               if i=len(a) and i<len(b) then
                   max=b
               elseif i=len(b) and i<len(a) tehn
                   max=a
               elseif i=len(a) and i=len(b) then
                   max=a
               end if
    end function
      

  2.   


    Function max(byref a As Double,byref b As Double)
      dim temp as double
      If (a < b) Then
           temp=a
           a=b
           b=temp
      end if
    end function
      

  3.   

    public function 函数名(参数列表)
    函数体
    end function
      

  4.   

    Function max(a As Double, b As Double) As Double
      If (a < b) Then
          max = b
      Else
          max = a
      End If
    End Function