formula 变量的用法类似于在 Visual Basic 中编写名为 formula 的函数。
请考察下面的 Basic 语法公式:
Rem A formula that returns a String value Rem The function Rnd returns a random number Rem between 0 and 1 If Rnd > 0.9 Then formula = "You won!" Else formula = "Sorry, try again." End If
若 Rnd 返回的随机数大于 0.9,以上的公式返回文本串值“您赢了!”,否则返回文本串值“对不起,请再试一次。”。
以上公式可以编写成 Visual Basic 函数,如下所示:
Rem The following code is in Visual Basic Function formula() If Rnd > 0.9 Then formula = "You won!" Else formula = "Sorry, try again." End If End Function