⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmbyval.frm

📁 Visual Basic 6 大学教程的代码
💻 FRM
字号:
VERSION 5.00
Begin VB.Form frmByVal 
   Caption         =   "Fig. 6.12: Value versus Reference"
   ClientHeight    =   4800
   ClientLeft      =   2865
   ClientTop       =   795
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   4800
   ScaleWidth      =   4680
   Begin VB.CommandButton cmdPrint 
      Caption         =   "Print"
      Height          =   495
      Left            =   3360
      TabIndex        =   0
      Top             =   2160
      Width           =   1215
   End
End
Attribute VB_Name = "frmByVal"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 6.12
' Demonstrating passing arguments by value and by reference
Option Explicit           ' General declaration

Private Sub cmdPrint_Click()
   Dim a As Integer

   Call Cls
   a = 1    ' Initialize a
   
   ' Call CallByValue1
   Print "Value of a before CallByValue1 is " & a
   Call CallByValue1(a)  ' ByVal in parameter list
   Print "Value of a after CallByValue1 is " & a
   Print
   
   ' Call CallByValue2
   Print "Value of a before CallByValue2 is " & a
   Call CallByValue2((a)) ' Parentheses for call-by-value
   Print "Value of a after CallByValue2 is " & a
   Print
   
   ' Call CallByValue3
   Print "Value of a before CallByValue3 is " & a
   Call CallByValue3((a)) ' Parentheses for call-by-value
   Print "Value of a after CallByValue3 is " & a
   Print
   
   ' Call CallByReference
   Print "Value of a before CallByReference is " & a
   Call CallByReference(a) ' Default call-by-reference
   Print "Value of a after CallByReference is " & a
   Print
   
   ' Call CallByReference2
   Print "Value of a before CallByReference2 is " & a
   Call CallByReference2(a) ' Default call-by-reference
   Print "Value of a after CallByReference2 is " & a
End Sub

Private Sub CallByValue1(ByVal x As Integer)
   Print "Initial value of x in CallByValue1 is " & x
   x = x * 3    ' Modifying x does not modify caller's a
   Print "Last value of x in CallByValue1 is " & x
End Sub

Private Sub CallByValue2(y As Integer)
   Print "Initial value of y in CallByValue2 is " & y
   y = y * 4    ' Modifying y does not modify caller's a
   Print "Last value of y in CallByValue2 is " & y
End Sub

' Parentheses around argument in call and ByVal in header
Private Sub CallByValue3(ByVal z As Integer)
   Print "Initial value of z in CallByValue3 is " & z
   z = z * 5    ' Modifying z does not modify caller's a
   Print "Last value of z in CallByValue3 is " & z
End Sub

' Implicit call-by-reference
Private Sub CallByReference(r As Integer)
   Print "Initial value of r in CallByReference is " & r
   r = r * 9    ' Modifying r does modify caller's a
   Print "Last value of r in CallByReference is " & r
End Sub

' Explicit call-by-reference using ByRef in the header
Private Sub CallByReference2(ByRef r2 As Integer)
   Print "Initial value of r2 in CallByReference2 is " & r2
   r2 = r2 * 2  ' Modifying r does modify caller's a
   Print "Last value of r2 in CallByReference2 is " & r2
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -