此处为VisualFreeBasic编程教程(从零开始学或VB进阶)的子章节部分,全部目录点链接。
Sub
Sub 是不返回值的过程。它们使用Declare关键字声明,并使用Sub关键字定义。声明过程引入其名称,以便可以调用它,并且过程定义列出了在调用时将执行的代码语句。A sub 简单地通过在程序中的某个地方使用它的名称。
Sub MyProcedure
Print "the body of MyProcedure"
End Sub
将产生输出:
the body of MyProcedure
请注意,只需要声明来调用该过程。该过程可以在代码中稍后定义,甚至可以在不同的源文件中进行定义。
Functions
Functions 是将值返回到调用代码中的点的过程。您可以将function 调用视为对某个表达式的评估,就像变量或对象一样。它们使用Declare关键字声明,并使用Function关键字定义。在声明结尾处指定functions 返回的值的类型。
' introduces and defines a procedure that returns an integer value
Function MyProcedure As Integer
Return 10
End Function
' calls the procedure, and stores its return value in a variable
Dim i As Integer = MyProcedure
Print i