找回密码
 加入
搜索
查看: 4668|回复: 32

用TimerInit 和 TimerDiff统计是时间取整的问题。

[复制链接]
发表于 2009-8-25 18:49:38 | 显示全部楼层 |阅读模式
本帖最后由 xavier880819 于 2009-9-2 16:57 编辑

我用TimerInit 和 TimerDiff统计时间,但是这个统计出来的时间小数点后面很多位,请问问大家能不能取整呢??我不想要小数点后面的数字该怎么办啊??
 楼主| 发表于 2009-8-26 15:18:02 | 显示全部楼层
希望知道这个问题怎么解决的朋友可以帮帮忙啊,谢谢~~
发表于 2009-8-26 15:32:19 | 显示全部楼层
Round ('时间值')
 楼主| 发表于 2009-8-26 15:36:48 | 显示全部楼层
谢谢你afan,我去试试
 楼主| 发表于 2009-8-26 15:49:23 | 显示全部楼层
其实我要做的是统计格式化的时间,我要做成花费了XX小时XX分钟XX秒的效果,但是如果我直接用round,会不会四舍五入在某些时候出问题呢??还是用直接拿windows的时间,拿2次,然后想减比较容易呢??
#Region ;

#AutoIt3Wrapper_UseAnsi=y

#EndRegion ;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>

GUICreate("Formater Ver 1.1", 633, 380, 193, 125)
Dim $xz,$a,$b,$zx,$Q,$F,$ff
Local $add, $clear, $mylist,$Button1,$sf,$format
$myedit = GUICtrlCreateEdit("", 5, 32, 620, 200)
$Button1 = GUICtrlCreateButton("Start Format Disc", 380, 250, 245, 33, 0)
GUICtrlCreateGroup("  Choose Format Way  ", 230, 250, 140, 100)
$Q = GUICtrlCreateRadio("Quick Format", 250, 280, 100, 20)
$F = GUICtrlCreateRadio("Full Format", 250, 300, 100, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1)  ;close group
GUISetState()  
$var = DriveGetDrive( "REMOVABLE" )
$xz = GUICtrlCreateCombo("Select The Disc", 20, 250,200,30)
For $i = 1 To $var[0]        
GUICtrlSetData($xz, $var[$i])
Next

GuiSetState(@SW_SHOW)

While 1
        $Msg = GUIGetMsg()
        Switch $Msg
                Case $GUI_EVENT_CLOSE
                        Exit
                
                Case $Button1
                        $f = MsgBox(1 + 48, 'Attention', 'Are you sure you want to format this disc?')
                        Select
                           Case $f = 1
                                             _test()
                                
                                Case $f = 2
                                ContinueLoop
                EndSelect
            Case $Q
                    $format='/Q/'
                Case $F
                        $format=''
        EndSwitch
Wend

 Func _test()
         
           Local $foo, $line, $lines, $currentRead
                        $a = TimerInit() 
                        $zx = GUICtrlRead($xz)
                        $foo =  Run(@ComSpec & " /c " & 'Format '&$zx&'/FS:FAT32/V:HaHa'&$format&'X/Y', "",@SW_HIDE, $STDOUT_CHILD)
                         While 1
                     
                      $line = StdoutRead($foo)

                      If @error Then ExitLoop

              GUICtrlSetData($myedit, $line, -1)
                          
                  WEnd
                       $b = TimerDiff($a)
                       $c = $b / 1000
                       $d = Round($c)    
               Msgbox(64,"Finish","This format cost you  " & $d & "  Seconds")
              EndFunc   ;==>_test
感觉还挺有问题的。
发表于 2009-8-26 16:04:13 | 显示全部楼层
TimerInit & TimerDiff 以毫秒计量已经相当精确了,不存在出什么问题~
 楼主| 发表于 2009-8-26 16:23:13 | 显示全部楼层
6# afan


当然是精确,但是如果要做成总共花费了 XX小时XX分钟XX秒 的显示格式怎么办??

如果用总时间是b,怎么弄呢??我好像有点乱了。
发表于 2009-8-26 16:58:36 | 显示全部楼层
#include <Date.au3>
Dim $H, $M, $S
_TicksToTime(Int($b), $H, $M, $S)
msgbox(0,0,'共耗时: ' & $H & ' 小时 ' & $M & ' 分钟 ' & $S & ' 秒 ')
 楼主| 发表于 2009-8-26 17:27:24 | 显示全部楼层
谢谢你afan!!!!
但是我的程序还有一些问题。
第一,在程序不关闭的情况下,我如果先选full format再选 quick format就没问题,但是我如果先选择了quick format,再去选择fullformat就不行了,还是直接执行quick format,很奇怪。明明我已经设定了点哪个就是那个的选项啊。
第二,在DOS里面,用full format,那个 1-100 persent complete是从1一个一个加到100的,为什么到了我的回显里面就全部成了1 persent complete, 2 persent complete,3 persent complete,4 persent complete,5 persent complete...............100 persent complete这样子显示的了呢??
发表于 2009-8-26 17:51:01 | 显示全部楼层
第一个问题,因为你的变量 $F 重名了;case也不对。
#Region ;
#AutoIt3Wrapper_UseAnsi=y
#EndRegion ;
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <StaticConstants.au3>

GUICreate("Formater Ver 1.1", 633, 380, 193, 125)
Dim $xz, $a, $b, $zx, $Q, $F, $ff
Local $add, $clear, $mylist, $Button1, $sf, $format
$myedit = GUICtrlCreateEdit("", 5, 32, 620, 200)
$Button1 = GUICtrlCreateButton("Start Format Disc", 380, 250, 245, 33, 0)
GUICtrlCreateGroup("  Choose Format Way  ", 230, 250, 140, 100)
$Q = GUICtrlCreateRadio("Quick Format", 250, 280, 100, 20)
$F = GUICtrlCreateRadio("Full Format", 250, 300, 100, 20)
GUICtrlCreateGroup("", -99, -99, 1, 1) ;close group
GUISetState()
$var = DriveGetDrive("REMOVABLE")
$xz = GUICtrlCreateCombo("Select The Disc", 20, 250, 200, 30)
For $i = 1 To $var[0]
        GUICtrlSetData($xz, $var[$i])
Next

GUISetState(@SW_SHOW)

While 1
        $Msg = GUIGetMsg()
        Switch $Msg
                Case $GUI_EVENT_CLOSE
                        Exit

                Case $Button1
                        $F111 = MsgBox(1 + 48, 'Attention', 'Are you sure you want to format this disc?')
                        Select
                                Case $F111 = 1
                                        If BitAND(GUICtrlRead($Q), $GUI_CHECKED) Then $format = '/Q/'
                                        If BitAND(GUICtrlRead($F), $GUI_CHECKED) Then $format = ''
                                        _test()

                                Case $F111 = 2
                                        ContinueLoop
                        EndSelect

        EndSwitch
WEnd

Func _test()
        Local $foo, $line, $lines, $currentRead
        $a = TimerInit()
        $zx = GUICtrlRead($xz)
        $foo = Run(@ComSpec & " /c " & 'Format ' & $zx & '/FS:FAT32/V:HaHa' & $format & 'X/Y', "", @SW_HIDE, $STDOUT_CHILD)
        While 1
                $line = StdoutRead($foo)
                If @error Then ExitLoop
                GUICtrlSetData($myedit, $line, -1)
        WEnd
        $b = TimerDiff($a)
        $c = $b / 1000
        $d = Round($c)
        MsgBox(64, "Finish", "This format cost you  " & $d & "  Seconds")
EndFunc   ;==>_test
发表于 2009-8-26 17:55:39 | 显示全部楼层
第二个问题,因为在dos里显示使用了在同一行更新,所以是 1-100 都在一行显示。
 楼主| 发表于 2009-8-26 22:30:31 | 显示全部楼层
那在autoit的回显里面能不能也在同一行更新呢??
或者说
1 persent complete
2 persent complete
3 persent complete
4 persent complete
5 persent complete
6 persent complete
这样也行啊。
只要不是1 persent complete,2 persent complete,3 persent complete,4 persent complete,5 persent complete这样就好啊。
 楼主| 发表于 2009-8-27 09:18:17 | 显示全部楼层
希望可以有高手对于上面的问题给个解答,谢谢
 楼主| 发表于 2009-8-27 14:39:49 | 显示全部楼层
对于回显问题,希望有大虾可以对我在12楼的问题给支个招
 楼主| 发表于 2009-8-28 09:09:23 | 显示全部楼层
自己顶一下,希望懂得的朋友能够看到。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-4-29 02:41 , Processed in 0.081324 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表