Jump to content

Nested "With" statements are not allowed


ACalcutt
 Share

Recommended Posts

Hello eveyone,

I am trying to use the attached AccessCom.au3 udf that is attached in my Vistumbler program (www.vistumbler.net). It is based on the work here (http://www.autoitscript.com/forum/index.php?showtopic=32144)

Mostly it works well, but I am getting a random error sometimes when i load a data file into the database

The error I am getting is this

C:\Users\ACalcutt\Documents\Vistumbler\VistumblerMDB\AccessCom.au3 (373) : ==> Nested "With" statements are not allowed.:

With $o_adoRs

^ ERROR

What is a "nested with" and how do i fix this error. Does anyone have any idea how i can fix this?

The function that it is getting this error from is this one

Func _RecordSearch($s_dbname, $_query, ByRef $o_adoCon, $i_adoMDB = 1, $USRName = "", $PWD = "")
    If Not IsObj($o_adoCon) Then
        _AccessConnectConn($s_dbname, $o_adoCon, $i_adoMDB, $USRName, $PWD)
        $i_NeedToCloseInFunc = 1
    Else
        $i_NeedToCloseInFunc = 0
    EndIf
    $o_adoRs = ObjCreate("ADODB.Recordset")
    $o_adoRs.CursorType = 1
    $o_adoRs.LockType = 3
    $o_adoRs.Open($_query, $o_adoCon)
    With $o_adoRs
        Dim $_output[.RecordCount + 1][.Fields.Count + 1]
        $_output[0][0] = .RecordCount
        For $i = 1 To .Fields.Count
            $_output[0][$i] = .Fields($i - 1).Name
        Next
        If $o_adoRs.RecordCount Then
            $z = 0
            While Not .EOF
                $z = $z + 1
                For $x = 1 To .Fields.Count
                    $_output[$z][$x] = .Fields($x - 1).Value
                Next
                .MoveNext
            WEnd
        EndIf
    EndWith
    $o_adoRs.Close
    If $i_NeedToCloseInFunc Then $o_adoCon.Close
    Return $_output
EndFunc ;==>_RecordSearch

The latest version of vistumbler that uses this UDF is here (http://forum.techidiots.net/forum/viewtopic.php?f=26&t=126)

Example data can be found here...though this is a big list of data (http://forum.techidiots.net/forum/viewtopic.php?f=16&t=131)

AccessCom.au3

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

I am guessing that within a With/EndWith you are calling a function that itself has a With/EndWith

With

FuncCall()

EndWith

Func FuncCall

With

EndWith

EndFunc

Perhaps that is throwing the nested With. I am sure nested Withs are possible... just not implemented. So With/EndWith should be used minimally just too cut down on redundancy.

Lar.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Link to comment
Share on other sites

anybody have any other suggestions?

Maybe there are Withs inside With but we don't see them.

Try this code to see that there are Withs out there...

$obj = ObjCreate("Shell.Application")
    
    $obj.NameSpace(@ScriptDir).CopyHere($obj.NameSpace(@ScriptDir & "abc").ParseName(""), 0)

Error is intentional

You should get "blah, blah... Object referenced outside a "With" statement..."

Link to comment
Share on other sites

Maybe there are Withs inside With but we don't see them.

Try this code to see that there are Withs out there...

$obj = ObjCreate("Shell.Application")
    
    $obj.NameSpace(@ScriptDir).CopyHere($obj.NameSpace(@ScriptDir & "abc").ParseName(""), 0)

Error is intentional

You should get "blah, blah... Object referenced outside a "With" statement..."

I made a copy of _RecordSearch() and called it _RecordSearch2()...right above the "with" that keeps having problems I put that code. i replaced each _RecordSearch() reference to _RecordSearch2() in my import function one at a time.

every time it came up as the error it should have

>Running:(3.2.12.1):C:\Program Files\AutoIt3\autoit3.exe "C:\Users\Andrew\Desktop\VistumblerMDB\Vistumbler.au3"

C:\Users\Andrew\Desktop\VistumblerMDB\AccessCom.au3 (408) : ==> Object referenced outside a "With" statement.:

$obj.NameSpace(@ScriptDir).CopyHere($obj.NameSpace(@ScriptDir & "abc" ).ParseName(""), 0)

$obj.NameSpace(@ScriptDir).CopyHere($obj.NameSpace(@ScriptDir & "abc" )^ ERROR

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

I made a copy of _RecordSearch() and called it _RecordSearch2()...right above the "with" that keeps having problems I put that code. i replaced each _RecordSearch() reference to _RecordSearch2() in my import function one at a time.

every time it came up as the error it should have

I don't get your point.

What is your point?

That little code was supposed to be an example of "With" showing up as (in) error without using "With... EndWith" in our code. It has nothing to do with AccessCom.au3

As for your original problem...

Try removing "With... EndWith" knowing that (for example):

With $o_adoRs
    $r_count = .RecordCount
    $f_count = .Fields.Count
EndWith

is the same as:

$r_count = $o_adoRs.RecordCount
$f_count = $o_adoRs.Fields.Count

Maybe it helps and than again...

Edited by trancexx
Link to comment
Share on other sites

Hmmm maybe i misunderstood what that code was supposed to do. From what i gather it tells you if that code in inside a with.

I put it into AccessCom.au3 because that is where I am getting the nested with error.

I put it right before the line the gets the nested with error (in AccessCom.au3) and every time it was called it said it was not inside a with.

I will try out your other suggestion

Thanks

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

Link to comment
Share on other sites

Ok...

I replaced this

Func _RecordSearch($s_dbname, $_query, ByRef $o_adoCon, $i_adoMDB = 1, $USRName = "", $PWD = "")
    If Not IsObj($o_adoCon) Then
        _AccessConnectConn($s_dbname, $o_adoCon, $i_adoMDB, $USRName, $PWD)
        $i_NeedToCloseInFunc = 1
    Else
        $i_NeedToCloseInFunc = 0
    EndIf
    $o_adoRs = ObjCreate("ADODB.Recordset")
    $o_adoRs.CursorType = 1
    $o_adoRs.LockType = 3
    $o_adoRs.Open($_query, $o_adoCon)
    With $o_adoRs
        Dim $_output[.RecordCount + 1][.Fields.Count + 1]
        $_output[0][0] = .RecordCount
        For $i = 1 To .Fields.Count
            $_output[0][$i] = .Fields($i - 1).Name
        Next
        If $o_adoRs.RecordCount Then
            $z = 0
            While Not .EOF
                $z = $z + 1
                For $x = 1 To .Fields.Count
                    $_output[$z][$x] = .Fields($x - 1).Value
                Next
                .MoveNext
            WEnd
        EndIf
    EndWith
    $o_adoRs.Close
    If $i_NeedToCloseInFunc Then $o_adoCon.Close
    Return $_output
EndFunc ;==>_RecordSearch

With This

Func _RecordSearch($s_dbname, $_query, ByRef $o_adoCon, $i_adoMDB = 1, $USRName = "", $PWD = "")
    If Not IsObj($o_adoCon) Then
        _AccessConnectConn($s_dbname, $o_adoCon, $i_adoMDB, $USRName, $PWD)
        $i_NeedToCloseInFunc = 1
    Else
        $i_NeedToCloseInFunc = 0
    EndIf
    $o_adoRs = ObjCreate("ADODB.Recordset")
    $o_adoRs.CursorType = 1
    $o_adoRs.LockType = 3
    $o_adoRs.Open($_query, $o_adoCon)
    $r_count = $o_adoRs.RecordCount
    $f_count = $o_adoRs.Fields.Count
    
    Dim $_output[$r_count + 1][$f_count + 1]
    $_output[0][0] = $r_count
    For $i = 1 To $f_count
        $_output[0][$i] = $o_adoRs.Fields($i - 1).Name
    Next
    
    If $r_count Then
        $z = 0
        While Not $o_adoRs.EOF
            $z = $z + 1
            For $x = 1 To $f_count
                $_output[$z][$x] = $o_adoRs.Fields($x - 1).Value
            Next
            $o_adoRs.MoveNext
        WEnd
    EndIf
    $o_adoRs.Close
    If $i_NeedToCloseInFunc Then $o_adoCon.Close
    Return $_output
EndFunc ;==>_RecordSearch

It's still importing, so it looks like i did it right... I'll see if i still get random errors with this (it should no longer get a nested with error at least...since there is no with)

Edited by ACalcutt

Andrew Calcutt

Http://www.Vistumbler.net

Http://www.TechIdiots.net

Its not an error, its a undocumented feature

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...