找回密码
 加入
搜索
查看: 4529|回复: 7

[AU3基础] [已解决]代码什么错误?只能运行一次。

  [复制链接]
发表于 2014-1-21 17:37:35 | 显示全部楼层 |阅读模式
本帖最后由 hnfeng 于 2014-1-21 19:56 编辑

初学AU3. 下面的代码尚未完成(数据输出尚未做)。测试时发现,可以浏览导入含有key的文件(或者“从剪贴板”,或者直接在 edit1 里面Ctrl+V),然后按“开始”,能把结果放到 edit2里面。但是此时必须退出,如果想再次导入key文件或者“从剪贴板”或者在edit1中有编辑动作,再按“开始”,程序必定会死掉。就是说只能按一次“开始”,然后退出。为什么哦,求帮忙看看:
#region ;**** 参数创建于 ACNWrapper_GUI ****
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <File.au3>

Global $KeyFileName, $KeyS, $Array_KeyS[1]

Local $iLabel = ""
$Form1 = GUICreate("MS_Key提取整理去重复工具", 874, 451)
$Label1 = GUICtrlCreateLabel("MS Key 提取整理去重复小工具", 217, 16, 438, 42, $SS_CENTER)
GUICtrlSetFont(-1, 22, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x0000FF)
$Label2 = GUICtrlCreateLabel($iLabel, 824, 48, 36, 17, $SS_RIGHT)
$Label3 = GUICtrlCreateLabel("", 166, 56, 540, 3, BitOR($SS_GRAYRECT, $WS_TABSTOP))
GUICtrlSetBkColor(-1, 0x808080)
$Group1 = GUICtrlCreateGroup(" 输入 ", 8, 72, 361, 369)
$Input1 = GUICtrlCreateInput("", 24, 104, 273, 21)
$Edit1 = GUICtrlCreateEdit("", 24, 144, 273, 281)
GUICtrlSetFont(-1, 9, 400, 0, "Courier New")
$Button1 = GUICtrlCreateButton("浏览", 312, 104, 41, 25)
$Button2 = GUICtrlCreateButton("从剪贴板", 304, 200, 57, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup(" 输出 ", 504, 72, 361, 369)
$Input2 = GUICtrlCreateInput("", 520, 104, 273, 21)
$Edit2 = GUICtrlCreateEdit("", 520, 144, 273, 281)
GUICtrlSetFont(-1, 9, 400, 0, "Courier New")
$Button3 = GUICtrlCreateButton("浏览", 808, 104, 41, 25)
$Button4 = GUICtrlCreateButton("到剪贴板", 800, 200, 57, 33)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button5 = GUICtrlCreateButton("开始", 392, 208, 89, 57)
$Button6 = GUICtrlCreateButton("退出", 392, 308, 89, 41)
$Button7 = GUICtrlCreateButton("关于", 392, 408, 89, 25)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###
Local $InFile, $OutFile

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        _InputFile()
                Case $Button2
                        _GetFrClip()
                ;Case $Button3
                ;        _OutputFile()
                ;Case $Button4
                ;        _PutTo()
                Case $Button5
                        _GOGOGO()
                Case $Button6
                        Exit
                Case $Button7
                        _ABOUT()
        EndSwitch
WEnd

Func _InputFile()
        $InFile = FileOpenDialog("选择欲导入的保存有Key的文件", @ScriptDir, "(*.txt)", 3)
        If @error Then
                MsgBox(16, "", "没有选择文件或者无效文件类型!")
        Else
                Local $File = FileOpen($InFile)
                If $File = -1 Then
                        MsgBox(4096, "错误", "不能打开文件.")
                Else
                        Local $chars = FileRead($File, -1)
                        ;MsgBox(4096, "读取的字符:", $chars)
                        GUICtrlSetData($Input1, $InFile)
                        GUICtrlSetData($Edit1, $chars)
                EndIf
        EndIf
        FileClose($InFile)
EndFunc   ;==>_InputFile

Func _GetFrClip()
        Local $Clip = ClipGet()
        If @error Then
                MsgBox(16, "", "剪切板为空或为非文本")
        Else
                GUICtrlSetData($Input1, "")
                GUICtrlSetData($Edit1, $Clip)
        EndIf
EndFunc   ;==>_GetFrClip

Func _GOGOGO()
        Local $Data1 = GUICtrlRead($Edit1)
        ;MsgBox(0,"",$Data)
        $KeyFileName = @TempDir & "\MS_Key_tmp.txt"
        _FileCreate($KeyFileName)
        FileOpen($KeyFileName)
        FileWrite($KeyFileName, $Data1)
        FileClose($KeyFileName)
        $KeyS = _GetKey($KeyFileName)
        ;MsgBox(0,"找到的Key数量(可能有重复的):",$KeyS)
        ;_ArrayDisplay($Array_KeyS)
        Local $aNewArray = _ArrayUnique($Array_KeyS)
        ;_ArrayDisplay($aNewArray)
        Local $Data2 = _ArrayToString($aNewArray, @CRLF, 1)
        ;MsgBox(0,"xxxxxx",$Data)
        GUICtrlSetData($Edit2, $Data2)
        FileDelete($KeyFileName)
EndFunc   ;==>_GOGOGO

Func _ABOUT()
        MsgBox(0x00000040, "自编自用程序", _
                        "MS Key 提取整理去重复小工具" & @CRLF & @CRLF & _
                        "说明------------------------------------" & @CRLF & _
                        "说明------------------------------------")
EndFunc   ;==>_ABOUT

Func _GetKey($KeyFileName)
        FileOpen($KeyFileName)
        $KeyS = 0
        Local $line = 1, $KeyH = 1, $Key
        While 1
                $Key = FileReadLine($KeyFileName, $line)
                If @error = -1 Then ExitLoop
                $line += 1
                $KeyH = StringReplace($Key, " ", "")
                $Key = StringRegExp($KeyH, "([A-Za-z0-9]{5}-){4}[A-Za-z0-9]{5}", 0)
                If $Key = 1 Then $KeyS += 1
        WEnd
        ;MsgBox(0, "", "个数:" & $KeyS)
        If $KeyS <> 0 Then
                ReDim $Array_KeyS[$KeyS]
                $line = 1
                $KeyS = 0
                While 1
                        $Key = FileReadLine($KeyFileName, $line)
                        If @error = -1 Then ExitLoop
                        $line += 1
                        $KeyH = StringReplace($Key, " ", "")
                        $Key = StringRegExp($KeyH, "([A-Za-z0-9]{5}-){4}[A-Za-z0-9]{5}", 2)
                        If Not @error Then
                                $K = $Key[0]
                                $Array_KeyS[$KeyS] = $K
                                ;_ArrayDisplay($Array_KeyS)
                                $KeyS += 1
                        EndIf
                WEnd
        EndIf
        FileClose($KeyFileName)
        Return $KeyS
EndFunc   ;==>_GetKey

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2014-1-21 17:40:12 | 显示全部楼层
供测试用来输入用的:
[Tested working 20 January 2014]: 
Key Win 8.1 mak (retail & VL), Enterprise & enterpriseN). 
slmgr.vbs /ipk FMNCT-6JGDC-BGXQ7-VC8VJ-VH4X3 
====================== 
Key win 8 / 8.1 pro with media center. 
[Tested working 20 January 2014]: 
slmgr.vbs /ipk PFJY7-W9DH7-M4V62-NJ4QM-XBQJD 
slmgr.vbs /ipk KX6F8-MKG8B-D2NQP-YGC27-46V4Q 
slmgr.vbs /ipk PVMXD-2GN9F-9PW7Q-GXJVG-KTMDQ 
====================== 
Key win 8 mak(retail & VL), Enterprise & enterpriseN). 
[Tested working 20 January 2014]: 
slmgr.vbs /ipk BJKP6-NDDC9-W9X7H-MMMTD-TCKVC 
slmgr.vbs /ipk 9Y8JN-JJC2X-F2786-YMVW3-3PBQP 
slmgr.vbs /ipk NKJWV-P2762-F83P7-3PF68-PJ8X2 
发表于 2014-1-21 17:53:00 | 显示全部楼层
FileDelete($KeyFileName)
 楼主| 发表于 2014-1-21 18:04:25 | 显示全部楼层
回复 3# auto

这个命令有什么问题吗?
文件用完,delete它 觉得很正常啊
 楼主| 发表于 2014-1-21 18:07:06 | 显示全部楼层
回复 3# auto

经试验,注释掉这行就ok了,果然高手啊
但是不明白为什么
发表于 2014-1-21 23:08:31 | 显示全部楼层
回复 4# hnfeng

这个命令没什么问题
    实际上你文件打开模式和关闭都有问题。FIELCLOSE函数用法不对啊
$ff = FileOpen($KeyFileName)
FileClose($ff)
 楼主| 发表于 2014-1-22 08:06:06 | 显示全部楼层
回复 6# auto


    明白了,多谢指导
发表于 2014-1-24 09:05:20 | 显示全部楼层
谢谢分享!学习了
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 11:44 , Processed in 0.086224 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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