一.在窗体内总定义公共变量进行传递(常用)
二.在窗体内部定义函数进行传递
建二个窗体 Form1 Text1 Command1
代码: Option Explicit
Private Sub Command1_Click() Dim strTemp As String strTemp = Form2.GetText(Text1.Text) Text1.Text = strTemp End Sub
Private Sub Form_Load() Text1.Text = "我是第一个窗体的文本" End Sub
Form2 Text1 Text2 Command1
代码: Option Explicit
Dim mstrTemp As String
Private Sub Command1_Click() Unload Me End Sub
Private Sub Form_Load() Text1.Text = "我是第二个窗体的文本" Text2.Text = "" Text2.Text = mstrTemp End Sub
Public Function GetText(ByVal strText As String) As String mstrTemp = strText Me.Show vbModal GetText = Text1.Text Unload Me End Function 
|