我用VB编好了一个时钟的程序,如下,我怎么修改可以让程序中的时针、分针、秒针,随系统时间走动呢?帮帮

Constpi=3.1415926PrivateSubForm_Load()DimtAsDateDimsAsIntegerDimmAsIntegerDimhAsInteg... Const pi = 3.1415926
Private Sub Form_Load()
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
lins.X2 = lins.X1 + 3200 * Sin(6 * s * pi / 180)
lins.Y2 = lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
linf.X2 = linf.X1 + 2600 * Sin(6 * m * pi / 180)
linf.Y2 = linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
linh.X2 = linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
linh.Y2 = linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub
展开
 我来答
知道答题高手
2011-03-26 · TA获得超过286个赞
知道答主
回答量:66
采纳率:0%
帮助的人:0
展开全部
添加一个Timer时钟控件,把Timer1的Interval值设为1000,把Form_Load()事件里的代码移到Timer_Timer()事件里

Const pi = 3.1415926

Private Sub Timer1_Timer()
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
lins.X2 = lins.X1 + 3200 * Sin(6 * s * pi / 180)
lins.Y2 = lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
linf.X2 = linf.X1 + 2600 * Sin(6 * m * pi / 180)
linf.Y2 = linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
linh.X2 = linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
linh.Y2 = linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub
冰糖BST
2011-03-26 · TA获得超过560个赞
知道小有建树答主
回答量:262
采纳率:0%
帮助的人:233万
展开全部
用一个TIMER控件,把代码放到TIMER里面去
Const pi = 3.1415926
Private Sub Form_Load()
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
Lins.X2 = Lins.X1 + 3200 * Sin(6 * s * pi / 180)
Lins.Y2 = Lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
Linf.X2 = Linf.X1 + 2600 * Sin(6 * m * pi / 180)
Linf.Y2 = Linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
Linh.X2 = Linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
Linh.Y2 = Linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub

Private Sub Timer1_Timer()
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
Lins.X2 = Lins.X1 + 3200 * Sin(6 * s * pi / 180)
Lins.Y2 = Lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
Linf.X2 = Linf.X1 + 2600 * Sin(6 * m * pi / 180)
Linf.Y2 = Linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
Linh.X2 = Linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
Linh.Y2 = Linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
wtywtykk
2011-03-26 · TA获得超过128个赞
知道小有建树答主
回答量:153
采纳率:0%
帮助的人:173万
展开全部
吧Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
lins.X2 = lins.X1 + 3200 * Sin(6 * s * pi / 180)
lins.Y2 = lins.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
linf.X2 = linf.X1 + 2600 * Sin(6 * m * pi / 180)
linf.Y2 = linf.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
linh.X2 = linh.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
linh.Y2 = linh.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)这一段放到一个timer控件的过程里就行了,Interval设为100(0.1秒刷新)或1000(1秒刷新)。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
xiaoyuemt
2011-03-26 · TA获得超过1.6万个赞
知道大有可为答主
回答量:3202
采纳率:64%
帮助的人:1677万
展开全部
没有定义各线的初始位置,直接调到窗口中心吧,加个timer控件:
Private Sub Form_Load()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Const pi = 3.1415926
Dim t As Date
Dim s As Integer
Dim m As Integer
Dim h As Integer
t = Time()
s = Second(t)
Line1.X1 = Me.Width / 2
Line3.X1 = Me.Width / 2
Line2.X1 = Me.Width / 2
Line1.Y1 = Me.Height / 2
Line2.Y1 = Me.Height / 2
Line3.Y1 = Me.Height / 2
Line1.X2 = Line1.X1 + 3200 * Sin(6 * s * pi / 180)
Line1.Y2 = Line1.Y1 - 3200 * Cos(6 * s * pi / 180)
m = Minute(t)
Line2.X2 = Line2.X1 + 2600 * Sin(6 * m * pi / 180)
Line2.Y2 = Line2.Y1 - 2600 * Cos(6 * m * pi / 180)
h = Hour(t)
Line3.X2 = Line3.X1 + 2000 * Sin((30 * h + 0.5 * m) * pi / 180)
Line3.Y2 = Line3.Y1 - 2000 * Cos((30 * h + 0.5 * m) * pi / 180)
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(2)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式