小弟定制了一个About窗体类,帮忙看错在哪里
主要控件有,三个标签lblDescription,lblVersion,lblTime,一个Timer控件timInterval interval=1000
可是一运行,就出错(变量没定义,出错位置为黄色和蓝色标记),代码如下:
Option Explicit
'mstrTitle 用来表示对话框的标题
Private mstrTitle As String
'取得对话框的标题
Public Property Get Title() As Variant
Title = mstrTitle
End Property
'给对话框标题赋值
Public Property Let Title(ByVal vNewValue As Variant)
'若传递过来的值不为空,则将其赋给mstrTitle
'若为空,则将以默认的形式给mstrTitle赋值
If CStr(vNewValue) <> "" Then
mstrTitle = vNewValue
Else
mstrTitle = "关于" & App.Title
End If
'将mstrTitle属性赋给对话框的标题
Me.Caption = mstrTitle
End Property
'mstrDescription用来表示应用程序的说明,对应lblDescription的Caption属性
Private mstrDescription As String
'添加属性的获取过程(Property Get)和赋值过程(Property Let),代码如下:
'获取对话框的说明性描述
Public Property Get Description() As Variant
Description = mstrDescription
End Property
Public Property Let Description(ByVal vNewValue As Variant)
'若传递过来的值不为空,则将其赋给mstrDescription
'若为空,则将以默认的形式给mstrDescrition赋值
If CStr(vNewValue) <> "" Then
mstrDescription = vNewValue
Else
mstrDescription = App.Title
End If
'将mstrDescription属性赋给lblDescription的Caption属性
lblDescription.Caption = mstrDescription
End Property
'mstrVersion用来表示应用程序的版本信息,对应lblVersion的Caption属性
Private mstrVersion As String
'添加属性的获取过程(Property Get)和赋值过程(Property Let),代码如下:
'获取对话框的版本信息
Public Property Get Version() As Variant
Version = mstrVersion
End Property
Public Property Let Version(ByVal vNewValue As Variant)
'若传递过来的值不为空,则将其赋给mstrVersion
'若为空,则将以默认的形式给mstrVersion赋值
If CStr(vNewValue) <> "" Then
mstrVersion = vNewValue
Else
mstrVersion = "版本" & App.Major & "." & App.Minor & "." & App.Revision
End If
'将mstrVersion属性赋给lblVersion的Caption属性
lblVersion.Caption = mstrVersion
End Property
'mnTimeRemain表示对话框存在的时间,以秒计时,一量时间到,则关闭对话框
Private mnClosetime As Integer
'还剩余多少时间才关闭对话框
Private mnTimeRemain As Integer
'添加属性的获取过程(Property Get)和赋值过程(Property Let),代码如下:
'获取对话框的存在时间
Public Property Get CloseTime() As Variant
CloseTime = mnClosetime
End Property
'给对话框的存在时间赋值
Public Property Let CloseTime(ByVal vNewValue As Variant)
'若传递过来的值小于等于0,则令关闭时间为1秒
Dim i As Integer
i = Int(Val(vNewValue))
If i <= 0 Then
i = 1
End If
'将关闭时间赋值
mnClosetime = i
'在mnTimeRemain中记录关闭对话框所剩余的时间,初始为mnCloseTime
mnTimeRemain = mnClosetime
'根据关闭时间,来改变lblTime的Caption属性
lblTime.Caption = "对话框将会在 " & mnTimeRemain & "秒钟之后关闭!"
End Property
'对话框的自定义打开方法
Public Sub ShowDialog(ByVal nStyle As Integer, ByVal strTitle As String, _
ByVal strDescription As String, ByVal strVersion As String, ByVal nCloseTime As Integer)
'传递过来的值分别赋给对话框对应的属性
Me.Title = strTitle
Me.Description = strDescription
Me.Version = strVersion
Me.CloseTime = nCloseTime
'参数nStyle指出将会以何种方式显示对话框
'若为0,将会以无模式的方式显示;若为1,将会以模式的方式显示对话框
'若nStyle的值不为0或1,这将会是模式的方式显示对话框
Dim n As Integer
If nStyle = 0 Or nStyle = 1 Then
n = nStyle
Else
n = 1
End If
Me.Show n
End Sub
Private Sub timInterval_Timer()
mnTimeRemain = mnTimeRemain - 1 (错误原因:变量未定义)
'若对话框存在时间>=0,则改变lblTime的Caption属性
'否则,关闭对话框
If mnTimeRemain >= 0 Then
lblTime.Caption = "对话框将会在 " & mnTimeRemain & "秒钟之后自动关闭!"
Else
Unload Me
End If
End Sub