Lotus Symphony 1.2


CBool 函數 [執行時期]

將字串比較或數字比較的結果轉換成布林表示式,或者將單一數值表示式轉換成布林表示式。

語法:

CBool (Expression1 {= | <> | < | > | <= | >=} Expression2) or CBool (Number)

回覆值:

Bool

參數:

Expression1、Expression2:要比較的任意字串表示式或數值表示式。如果表示式相符,CBool 函數將傳回 True (真),否則將傳回 False (假)

Number:要轉換的任意數值表示式。如果表示式等於 0,則傳回 False (假),否則傳回 True (真)

下面的範例將使用 CBool 函數演算 Instr 函數傳回的值。此函數會檢查使用者輸入的句子中是否含有 "and" 這個字。

錯誤代碼

5 無效的程序呼叫

範例:

Sub ExampleCBool

Dim sText As String

sText = InputBox("Please enter a short sentence:")

REM 檢驗句子中是否含有 ;and+ 這個字。

REM 未使用下面的指令行

REM If Instr(Input, "and")<>0 Then...

REM CBool 函數使用方式如下:

If CBool(Instr(sText, "and")) Then

MsgBox "The word ;and+ appears in the sentence you entered!"

EndIf

End Sub


其他文件 | 商標