Dim frmEx As New Form2 frmEx.Show 1 '其它代码 if frmEx.ID=1 then'ID是Form2的public变量 '操作1 else '操作2 end if Set frmEx = Nothing
end sub
建立一个窗口Form1 在Form1中增加一个Command1的按扭 在代码窗口中输入代码: Private Sub Command1_Click() Select Case sMsgbox("vfdsda", Me) Case 0 MsgBox "你单击的是""是""按扭" Case 1 MsgBox "你单击的是""否""按扭" Case 2 MsgBox "你单击的是""取消""按扭" Case Else MsgBox "您没有单击按扭退出窗口" End Select End Sub '************************************* 建立一个窗口Form2 在Form1中增加三个按扭 第一个按扭 Name=Command1 Caption=是 Index=0 第二个按扭 Name=Command1 Caption=否 Index=1 第三个按扭 Name=Command1 Caption=取消 Index=2代码窗口中输入以下代码: Public cmdIndex As LongPrivate Sub Command1_Click(Index As Integer) cmdIndex = Index Me.Hide End Sub '*************************************** 再建立一个Module1 在代码窗口中输入以下代码:Function sMsgbox(ByVal Prompt As String, ByVal frm As Form) As Long Form2.cmdIndex = -1 Form2.Show vbModal, frm Form2.Label1.Caption = Prompt Form2.Label1.AutoSize = True sMsgbox = Form2.cmdIndex End Function'************************** 按F5键运行,看是否是要这种效果?
frmEx.Show 1
'其它代码
if frmEx.ID=1 then'ID是Form2的public变量
'操作1
else
'操作2
end if
Set frmEx = Nothing
end sub
在Form1中增加一个Command1的按扭
在代码窗口中输入代码:
Private Sub Command1_Click()
Select Case sMsgbox("vfdsda", Me)
Case 0
MsgBox "你单击的是""是""按扭"
Case 1
MsgBox "你单击的是""否""按扭"
Case 2
MsgBox "你单击的是""取消""按扭"
Case Else
MsgBox "您没有单击按扭退出窗口"
End Select
End Sub
'*************************************
建立一个窗口Form2
在Form1中增加三个按扭
第一个按扭
Name=Command1
Caption=是
Index=0
第二个按扭
Name=Command1
Caption=否
Index=1
第三个按扭
Name=Command1
Caption=取消
Index=2代码窗口中输入以下代码:
Public cmdIndex As LongPrivate Sub Command1_Click(Index As Integer)
cmdIndex = Index
Me.Hide
End Sub
'***************************************
再建立一个Module1
在代码窗口中输入以下代码:Function sMsgbox(ByVal Prompt As String, ByVal frm As Form) As Long
Form2.cmdIndex = -1
Form2.Show vbModal, frm
Form2.Label1.Caption = Prompt
Form2.Label1.AutoSize = True
sMsgbox = Form2.cmdIndex
End Function'**************************
按F5键运行,看是否是要这种效果?