excel里用vba实现开始计时 暂停计时 结束计时这三种功能 暂停的同时可以开始另一个计时 大侠们帮帮我吧
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了excel里用vba实现开始计时 暂停计时 结束计时这三种功能 暂停的同时可以开始另一个计时 大侠们帮帮我吧相关的知识,希望对你有一定的参考价值。
参考技术A Private Sub Worksheet_SelectionChange(ByVal Target As Range)Range("B1") = "开始"
Range("B2") = "暂停"
Range("B3") = "继续"
Range("B4") = "停止"
If Selection.Count > 1 Then End
If Target = "" Then End
Range("A1").NumberFormatLocal = "h:mm:ss"
Range("A2").NumberFormatLocal = "h:mm:ss"
Range("C1").NumberFormatLocal = "h:mm:ss"
Range("C2").NumberFormatLocal = "h:mm:ss"
nm = Target.Value
If nm = "开始" Then
Range("A1") = ""
Range("A2") = ""
Range("C1") = Now
Range("C2") = ""
Call JS(1)
Else
If nm = "停止" Then
Range("C1") = ""
Range("C2") = ""
Else
If nm = "暂停" Then
Range("C1") = ""
Range("C2") = Now
Call JS(2)
Else
If nm = "继续" Then
Range("C1") = Now
Range("C2") = ""
Call JS(1)
End If
End If
End If
End If
End Sub
...'宏
Sub Disp1()
If Range("C1") <> "" Then
If Range("A1") <> "" Then
Range("A1") = Range("A1") + TimeValue("0:00:01")
Else
Range("A1") = Now - Range("C1")
End If
Call JS(1)
End If
End Sub
Sub Disp2()
If Range("C2") <> "" Then
Range("A2") = Now - Range("C2")
Call JS(2)
End If
End Sub
Sub JS(id As Integer)
If id = 1 Then
Application.OnTime Now + TimeValue("0:00:01"), "Disp1"
Else
If id = 2 Then
Application.OnTime Now + TimeValue("0:00:01"), "Disp2"
End If
End If
End Sub
用java编一个简单的倒计时表
他倒计时1分钟,但是显示的是几小时几分几秒 界面中有三部分 一个开始一个暂停。按暂停停止 安开始又继续 麻烦高手们了。。。谢谢 要全面的。。
先不要关闭问题,给我点时间我编出来,我也想断炼一下。代码如下:
我这程序有点问题 ,这倒计时你讲的功能都有了,但那个暂停按钮有问题,只能用两次,我怎么也找不出原因, 我想是多线程方面的问题吧,按两下那暂停按钮就失去作用了。
--------------------------MainFrame.java------------------------------------
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class MainFrame extends Frame
Dispose dp= null;
int flag=1; //暂停开始的按钮,1为计时中,0为暂停。
Button button=null;
Label l1 =null;
Label l2 =null;
Label l3 = null;
TextField tfh =null;
TextField tfm =null;
TextField tfs =null;
public void lanchFrame()
this.setLocation(200,200);
this.setSize(200,200);
this.setLayout(new FlowLayout());
l1=new Label("hour");
tfh = new TextField("1",6);
l2=new Label("minute");
tfm = new TextField("3",6);
l3=new Label("second");
tfs = new TextField("5",6);
button = new Button("stop");
this.add(l1);
this.add(tfh);
this.add(l2);
this.add(tfm);
this.add(l3);
this.add(tfs);
this.add(button);
button.addActionListener(new StartAndStopListener(this));
this.addWindowListener(new MyClosingListener());
this.dp = new Dispose(this);
this.pack();
this.setVisible(true);
public static void main(String args[])
MainFrame mf=new MainFrame();
mf.lanchFrame();
mf.dp.run(mf);
private class MyClosingListener extends WindowAdapter
public void windowClosing(WindowEvent e)
System.exit(0);
--------------------------Dispose.java------------------------------------
public class Dispose
int hour;
int minute;
int second;
public Dispose(MainFrame mf)
this.hour = Integer.parseInt(mf.tfh.getText());
this.minute = Integer.parseInt(mf.tfm.getText());
this.second = Integer.parseInt(mf.tfs.getText());
public void run(MainFrame mf)
while (!(hour == 0 && minute == 0 && second == 0) && mf.flag == 1)
if (second == 0)
if (minute > 0)
second = 59;
minute--;
if (minute == 0)
if (hour > 0)
minute = 59;
hour--;
second--;
mf.tfs.setText(second + "");
mf.tfm.setText(minute + "");
mf.tfh.setText(hour + "");
try
Thread.sleep(1000);
catch (InterruptedException e)
e.printStackTrace();
------------------------------StarAndStopListener.java-----------------------------
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class StartAndStopListener implements ActionListener
MainFrame mf = null;
public StartAndStopListener(MainFrame mf)
this.mf = mf;
public void actionPerformed(ActionEvent arg0)
if(mf.flag==0)
mf.flag =1;
mf.button.setLabel("stop");
mf.dp.run(mf);
if(mf.flag == 1)
mf.flag = 0;
mf.button.setLabel("start");
参考技术A public class Daojishi extends Thread
public static void main(String[] args) throws Exception
for(int i=10;i>0;i--)
Thread.sleep(1000);
System.out.println("倒计时:"+i);
以上是关于excel里用vba实现开始计时 暂停计时 结束计时这三种功能 暂停的同时可以开始另一个计时 大侠们帮帮我吧的主要内容,如果未能解决你的问题,请参考以下文章