使用 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 時,會傳回文字字串值「You won!」,否則會傳回文字字串值「Sorry, try again.」。
上述的公式可以寫成如下的 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