1 / 15

VB 中函数的调用 ( 引用传递 )

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

Download Presentation

VB 中函数的调用 ( 引用传递 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. VB中函数的调用(引用传递) • 函数定义如下: • Function Get_Hello(ByRef pval As String) As String • pval = "Hello World!" • End Function

  2. 函数调用如下: • 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)

  3. 调用结果如下: • p= • p1=Hello World! • p3=Hello World!

  4. 值传递 • 函数调用如下: • Function Get_Helloval(ByVal pval As String) As String • pval = "Hello World!" • End Function

  5. 函数调用如下: • 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)

  6. 调用结果如下: • p= • p1= • p3=

  7. VB中过程的调用(引用传递) • 函数定义如下: • Sub Get_Hellosub(ByRef pval As String) • pval = "Hello World!" • End Sub

  8. 函数调用如下: • 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)

  9. 调用结果如下: • p= • p3=Hello World! • 注意:以下语句错误,去掉输出如上. • p2 = Get_Hellosub(p1) • MsgBox ("p1=" + p1)

  10. 值传递 • 函数调用如下: • Sub Get_Hellovalsub(ByVal pval As String) • pval = "Hello World!" • End Sub

  11. 函数调用如下: • 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)

  12. 调用结果如下: • p= • p3= • 注意:以下语句错误,去掉输出如上. • p2 = Get_Hellosub(p1) • MsgBox ("p1=" + p1)

More Related