Option Explicit
'这个程序需要有两个窗体Form1/Form2;
'在Form1上有一个CommandButton和一个TextBox;
'在Form2上有两个OptionButton;
'启动窗体是Form1;
'以下代码在Form1;
Private Sub Command1_Click()    Form2.Show vbModal
    Text1.Text = "Option " & CStr(Form2.Chose) & " Chosed"End Sub
Option Explicit
'以下代码在Form2;
Dim iChose As Integer
Public Property Get Chose() As Integer
    Chose = iChose
End Property
Private Sub Command1_Click()
    Unload Me
End Sub
Private Sub Option1_Click()
    iChose = 1
End SubPrivate Sub Option2_Click()
    iChose = 2
End Sub

解决方案 »

  1.   

    把窗体中加入public定义,将变量作为窗体属性,可以随意调用了
      

  2.   

    以下代码粘在Form1中
    '        Tip:其实很多问题在以前的贴子里都有过很好的解答,我建议大家提问前先搜一下以前的贴子,会节约很多时间的.
    '
    '     Author:吴文智
    '       Date:2001-11-20
    'Description:要试用本例请在工程中填加Form1,上有一个按钮
    '            然后在代码窗体中粘贴如下代码
    '            Good luck!Option ExplicitPrivate Sub Command1_Click()
        Me.Print GetInput("试试")
    End Sub以下代码粘在Form2中
    '        Tip:其实很多问题在以前的贴子里都有过很好的解答,我建议大家提问前先搜一下以前的贴子,会节约很多时间的.
    '
    '     Author:吴文智
    '       Date:2001-11-20
    'Description:要试用本例请在工程中再填加Form2,上有两个按钮和一个文本框,Form2就是用来输入的窗体了
    '            然后在代码窗体中粘贴如下代码
    '            Good luck!
    Option ExplicitPublic blnConfirm As BooleanPrivate Sub Command1_Click()
        blnConfirm = True
        Me.Hide
    End SubPrivate Sub Command2_Click()
        blnConfirm = False
        Me.Hide
    End Sub
    Private Sub Form_Load()
        blnConfirm = False
        Command1.Caption = "确定"
        Command2.Caption = "退出"
    End Sub
    以下代码粘在模块中
    '        Tip:其实很多问题在以前的贴子里都有过很好的解答,我建议大家提问前先搜一下以前的贴子,会节约很多时间的.
    '
    '     Author:吴文智
    '       Date:2001-11-20
    'Description:要试用本例请在工程中再填加一个模块,用来存放此函数
    '            然后在代码窗体中粘贴如下代码
    '            Good luck!
    Option ExplicitPublic Function GetInput(ByVal Caption As String) As String
        Dim frmInput As Form2
        
        Set frmInput = New Form2
        With frmInput
            .Caption = Caption
            .Show vbModal
            If .blnConfirm Then
                GetInput = .Text1.Text
            Else
                '如果返回"阿木,uguess等兄弟们来喝茶了吗?",就说明用户按了取消
                GetInput = "阿木,uguess等兄弟们来喝茶了吗?"
            End If
        End With
    End Function