150 likes | 287 Views
VB 中函数的调用 ( 引用传递 ). 函数定义如下 : Function Get_Hello(ByRef pval As String) As String pval = "Hello World!" End Function. 函数调用如下 : Get_Hello (p) MsgBox ("p=" + p) Dim p1 As String p2 = Get_Hello(p1) MsgBox ("p1=" + p1) Dim p3 As String Get_Hello p3
E N D
VB中函数的调用(引用传递) • 函数定义如下: • Function Get_Hello(ByRef pval As String) As String • pval = "Hello World!" • End Function
函数调用如下: • Get_Hello (p) • MsgBox ("p=" + p) • Dim p1 As String • p2 = Get_Hello(p1) • MsgBox ("p1=" + p1) • Dim p3 As String • Get_Hello p3 • MsgBox ("p3=" + p3)
调用结果如下: • p= • p1=Hello World! • p3=Hello World!
值传递 • 函数调用如下: • Function Get_Helloval(ByVal pval As String) As String • pval = "Hello World!" • End Function
函数调用如下: • Get_Helloval (p) • MsgBox ("p=" + p) • Dim p1 As String • p2 = Get_Helloval(p1) • MsgBox ("p1=" + p1) • Dim p3 As String • Get_Helloval p3 • MsgBox ("p3=" + p3)
调用结果如下: • p= • p1= • p3=
VB中过程的调用(引用传递) • 函数定义如下: • Sub Get_Hellosub(ByRef pval As String) • pval = "Hello World!" • End Sub
函数调用如下: • Get_Hellosub (p) • MsgBox ("p=" + p) • Dim p1 As String • p2 = Get_Hellosub(p1) • MsgBox ("p1=" + p1) • Dim p3 As String • Get_Hellosub p3 • MsgBox ("p3=" + p3)
调用结果如下: • p= • p3=Hello World! • 注意:以下语句错误,去掉输出如上. • p2 = Get_Hellosub(p1) • MsgBox ("p1=" + p1)
值传递 • 函数调用如下: • Sub Get_Hellovalsub(ByVal pval As String) • pval = "Hello World!" • End Sub
函数调用如下: • Get_Hellovalsub (p) • MsgBox ("p=" + p) • Dim p1 As String • ' p2 = Get_Hellosub(p1) • 'MsgBox ("p1=" + p1) • Dim p3 As String • Get_Hellovalsub p3 • MsgBox ("p3=" + p3)
调用结果如下: • p= • p3= • 注意:以下语句错误,去掉输出如上. • p2 = Get_Hellosub(p1) • MsgBox ("p1=" + p1)