Form的中加一个Public变量,就可以通过Form名.变量名访问

解决方案 »

  1.   

    在form1中 public i as integer
    然后在form2中可以用form1.i来引用
      

  2.   

    比如:在form1中  form2.var1
      

  3.   

    上面的几位都说了工程1.vbpType=Exe
    Form=Form1.frm
    Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\..\SYSTEM\STDOLE2.TLB#OLE Automation
    Form=Form2.frm
    Startup="Form1"
    Command32=""
    Name="工程1"
    HelpContextID="0"
    CompatibleMode="0"
    MajorVer=1
    MinorVer=0
    RevisionVer=0
    AutoIncrementVer=0
    ServerSupportFiles=0
    CompilationType=0
    OptimizationType=0
    FavorPentiumPro(tm)=0
    CodeViewDebugInfo=0
    NoAliasing=0
    BoundsCheck=0
    OverflowCheck=0
    FlPointCheck=0
    FDIVCheck=0
    UnroundedFP=0
    StartMode=0
    Unattended=0
    ThreadPerObject=0
    MaxNumberOfThreads=1Form1.frmVERSION 5.00
    Begin VB.Form Form1 
       Caption         =   "Form1"
       ClientHeight    =   3195
       ClientLeft      =   60
       ClientTop       =   345
       ClientWidth     =   4680
       LinkTopic       =   "Form1"
       ScaleHeight     =   3195
       ScaleWidth      =   4680
       StartUpPosition =   3  'Windows Default
       Begin VB.CommandButton Command1 
          Caption         =   "Command1"
          Height          =   495
          Left            =   1500
          TabIndex        =   0
          Top             =   1080
          Width           =   1215
       End
    End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Public i As IntegerPrivate Sub Command1_Click()
        i = 12345
        Form2.Show
    End SubForm2.frm
    VERSION 5.00
    Begin VB.Form Form2 
       AutoRedraw      =   -1  'True
       Caption         =   "Form2"
       ClientHeight    =   3195
       ClientLeft      =   60
       ClientTop       =   345
       ClientWidth     =   4680
       LinkTopic       =   "Form2"
       ScaleHeight     =   3195
       ScaleWidth      =   4680
       StartUpPosition =   3  'Windows Default
       Begin VB.CommandButton Command1 
          Caption         =   "Command2"
          Height          =   495
          Left            =   1590
          TabIndex        =   0
          Top             =   1125
          Width           =   1215
       End
    End
    Attribute VB_Name = "Form2"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredId = True
    Attribute VB_Exposed = False
    Private Sub Command1_Click()
        Print Form1.i
    End Sub
      

  4.   

    用property Get/Property Let或Set,这样比较规范且决无性能上的损耗,VB在后台也是这么做的。
      

  5.   

    在form1中 public i as integer
    然后在form2中可以用form1.i来引用