本帖最后由 kingfirekkk 于 2011-1-13 10:42 编辑
像有些自己定义的UDF函数,如果执行一遍是没有问题,但再执行第二遍的时候,就会提示错误,如何解决这类问题?代码附后:
错误代码为:
C:\Users\Administrator\Desktop\GUISQL.au3 (66) : ==> ???????????.:
$data = $data & $array[$rows][$fields - 1]
$data = $data & $array^ ERROR
#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiStatusBar.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MYSQL.AU3>
Global $SERVER = '192.168.0.1'
Global $Dll, $today = today()
__MySQL_ExtractEmbeddedDLL()
_MySQL_InitLibrary()
$MysqlConn = _MySQL_Init()
Global $pass = "test"
Global $connected = _MySQL_Real_Connect($MysqlConn, $SERVER, "root", $pass, "test")
If $connected = 0 Then
$errno = _MySQL_errno($MysqlConn)
;~ MsgBox(0, "Error:", $errno & @LF & _MySQL_error($MysqlConn))
If $errno = $CR_UNKNOWN_HOST Then MsgBox(0, "Error:", "$CR_UNKNOWN_HOST" & @LF & $CR_UNKNOWN_HOST)
_MySQL_Close($MysqlConn)
_MySQL_EndLibrary()
;~ Exit
EndIf
$Form1 = GUICreate("数据库状态统计", 615, 438, 227, 160)
$Button1 = GUICtrlCreateButton("统计", 200, 296, 193, 49)
$Label1 = GUICtrlCreateLabel("今日写入数据总笔数:", 112, 120, 124, 17)
$Label2 = GUICtrlCreateLabel("", 240, 120, 36, 17)
$Label3 = GUICtrlCreateLabel("今日张三写入数据总笔数:", 88, 144, 148, 17)
$Label4 = GUICtrlCreateLabel("今日李四写入数据总笔数:", 88, 168, 148, 17)
$Label5 = GUICtrlCreateLabel("", 240, 144, 36, 17)
$Label6 = GUICtrlCreateLabel("", 240, 168, 36, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Sleep(1000)
GUICtrlSetData($Label2,p_L1())
GUICtrlSetData($Label5,c_zs())
GUICtrlSetData($Label6,c_ls())
EndSwitch
WEnd
Func P_L1()
;****************统计今日数据;****************
_MySQL_Real_Query($MysqlConn, "SELECT count(DISTINCT name) FROM mbtest WHERE 'timedate' like '2010-12-27%';")
$res = _MySQL_Store_Result($MysqlConn)
_MySQL_Store_Result($MysqlConn)
$fields = _MySQL_Num_Fields($res)
$rows = _MySQL_Num_Rows($res)
$array = _MySQL_Fetch_Result_StringArray($res)
$data = ""
$data = $data & $array[$rows][$fields - 1]
Return $data
EndFunc ;==>P_L1
Func C_Zs()
;****************统计今日数据;****************
_MySQL_Real_Query($MysqlConn, "SELECT count( DISTINCT `name` ) FROM mbtest where `Timedate` like '" & $today & "%' and `name` like 张三';")
$res = _MySQL_Store_Result($MysqlConn)
_MySQL_Store_Result($MysqlConn)
$fields = _MySQL_Num_Fields($res)
$rows = _MySQL_Num_Rows($res)
$array = _MySQL_Fetch_Result_StringArray($res)
$data = ""
$data = $data & $array[$rows][$fields - 1]
Return $data
EndFunc ;==>C_Zs
Func C_ls()
;****************统计今日数据;****************
_MySQL_Real_Query($MysqlConn, "SELECT count( DISTINCT `name` ) FROM mbtest where `Timedate` like '" & $today & "%' and `name` like '李四';")
$res = _MySQL_Store_Result($MysqlConn)
_MySQL_Store_Result($MysqlConn)
$fields = _MySQL_Num_Fields($res)
$rows = _MySQL_Num_Rows($res)
$array = _MySQL_Fetch_Result_StringArray($res)
$data = ""
$data = $data & $array[$rows][$fields - 1]
;~ GUICtrlSetData($Label6, $data)
Return $data
EndFunc ;==>C_ls
Func today()
Return @YEAR & "-" & @MON & "-" & @MDAY
EndFunc ;==>today
另外:有没有函数或者代码能够实现复位的功能,让代码重新从头开始执行或者像批处理那样,能够定义到任何标签定位的位置? |