Jump to content

Error - Nested "With" not alowed


Recommended Posts

Hello,

This is my first post here even if i read the forum a lot in the last week or so since i discovered AutoIt. I made a small app the works (most of the time). The problem is that every few records it gives this error : 'Nested "with" not allowed' then hangs Excel and the app itself.

Even if i want to add more thing to the app to ease my work i cant really point my finger on the problem i have now.

If anyone has at least a hint please let me know.

Thank you.

PS. The error happens when after i click one of the Save Buttons. (During sending the data to the excel file since it does not get to the save part...)

Save buttons functions are to submit data to excel cells and then save the excel file after every record submitted.

The source code is attached here since this is a non-commercial app and it's just for usage in our group.

These are the buttons and the functions called by the buttons :

Buttons

Func SaveClearClick()
WriteToFile()
If GUICtrlRead($ASexcel) =1 then SaveExcel()
ClearAfterSave()
GUICtrlSetData($rentpr,"")
GUICtrlSetState($rentpr,$Gui_Show)
GUICtrlSetData($salepr,"")
GUICtrlSetState($salepr,$Gui_Show)
GUICtrlSetData($StartRow,GUICtrlRead($StartRow)+1)
GUICtrlSetState($StartRow,$Gui_Show)
RefLabelClick()
EndFunc

Func SaveKeepClick()
WriteToFile()
If GUICtrlRead($ASexcel) =1 then SaveExcel()
GUICtrlSetData($rentpr,"")
GUICtrlSetState($rentpr,$Gui_Show)
GUICtrlSetData($salepr,"")
GUICtrlSetState($salepr,$Gui_Show)
GUICtrlSetData($StartRow,GUICtrlRead($StartRow)+1)
GUICtrlSetState($StartRow,$Gui_Show)
RefLabelClick()
EndFunc

Functions

Func WriteToFile()
;WRITE TO EXCEL

_ExcelWriteCell($oExcel, GUICtrlRead($address), $CurRow, 2)

_ExcelWriteCell($oExcel, GUICtrlRead($postcode), $CurRow, 3)
_ExcelWriteCell($oExcel, GUICtrlRead($category), $CurRow, 4)
_ExcelWriteCell($oExcel, GUICtrlRead($size), $CurRow, 5)
_ExcelWriteCell($oExcel, GUICtrlRead($rentpr), $CurRow, 6)
_ExcelWriteCell($oExcel, GUICtrlRead($salepr), $CurRow, 7)
_ExcelWriteCell($oExcel, GUICtrlRead($heading), $CurRow, 8)
_ExcelWriteCell($oExcel, GUICtrlRead($desc), $CurRow, 9)
_ExcelWriteCell($oExcel, GUICtrlRead($img1), $CurRow, 10)
_ExcelWriteCell($oExcel, GUICtrlRead($img2), $CurRow, 11)
_ExcelWriteCell($oExcel, GUICtrlRead($img3), $CurRow, 12)
_ExcelWriteCell($oExcel, GUICtrlRead($img4), $CurRow, 13)
_ExcelWriteCell($oExcel, GUICtrlRead($img5), $CurRow, 14)
_ExcelWriteCell($oExcel, GUICtrlRead($UnderOffer), $CurRow, 15)
_ExcelWriteCell($oExcel, GUICtrlRead($ReFABC)&GUICtrlRead($ReF123), $CurRow, 1)
MsgBox(0, "DONE", "DATA SENT TO EXCEL!", 1)
;If GUICtrlRead($ASexcel) =1 then SaveExcel()

EndFunc

Func SaveExcel()
;SAVE EXCEL FILE
_ExcelBookSave($oExcel) ;Save File With No Alerts
If @error Then MsgBox(0, "ERROR", "File Was NOT Saved!", 3)
$LastRow=$CurRow
$CurRow=$CurRow+1

EndFunc

Thank you !

AutoAddv3.au3

Edited by BlueMonkUK
Link to comment
Share on other sites

Hi BlueMonkUK, and Welcome!

I was just able to save 40+ records, changing various fields and values along the way, and everything seems to work fine. Do you know how to reproduce the problem, perhaps specific entries and options to use?

I had to change the following lines to still show me the MsgBox but not exit so I could get the script to continue to run for me:

$AuthCode = Label16Click()
If $AuthCode <> $AuthPC And $AuthCode <> $AuthPCLiviu Then
    Msgbox (0,"FATAL ERROR", "Runtime files not found. Error code:" & $AuthCode)
;~  Exit
EndIf

Then, I changed code starting at around line 200 to create a new Excel workbook, since you haven't posted the workbook you are using:

$oExcel = ObjGet("","Excel.Application")
if @error then
 Msgbox (0,"ExcelFileTest","You don't have Excel running at this moment. Error code: " & hex(@error,8))
 $oExcel = _ExcelBookNew()
;~   exit
endif

If you do the same and use a new workbook are you able to reproduce the error then post what you did?

Link to comment
Share on other sites

Welcome to the AutoIt forums.

There is a couple of issues with With in AutoIt: it doesn't use a stack but apparently a single fixed internal variable. It isn't a block construct either (you can do a With in one function and an EndWith in another function).

Since With is only synctatic sugar, you can make your own copy of the Excel UDF (call it _Excel) not using With at all.

Now since you have (from what I can see in a quick glance) asynchronous OnEvent operations using calls to the Excel UDF (several function use With) and an autosave feature also using a function using With, it's quite possible that one of them is taking control after a With is encountrred in another function, giving two With encountered in a row without an intervening EndWith.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

Solved. I thing i'm losing my mind :huh2: The problem was the Excel template. I don't know what the problem was but by creating a new file it works wonders.

Thank you for the create part. ;) I added that too :ph34r:

If anyone has any use for the code fell free to use it as you wish as long as you credit for it this forum.

:alien:

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