变量的作用域问题, 想不通...
本帖最后由 bcrun 于 2013-02-08 08:39:17 编辑
'为什么下边这三个变量不能放在载入窗体里?
'h = 0 还是传递到了始终控件那儿啊~
Dim h As Integer
Dim m As Integer
Dim s As Integer
Private Sub Form_Load()
h = 0
m = 0
s = 0
Label1.Caption = "00: 00: 00"
End Sub
Private Sub Timer1_Timer()
'字符串每次都需要归零, 重新赋值.
Dim strH As String
Dim strM As String
Dim strS As String
s = s + 1
If s = 60 Then
s = 0
m = m + 1
If m = 60 Then
m = 0
h = h + 1
If h = 24 Then
h = 0
End If
End If
End If
If s < 10 Then
strS = "0" & s
Else
strS = s
End If
If m < 10 Then
strM = "0" & m
Else
strM = m
End If
If h < 10 Then
strH = "0" & h
Else
strH = h
End If
Label1.Caption = strH & ": " & strM & ": " & strS
End Sub