public function x( ) as boolean    if 1<2 then
        x=false
    else
        x=true
    end ifend function

解决方案 »

  1.   


    你的运行结果是正确的:public function x( ) as boolean    if 1<2 then
            x=false
        else
            x=true
        end ifend function
      

  2.   

    定义布尔值默认为false
    你应在函数内对x赋值

    public function x( ) as boolean    ...       if ... then
            x = true
        else
            x = false
        end ifend function
      

  3.   


    那如果想函数有一个返回值要怎样做(假如要返回一个String类型的值 s)?记得在C++里面是先把函数的类型定义了CString类型,然后在函数里面定义一个CString s,最后再return s,但在VB中应怎样做?
      

  4.   

    public function x( ) as String
        ...       if ... then
            x = "s"
        else
            x = "ss"
        end ifend function
      

  5.   

    public function x( ) as String
        ...       if ... then
            x = "s"
        else
            x = "ss"
        end ifend function
      

  6.   

    与return s功能对应的格式是:
    函数名=要返回的值在你的例子中用x=True/False。另外,下列代码中的If判断条件写得不规范。
    if b=true then
       msgbox "It's true"
    else
       msgbox "It's false"
    endif改成如下格式更好些。
    If b Then
       Msgbox "It's true"
    Else
       Msgbox "It's false"
    End If