[已解决]代码什么错误?只能运行一次。
本帖最后由 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
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, "({5}-){4}{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, "({5}-){4}{5}", 2)
If Not @error Then
$K = $Key
$Array_KeyS[$KeyS] = $K
;_ArrayDisplay($Array_KeyS)
$KeyS += 1
EndIf
WEnd
EndIf
FileClose($KeyFileName)
Return $KeyS
EndFunc ;==>_GetKey
供测试用来输入用的::
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.
:
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).
:
slmgr.vbs /ipk BJKP6-NDDC9-W9X7H-MMMTD-TCKVC
slmgr.vbs /ipk 9Y8JN-JJC2X-F2786-YMVW3-3PBQP
slmgr.vbs /ipk NKJWV-P2762-F83P7-3PF68-PJ8X2
FileDelete($KeyFileName) 回复 3# auto
这个命令有什么问题吗?
文件用完,delete它 觉得很正常啊 回复 3# auto
经试验,注释掉这行就ok了,果然高手啊
但是不明白为什么 回复 4# hnfeng
这个命令没什么问题
实际上你文件打开模式和关闭都有问题。FIELCLOSE函数用法不对啊
$ff = FileOpen($KeyFileName)
FileClose($ff) 回复 6# auto
明白了,多谢指导 谢谢分享!学习了
页:
[1]