wongfung 发表于 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

akmm88 发表于 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 里面了。
页: [1]
查看完整版本: 完成了, 想問問優化代碼的建議