public function x( ) as String ... if ... then x = "s" else x = "ss" end ifend function
public function x( ) as String ... if ... then x = "s" else x = "ss" end ifend function
与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
你的运行结果是正确的:public function x( ) as boolean if 1<2 then
x=false
else
x=true
end ifend function
你应在函数内对x赋值
如
public function x( ) as boolean ... if ... then
x = true
else
x = false
end ifend function
那如果想函数有一个返回值要怎样做(假如要返回一个String类型的值 s)?记得在C++里面是先把函数的类型定义了CString类型,然后在函数里面定义一个CString s,最后再return s,但在VB中应怎样做?
... if ... then
x = "s"
else
x = "ss"
end ifend function
... if ... then
x = "s"
else
x = "ss"
end ifend function
函数名=要返回的值在你的例子中用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