找回密码
 加入
搜索
查看: 1598|回复: 1

完成了, 想問問優化代碼的建議

[复制链接]
发表于 2009-1-20 21:03:10 | 显示全部楼层 |阅读模式
#cs ----------------------------------------------------------------------------

AutoIt 版本: 3.2.3.12第二版)
脚本作者:
        Email:
        QQ/TM:
脚本版本:
脚本功能:

#ce ----------------------------------------------------------------------------

; 脚本开始 - 在这后面添加您的代码.
#include <GUIConstantsEx.au3>
#include <File.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $Button_1, $Button_2, $msg, $var1, $var2, $right, $left
    GUICreate("Tool",220,40)
       
    Opt("GUICoordMode", 2)
    $Button_1 = GUICtrlCreateButton("Moving Right", 10, 10, 100)
    $Button_2 = GUICtrlCreateButton("Moving Left", 5, -24, 100)

    GUISetState()  

    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg = $Button_1
                 $var1 = FileOpenDialog("Open", @MyDocumentsDir, "1(*.1)" , 1 )
                        If @error Then
                        MsgBox(4096,"","File Not Found!")
                        Else
                                 $right = MsgBox(4+32,"Moving Right","Replace the File?")
                        If $right=6 Then
                                _ReplaceStringInFile ( $var1, "18:", "19:", 0 , 1 )
                                _ReplaceStringInFile ( $var1, "15:", "18:", 0 , 1 )
                                _ReplaceStringInFile ( $var1, "14:", "15:", 0 , 1 )
                        MsgBox(0, "Moving Right", "Finished & Saved! ")
                EndIf
                EndIf
                        Case $msg = $Button_2
                 $var2 = FileOpenDialog("Open BMS", @MyDocumentsDir, "1(*.1)" , 1 )
                        If @error Then
                        MsgBox(4096,"","File Not Found!")
                        Else
                                 $left = MsgBox(4+32,"Moving Left","Replace the File?")
                        If $left=6 Then
                                _ReplaceStringInFile ( $var2, "11:", "16:", 0 , 1 )
                                _ReplaceStringInFile ( $var2, "12:", "11:", 0 , 1 )
                                _ReplaceStringInFile ( $var2, "13:", "12:", 0 , 1 )
                        MsgBox(0, "Moving Left", "Finished & Saved! ")
                EndIf
                EndIf
        EndSelect
    WEnd
EndFunc
发表于 2009-1-20 21:38:50 | 显示全部楼层
Const $yes =6
If MsgBox(4+32,"Moving Right","Replace the File?")=$yes Then ;如果点击了yes按钮
这样可读性是不是好点呢?
Case $msg = $Button_1
下面的这些放在一个函数里比如 OnButton1_Click()
这个程序最差的就是可读性,其它的像主要操作都在_ReplaceStringInFile 里面了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-23 08:25 , Processed in 0.081452 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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