找回密码
 加入
搜索
楼主: zhaoyun

[系统综合] [已解决]Error:变量类型必须为对象类型(“Object”),求大神帮忙解决

 火.. [复制链接]
发表于 2016-4-27 08:37:11 | 显示全部楼层
回复 14# zhaoyun
这样你试试看
; *** AutoIt3Wrapper 开始 ***
#include <ListBoxConstants.au3>
; *** AutoIt3Wrapper 结束 ***
#NoTrayIcon
#Region ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#AccAu3Wrapper_OutFile=120.exe
#AccAu3Wrapper_UseX64=n
#AccAu3Wrapper_Res_Language=2052
#AccAu3Wrapper_Res_requestedExecutionLevel=None
#AccAu3Wrapper_Add_Constants=Y
#EndRegion ;**** 由 AccAu3Wrapper_GUI 创建指令 ****
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$mdb_data_path = @ScriptDir & "\DB0.mdb"
$mdb_data_pwd = "test"
$T = "*"
$tblname = "mydb"
If Not FileExists($mdb_data_path) Then
        new()
Else
        MsgBox(0, '欢迎使用', '数据库已创建',1)
EndIf

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Access 操作实例", 520, 455, 553, 128)
$ListView1 = GUICtrlCreateListView("编号|姓名|性别|联系电话|", 5, 5, 310, 200, _
                BitOR($GUI_SS_DEFAULT_LISTVIEW, $WS_BORDER), _
                BitOR($WS_EX_CLIENTEDGE, $LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlSendMsg(-1, 0x101E, 0, 50)
GUICtrlSendMsg(-1, 0x101E, 1, 80)
GUICtrlSendMsg(-1, 0x101E, 2, 50)
GUICtrlSendMsg(-1, 0x101E, 3, 100)
$Group1 = GUICtrlCreateGroup("创建/读取/修改/删除", 5, 210, 310, 60)
GUICtrlSetColor(-1, 0x0000FF)
$Button1 = GUICtrlCreateButton("创建", 10, 235, 75, 25)
$Button2 = GUICtrlCreateButton("读取", 85, 235, 75, 25)
$Button3 = GUICtrlCreateButton("修改", 160, 235, 75, 25)
$Button4 = GUICtrlCreateButton(" 删除", 235, 235, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("添加/修改记录", 5, 275, 310, 135)
GUICtrlSetColor(-1, 0xFF00FF)
$Input1 = GUICtrlCreateInput("", 55, 295, 96, 21)
$Input3 = GUICtrlCreateInput("", 55, 355, 96, 21, 0X2000)
$Combo1 = GUICtrlCreateCombo("", 55, 325, 95, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "男|女")
$Label1 = GUICtrlCreateLabel("账户:", 15, 300, 31, 17)
$Label2 = GUICtrlCreateLabel("性别:", 15, 330, 31, 17)
$Label3 = GUICtrlCreateLabel("手机:", 20, 360, 31, 17, BitOR($GUI_SS_DEFAULT_INPUT, $ES_NUMBER))
$Input2 = GUICtrlCreateInput("", 210, 295, 91, 21)
$Input4 = GUICtrlCreateInput("", 210, 355, 91, 21, 0X2000)
$Combo2 = GUICtrlCreateInput("", 210, 325, 90, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
;GUICtrlSetData(-1, "男|女")
;$Label4 = GUICtrlCreateLabel("姓名:", 170, 300, 31, 17)
;$Label5 = GUICtrlCreateLabel("性别:", 170, 330, 31, 17)
;$Label6 = GUICtrlCreateLabel("手机:", 170, 360, 31, 17, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))
$Button5 = GUICtrlCreateButton("添加", 45, 380, 75, 25)
$Button6 = GUICtrlCreateButton("保存修改", 195, 380, 75, 25)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("查询", 5, 410, 310, 40)
$Input5 = GUICtrlCreateInput("", 95, 420, 121, 21)
$Button7 = GUICtrlCreateButton("查询", 225, 420, 75, 25)
$Label7 = GUICtrlCreateLabel("姓名// 性别:", 10, 425, 81, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###



If FileExists($mdb_data_path) Then du()


While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        If Not FileExists($mdb_data_path) Then
                                new()
                        Else
                                MsgBox(0, '欢迎使用', '数据库已创建')
                        EndIf
                Case $Button2
                        du()
                Case $Button3
                        $Strn = GUICtrlRead(GUICtrlRead($ListView1))
                        $Strnspin = StringSplit($Strn, "|")
                        If $Strnspin[1] = '0' Then
                                MsgBox(48, '提示', '请选择要更新的条目')
                        Else
                                up()
                        EndIf
                Case $Button4
                        $Strn = GUICtrlRead(GUICtrlRead($ListView1))
                        $Strnspin = StringSplit($Strn, "|")
                        If $Strnspin[1] = '0' Then
                                MsgBox(48, '提示', '请选择要删除的条目')
                        Else
                                del()
                                du()
                        EndIf
                Case $Button5
                        xie()
                Case $Button6
                        back()
                Case $Button7
                        xun()

        EndSwitch
WEnd

Func new()
        $newMdb = ObjCreate('ADOX.Catalog')
        $newMdb.Create("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $newMdb.ActiveConnection.Close;建数据库
        $addtbl = ObjCreate("ADODB.Connection")
        $addtbl.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addtbl.Execute("CREATE TABLE " & $tblname)
        $addtbl.Close;建表
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $addfld.Execute("ALTER TABLE " & $tblname & " ADD id identity(1, 1) primary key,name text(255) ,ssex text(50),qq text(255)");id identity(1, 1) primary key为自动编号和主键
        $addfld.Close;建列表名
        MsgBox(0, '提示:', '创建成功!!!',1)
EndFunc   ;==>new

Func du()
        GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select " & $T & " From " & $tblname)
        While Not $RS.eof And Not $RS.bof
                If @error = 1 Then ExitLoop
                GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value & "|" & $RS.Fields(3).value, $ListView1)
                $RS.movenext
        WEnd
        $RS.close
        $addfld.Close
EndFunc   ;==>du

Func up() ;更新数据库内的某条记录到修改窗口
        $Strn = GUICtrlRead(GUICtrlRead($ListView1))
        $Strnspin = StringSplit($Strn, "|")
        GUICtrlSetData($Input2, '')
        GUICtrlSetData($Input4, '')
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $RS = ObjCreate("ADODB.Recordset")
        $RS.ActiveConnection = $addfld
        $RS.Open("Select " & $t & " From " & $tblname & " WHERE id" & " = " & $Strnspin[1]) ;$t : 表示一个连接  $adtable :表示的是这个表的名称
        GUICtrlSetData($Input2, $RS.Fields(1).value)
        GUICtrlSetData($Combo2, $RS.Fields(2).value)
        GUICtrlSetData($Input4, $RS.Fields(3).value)
        $RS.movenext
        $RS.close
        $addfld.Close
EndFunc   ;==>up

Func del()
        $Strn = GUICtrlRead(GUICtrlRead($ListView1))
        $Strnspin = StringSplit($Strn, "|")
        $addfld = ObjCreate("ADODB.Connection")
        $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
        $sQuery = "DELETE FROM " & $tblname & " IN '" & $mdb_data_path & "' WHERE id" & " = " & $Strnspin[1]
        $addfld.execute($sQuery)
        $addfld.close
EndFunc   ;==>del

Func xie()
        If GUICtrlRead($Input1) <> '' And GUICtrlRead($Input3) <> '' Then
                $read1 = GUICtrlRead($Input1)
                $read2 = GUICtrlRead($Combo1)
                $read3 = GUICtrlRead($Input3)
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $addfld.execute("insert into " & $tblname & " (name,ssex,qq) values('" & $read1 & "','" & $read2 & "','" & $read3 & "')")
                $addfld.close
                du()
        Else
                MsgBox(48, '出错啦', '请检查输入是否完整')
        EndIf
EndFunc   ;==>xie

Func back()
        If GUICtrlRead($Input2) <> '' And GUICtrlRead($Input4) <> '' Then
                $read4 = GUICtrlRead($Input2)
                $read5 = GUICtrlRead($Combo2)
                $read6 = GUICtrlRead($Input4)
                $Strn = GUICtrlRead(GUICtrlRead($ListView1))
                $Strnspin = StringSplit($Strn, "|")
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $addfld.execute("update " & $tblname & " set  name='" & $read4 & "',ssex='" & $read5 & "',qq='" & $read6 & "' WHERE id" & " = " & $Strnspin[1])
                $addfld.close
                du()
                GUICtrlSetData($Input2, '')
                GUICtrlSetData($Input4, '')
        Else
                MsgBox(48, '出错啦', '请检查输入是否完整')
        EndIf
EndFunc   ;==>back

Func xun()
        If Not GUICtrlRead($Input5) = '' Then
                $read10 = GUICtrlRead($Input5)
                GUICtrlSendMsg($ListView1, $LVM_DELETEALLITEMS, 0, 0)
                $addfld = ObjCreate("ADODB.Connection")
                $addfld.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $mdb_data_path & ";Jet Oledb:Database Password=" & $mdb_data_pwd)
                $RS = ObjCreate("ADODB.Recordset")
                $RS.ActiveConnection = $addfld
                $RS.open("SELECT * FROM " & $tblname & " WHERE name='" & $read10 & "' OR ssex='" & $read10 & "'")
                While Not $RS.eof And Not $RS.bof
                        If @error = 1 Then ExitLoop
                        GUICtrlCreateListViewItem($RS.Fields(0).value & "|" & $RS.Fields(1).value & "|" & $RS.Fields(2).value & "|" & $RS.Fields(3).value, $ListView1)
                        $RS.movenext
                WEnd
                $RS.close
                $addfld.close
        Else
                MsgBox(48, '出错啦', '你需要输入一个关键字')
        EndIf
EndFunc   ;==>xun
 楼主| 发表于 2016-4-27 09:30:02 | 显示全部楼层
回复 16# chzj589

谢了 解决了
发表于 2016-4-27 15:06:01 | 显示全部楼层
回复 16# chzj589

你改了什麼???
发表于 2016-4-27 18:25:47 | 显示全部楼层
回复 18# kk_lee69

把创建数据库放在最前面,
$mdb_data_path = @ScriptDir & "\DB0.mdb"
$mdb_data_pwd = "test"
$T = "*"
$tblname = "mydb"
If Not FileExists($mdb_data_path) Then
        new()
Else
        MsgBox(0, '欢迎使用', '数据库已创建',1)
EndIf
创建数据库代码改为qq text(255)
发表于 2016-4-28 17:20:51 | 显示全部楼层
回复 19# chzj589

了解
发表于 2016-4-30 22:15:08 | 显示全部楼层
回复 17# zhaoyun


    解決了請修改標題
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-15 11:45 , Processed in 0.068810 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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