I';我明天早上试一试
我的荣幸,希望有帮助
对于那些由于工作地点的安全设置而无法下载的用户,这里是代码
首先,名为frmMain的表单有3个控件: ;CommandButton,名为btnOk ;CommandButton,名为btnCancel ;文本框   ;命名tbxMain代码--Option Explicit
Private myExitState As Boolean
Public Property Get ExitState() As Boolean
''Return the value hosted our private member variable.
''Since we have no corresponding Let Property statement
''it's ostensibly read-only.
ExitState = myExitState
End Property
Public Property Get UserText() As String
''Return the current value of the text in the tbxMain
''object. While the way VB is structured it allows
''access to the object directly we should not go that
''route . A future implementation may use a
''different object, or otherwise employ a different
''implementation. Such changes should not affect clients
''or consumers of the form. Also, this gives us the
''opportunity to perform other activities before we
''return the value, like qualifying, logging, whatever.
UserText = tbxMain.text
End Property
Public Property Let UserText(value As String)
''Allow the client set the value of the txbMain object,
''BUT NOT DIRECTLY. See balance of comments in the Get
''UserText Property.
tbxMain.text = value
End Property
Private Sub btnOk_Click()
''Set the state and then hide the form.
IndicateAccept
Me.Hide
End Sub
Private Sub btnCancel_Click()
''Set the state and then hide the form.
IndicateCancel
Me.Hide
End Sub
Private Sub IndicateAccept()
''As there may be more than one way this is triggered
''let's have one procedure have responsibility for
''setting the state. While this seems overkill because
''we have but one little variable representing state,
''in a big application there could be many things that
''have to be done aside from merely setting said variable.
''This gives us one entry point, and thus, only one area
''to edit when things change, and more often than not
''they will.
myExitState = True
End Sub
Private Sub IndicateCancel()
''See comment in Sub IndicateAccept.
myExitState = False
End Sub
Private Sub UserForm_Activate()
''Start with state indicating cancel.
IndicateCancel
End Sub
Private Sub UserForm_Initialize()
''Start with state indicating cancel.
IndicateCancel
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
''If the user closed the form via the control
''box instead of the or buttons ...
If CloseMode = VbQueryClose.vbFormControlMenu Then
IndicateCancel
End If
End Sub 然后是模块代码,在名为mdlMain的模块中--Option Explicit
Public Sub Main()
Dim myForm As frmMain
Set myForm = New frmMain
''Access and use the property(s) we exposed.
myForm.UserText = "Mark's great adventure."
''Alrighty, let's show it.
myForm.Show
''Program execution will not end up here until the
''user closes the form, either by clicking the
''or buttons or via the control box (the
'' in the top right corner).
If Not (myForm Is Nothing) Then
''An error may be thrown if the user closes the
''form via the control box because it will have
''been unloaded but not yet nothing (let's trap
''that possibility).
On Error GoTo ErrHandler
If myForm.ExitState Then
''access the UserText Property we exposed
MsgBox _
"User pressed ." & vbCrLf & vbCrLf & _
"UserText = "
Else
MsgBox "User pressed ."
End If
Unload myForm
Set myForm = Nothing
Exit Sub
ErrHandler:
If Err.Number = -2147418105 Then
MsgBox _
"The user closed the form via the " & _
"form's control box."
Else
''Uhhh, what the h3ll? An error we didn't
''anticipate. Let's display the error
''description.
MsgBox Err.Description
End If
Err.Clear
Resume OutOfHere
End If
OutOfHere:
Set myForm = Nothing
End Sub 看到问题,看到错误的建议等?让我/我们知道。谢谢 一下子,议员提醒吉咪,他真的只是一个黑客……看起来像所有伟大的建议迈克尔!现在,如果我能学会将这些建议融入我写的东西中,那该多好啊……谢谢你发布代码,因为我不是';我不打算下载这个项目(我现在已经有足够的东西了……),但是哇!真让人大开眼界
Jeff_M回到了用hammer&;编写代码的时代;凿子
It';没错,我是个黑客<;不值得你的赞扬>;——但老实说,我每天都在努力变得更好!如果您看到该代码或注释有任何错误,很有可能,请告诉我
谢谢杰夫
页:
1
[2]