GHRH - 2006-12-16 21:58:00
看到瑞星升完级,更新后有个倒计时的显示,朋友就问我VB6.0中如何实现:
我举个简单的例子:
Dim a As String '绝对要的在声明中定义
Private Sub Form_Load()
Label1.Caption = ""
a = 30
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
a = Val(a) - 1
Label1.Caption = "程序将在:" & a & "后关闭!"
If a = 0 Then
End
End If
End Sub
闪电风暴 - 2006-12-21 13:34:00
| 引用: |
【GHRH的贴子】看到瑞星升完级,更新后有个倒计时的显示,朋友就问我VB6.0中如何实现: 我举个简单的例子: Dim a As String ''绝对要的在声明中定义 Private Sub Form_Load() Label1.Caption = "" a = 30 'a的类型为string,最好不要用INT类型赋值 Timer1.Interval = 1000 End Sub
Private Sub Timer1_Timer() a = Val(a) - 1 Label1.Caption = "程序将在:" & a & "后关闭!" If a = 0 Then End End If End Sub ……………… |
我个人觉得,把时间的integer型与string型最好分开声明,不要使用同名。
在Timer事件中的a=val(a)-1这行,前面的A为int,后面的为string型,容易引起混淆
闪电风暴 - 2006-12-21 13:42:00
建议不要把INT与STRING类型混用为一个变量名
闪电风暴 - 2006-12-21 13:42:00
感觉到这样比较好:
int a=30;
///省略SetTimer等函数.....
case WM_TIMER:
printf("%d\n",a--);
换成VB就是:
dim a as integer
sub form_load()
a=30
end sub
sub timer1_timer()
lable1.caption="程序将在" & a & "后关闭!"
a=a-1
if a=0 then
unload me
end if
end sub
© 2000 - 2026 Rising Corp. Ltd.