Private Sub Form_LinkExecute(CmdStr As String, Cancel As Integer)
Static lngCount As Long
Dim Info As String
Info = txtInfo.Text 注释: 保留原有信息
Select Case CmdStr 注释: CmdStr 是DDE程序传送过来的参数
Case "Max"
Me.WindowState = 2
Info = Info + vbNewLine + "窗体已被最大化"
Case "ShowTime"
Info = Info + vbNewLine + "最后一次运行这个程序的时间是:" + Str(Now)
Case "Count"
lngCount = lngCount + 1
Info = Info + vbNewLine + "你已经第" + Str(lngCount) + "次重复调用这个程序。" _
+ vbNewLine + "但怕您不多给工资,所以只运行了一个 ^_^"
End Select
If Left(CmdStr, Len(COMMANDLINE)) = COMMANDLINE Then
Info = Info + vbNewLine + "新程序曾以命令行形式运行" + vbNewLine + "命令行为:" _
+ vbNewLine + Right(CmdStr, Len(CmdStr) - Len(COMMANDLINE))
End If
txtInfo.Text = Info 注释: 把信息显示出来
Cancel = False
End Sub
Private Sub LinkAndSendMessage(ByVal Msg As String)
Dim t As Long
picDDE.LinkMode = 0 注释:--
picDDE.LinkTopic = "P1|FormDDE" 注释: |______连接DDE程序并发送数据/参数
picDDE.LinkMode = 2 注释: | “|”为管道符,是“退格键”旁边的竖线,
picDDE.LinkExecute Msg 注释:-- 不是字母或数字!
t = picDDE.LinkTimeout 注释:--
picDDE.LinkTimeout = 1 注释: |______终止DDE通道。当然,也可以用别的方法
picDDE.LinkMode = 0 注释: | 这里用的是超时强制终止的方法
picDDE.LinkTimeout = t 注释:--
End Sub
Private Sub Form_Load()
If App.PrevInstance Then 注释: 程序是否已经运行
将其中被调用工程做成activeEXE或者ActiveDLL格式。
然后创建对象,也可以传参数。
例如:
父工程:
Private Sub Command1_Click()
Dim o As Object
Dim age as Integer
age = 100
Set o = CreateObject("project1.class1")
o.SetAge = age
o.Show '
End Sub
子工程:
属性:工程类型:ActiveDLL
class1:
Public Sub show()
Form1.show vbmodal
End Sub
Public iAge As Integer
Public Property Let SetAge(LiAge As Variant)
On Error GoTo eh
iAge = LiAge
Exit Property
'*error処理
eh:
MsgBox Err.Description, vbInformation, "notion"
End Property
Public Property Get GetAge() As Integer
On Error GoTo eh
GetAge = iAge
Exit Property
eh:
MsgBox Err.Description, vbInformation, "notion"
End Property
class1的instance属性设为5-multiuse
module1:
Sub main()