Jump to content

Please help me


Recommended Posts

My code is below, it cann't run correctly. I don't know why. Who can help me? Thanks!

the events of recordset is new added, I think the error is here.

when i run it , the code can run to the loop of While, but when a new Record is added, the Function of event is not actived.

$sChkOutSer = IniRead("autochkoutclient.ini", "server", "chkoutser", "shuaka")
$nChkOutPort = IniRead("autochkoutclient.ini", "server", "chkoutport", "33892")
$wx2004 = IniRead("autochkoutclient.ini", "server", "wx2004", "d:\wx2004")

$dbname = $wx2004 & "\2004Rec.mdb"
$tblname = "tLogs"
$sDbPassword = "zhrmghg1949jgqz"
;$fldname1 = "dtTime1"
;$fldname2 = "dtTime2"
;$fldname3 = "sCom"

TCPStartUp()
Dim $szIPADDRESS = TCPNameToIP($sChkOutSer)
Dim $ConnectedSocket = -1

$adoCon = ObjCreate ("ADODB.Connection")


$adocon.open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname &"; Jet OLEDB:Database Password="& $sDbPassword)
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 2
$adoRs.LockType = 3
$adoRs.Open ("SELECT * FROM " & $tblname &" ORDER BY  dtTime2,dtTime1 DESC", $adoCon)
$EventObject=ObjEvent($adoRs,"DbEvent_","RecordSetEvents"); Start receiving Events.
if @error then 
   Msgbox(0,"AutoIt COM Test", "ObjEvent: Can't use event interface 'RecordsetEvent'. Error code: " & hex(@error,8))
   exit
endif

while 1
    sleep(100)
WEnd

$EventObject = 0
$adoRS.close
$adoCon.close

Exit

Func DbEvent_RecordChangeComplete($adRsnAddNew, $cRecords, $pError, $adStatus, $adoRs)
  $nRecNum = $adoRs.recordcount
  $n = 0
  Do 
    $n = $n + 1
        $adoRs.Move ($nRecNum-$cRecords+1)
      $bComNum = StringToBinary($adoRs.Fields(2).value,3)
      $ConnectedSocket = TCPConnect($szIPADDRESS,$nchkoutport)
      If @error Then
        MsgBox(4112,"Error","TCPConnect failed with WSA error: " & @error)
            Exit
        EndIf
        TCPSend($ConnectedSocket,$bComNum)
        If @error Then ExitLoop
        $adoRs.MovePrevious
    Until $n > $nAddRecNum
EndFunc
Link to comment
Share on other sites

For debugging, try using the following event processing code that should fire on any event of the recordSet and see if it is working at all:

$EventObject=ObjEvent($adoRs,"DbEvent_")

Func DbEvent_($s)
    ConsoleWrite("Event: " & $s & @CR)
EndFunc

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

For debugging, try using the following event processing code that should fire on any event of the recordSet and see if it is working at all:

$EventObject=ObjEvent($adoRs,"DbEvent_")

Func DbEvent_($s)
    ConsoleWrite("Event: " & $s & @CR)
EndFunc

Dale

First, If remove the "interface name" option, when run the code to this line will error.

Second, from your prompt, i update the code, but cann't run the events.

Please help me! thanks!

Link to comment
Share on other sites

If you are getting errors, please show your new code and the errors generated. If you make a habit of this in the future your answers will come much faster.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

If you are getting errors, please show your new code and the errors generated. If you make a habit of this in the future your answers will come much faster.

Dale

Thanks your advice, Dale.

My updated code is here:

$sChkOutSer = IniRead("autochkoutclient.ini", "server", "chkoutser", "shuaka")
$nChkOutPort = IniRead("autochkoutclient.ini", "server", "chkoutport", "33892")
$wx2004 = IniRead("autochkoutclient.ini", "server", "wx2004", "d:\wx2004")

$dbname = $wx2004 & "\2004Rec.mdb"
$tblname = "tLogs"
$sDbPassword = "zhrmghg1949jgqz"
;$fldname1 = "dtTime1"
;$fldname2 = "dtTime2"
;$fldname3 = "sCom"

TCPStartUp()
Dim $szIPADDRESS = TCPNameToIP($sChkOutSer)
Dim $ConnectedSocket = -1

$adoCon = ObjCreate ("ADODB.Connection")
$adocon.open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname &"; Jet OLEDB:Database Password="& $sDbPassword)
$adoRs = ObjCreate ("ADODB.Recordset")
$adoRs.CursorType = 2
$adoRs.LockType = 3
$adoRs.Open ("SELECT * FROM " & $tblname &" ORDER BY  dtTime2,dtTime1 DESC", $adoCon)

$EventObject=ObjEvent($adoRs,"DbEvent_")  ; Start receiving Events.
if @error then 
   Msgbox(0,"AutoIt COM Test", "ObjEvent: Can't use event interface 'RecordsetEvent'. Error code: " & hex(@error,8))
   exit
endif

while 1
    sleep(5)
WEnd

$EventObject = 0
$adoRS.close
$adoCon.close

Exit

Func DbEvent_($s)
    ConsoleWrite("Event: " & $s & @CR)
EndFunc

If run it, will popup one message: ObjEvent: Can't use event interface 'RecordsetEvent'. Error code: 80040200

Link to comment
Share on other sites

What happens if you explicitly specify the event? This creates a specific event for a record in the recordset being changed:

$sChkOutSer = IniRead("autochkoutclient.ini", "server", "chkoutser", "shuaka")
$nChkOutPort = IniRead("autochkoutclient.ini", "server", "chkoutport", "33892")
$wx2004 = IniRead("autochkoutclient.ini", "server", "wx2004", "d:\wx2004")

$dbname = $wx2004 & "\2004Rec.mdb"
$tblname = "tLogs"
$sDbPassword = "zhrmghg1949jgqz"
;$fldname1 = "dtTime1"
;$fldname2 = "dtTime2"
;$fldname3 = "sCom"

TCPStartup()
Dim $szIPADDRESS = TCPNameToIP($sChkOutSer)
Dim $ConnectedSocket = -1

$adoCon = ObjCreate("ADODB.Connection")
$adoCon.open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & $dbname & "; Jet OLEDB:Database Password=" & $sDbPassword)
$adoRs = ObjCreate("ADODB.Recordset")
$adoRs.CursorType = 2
$adoRs.LockType = 3
$adoRs.Open("SELECT * FROM " & $tblname & " ORDER BY  dtTime2,dtTime1 DESC", $adoCon)

$EventObject = ObjEvent($adoRs, "DbEvent_", "WillChangeRecord") ; Start receiving WillChangeRecord Event.
If @error Then
    MsgBox(0, "AutoIt COM Test", "ObjEvent: Can't use event interface 'RecordsetEvent'. Error code: " & Hex(@error, 8))
    Exit
EndIf

; Add something here that changes a record in $adoRs...

While 1
    Sleep(5)
WEnd

$EventObject = 0
$adoRs.close
$adoCon.close

Exit

Func DbEvent_WillChangeRecord($adReason, $cRecord, $adStatus, $pRecordset)
    Local $sReason, $sStatus
    
    Switch $adReason
        Case 1
            $sReason = "A record is added"
        Case 2
            $sReason = "A record is deleted"
        Case 3
            $sReason = "A record is updated"
        Case 4
            $sReason = "An update is cancelled"
        Case 5
            $sReason = "An add is cancelled"
        Case 6
            $sReason = "A delete is cancelled"
        Case 11
            $sReason = "Any operation that makes the first change to a record"
        Case Else
            $sReason = "An unexpected event reason code was received."
    EndSwitch
    
    Switch $adStatus
        Case 1
            $sStatus = "The operation that fired the event was successful"
        Case 2
            $sStatus = "Indicates that warnings and/or errors occurred"
        Case 3
            $sStatus = "Cannot cancel pending operation"
        Case 4
            $sStatus = "Cancels the operation that fired the event"
        Case 5
            $sStatus = "The operation that generated the event cannot generate future events"
        Case Else
            $sStatus = "An unexpected event status code was received."
    EndSwitch
    
    ConsoleWrite("Debug: DbEvent_WillChangeRecord" & @LF & _
            @TAB & "$adReason = " & $adReason & @LF & _
            @TAB & "Reason translation: " & $sReason & @LF & _
            @TAB & "Record count affected: " & $cRecord & @LF & _
            @TAB & "$adStatus = " & $adStatus & @LF & _
            @TAB & "Status translation = " & $sStatus)
EndFunc   ;==>DbEvent_WillChangeRecord

I can't test it here, and it's not complete, in that to trigger the event you'll need to add code that changes some record data in the recordset.

As always, if that isn't helping, ignore it...

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...