两个值a,b进行比较,b是通过函数取过来的,当b得到的值跟a不一样时,等待10秒,然后再去取。
程序大体像下面一样
While a <> b
        Dim Savetime As Double
        Savetime = timeGetTime
        '等待10S
        While timeGetTime < Savetime + 10000
            b = ReadValue()
        Wend
    Wend但是这样的写的话好像在这10里它一直在执行b = ReadValue()这句话,而根本不是等待
有哪位兄弟能帮忙解决一下这个等待问题吗?

解决方案 »

  1.   


       Dim SaveTime As Date
       Dim NowTime As Date
       Dim NextSecond As Long
       SaveTime = Now
       Do
          DoEvents
          NowTime = Now
          NextSecond = DateDiff("s", SaveTime, NowTime)
       Loop While NextSecond < 10
      

  2.   

    Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Sub Macro1()
    '
    ' Macro1 Macro
    ''
        ActiveCell.FormulaR1C1 = "test"
        
        Sleep 10 * 1000
        
        MsgBox ActiveCell.Value
    End Sub  
    *****************************************************************************
    欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码) 
    http://feiyun0112.cnblogs.com/
      

  3.   

    给你个例子看看Private Sub Command1_Click()
       MsgBox "当您点击确定后,开始等待十秒然后再次提示信息。", 64, "提示"
       Call WaitTime(10)
       MsgBox "完成"
    End SubPrivate Sub WaitTime(WaitSecond As Long)
       Dim SaveTime As Date
       Dim NowTime As Date
       Dim NextSecond As Long
       SaveTime = Now
       Do
          DoEvents
          NowTime = Now
          NextSecond = DateDiff("s", SaveTime, NowTime)
          Label1.Caption = NextSecond
       Loop While NextSecond < WaitSecond
    End Sub
      

  4.   

    Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)Private Sub CommandButton1_Click()
        Dim strTemp As String
        
        strTemp = InputBox("please input")
        While strTemp <> "a"
            Call Sleep(10 * 1000)
            DoEvents
            strTemp = InputBox("please input")
        Wend
        MsgBox "ok"
        
    End Sub
      

  5.   

    谢谢各位兄弟了,看来我是少写了一句DoEvents