vb中我想实现在关闭程序时只有在运行时单击过command1才弹出对话框,以下是代码,为什么无法实现?

来源:百度知道 编辑:UC知道 时间:2024/05/31 05:29:46
Private Sub Command1_Click()
dim x as integer
x=1
end sub

Private Sub Form_Unload(Cancel As Integer)
if x=1 then
msgbox(您单击过command1)
unload me
end
else
unload me
end
end if
end sub
但是运行时不管单击没单击过command1,都不弹出对话框,为什么啊??
呵呵我是初学者,如何放在窗体级?

dim x as integer

放在窗体级

Private Sub Command1_Click()
dim x as integer ‘这样是过程变量 和Form_Unload中x无关
x=1
end sub

改成
dim x as integer

Private Sub Command1_Click()
x=1
end sub

Private Sub Form_Unload(Cancel As Integer)
if x=1 then
msgbox("您单击过command1")
unload me
end
else
unload me
end
end if
end sub

dim x as integer
放在代码窗 通用 声明 部分