本帖最后由 austere 于 2014-9-13 13:48 编辑
运行程序后如图,选择取消,测试程序一切正常,如果随便选择一个文件打开后,则程序测试无响应。。请教一下是什么原因造成的,求修正~~~
代码如下:#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $zhucaidan
If Not FileExists(".\123.mdb") Then
data()
EndIf
FileOpenDialog("请选择您要打开的文件", "", "任意文件 (*.*)")
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 429, 193, 218, 137)
$Input1 = GUICtrlCreateInput("", 72, 80, 201, 21)
$Input2 = GUICtrlCreateInput("Input2", 72, 120, 201, 21)
$Button1 = GUICtrlCreateButton("读取内容", 304, 80, 75, 25)
$Button2 = GUICtrlCreateButton("写入内容", 304, 120, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
MsgBox(0,0,$zhucaidan)
du()
GUICtrlSetData($Input1, $zhucaidan)
Case $Button2
$xieru = GUICtrlRead($Input2)
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=123.mdb")
$addfld.execute("update ignorant set zhucaidan='" & $xieru & "' WHERE id = 1")
$addfld.close
MsgBox(4096, " 提示: ", @CRLF & " 写入成功!!! ")
EndSwitch
WEnd
Func du()
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=123.mdb")
$RS = ObjCreate("ADODB.Recordset")
$RS.ActiveConnection = $addfld
$RS.Open("Select * From ignorant where id = 1")
$zhucaidan = $RS.Fields(1).value
$RS.close
$addfld.Close
EndFunc ;==>du
Func data()
If Not FileExists("123.mdb") Then
$newMdb = ObjCreate("ADOX.Catalog")
$newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=123.mdb")
$newMdb.ActiveConnection.Close;建数据库
$addtbl = ObjCreate("ADODB.Connection")
$addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=123.mdb")
$addtbl.Execute("CREATE TABLE ignorant")
$addtbl.Close;建表
$addfld = ObjCreate("ADODB.Connection")
$addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=123.mdb")
$addfld.Execute("ALTER TABLE ignorant ADD id identity(1, 1) primary key ,zhucaidan text ")
$addfld.Execute("insert into ignorant (zhucaidan) values('123')")
$addfld.Close;建列表名
; MsgBox(64, " 提示:", @CRLF & "建立数据库成功", 5)
Else
MsgBox(64, " 提示:", @CRLF & "你已经建立了一个数据库了....", 5)
EndIf
EndFunc ;==>data
|