Please help

I am having a problem which has been driving me mad for days now, can someone please help me out here.
I have the below code working…
[lua] pathToDownload = system.pathForFile( “image”…i…".jpg", system.DocumentsDirectory )
myFile = io.open( pathToDownload, “w+b” )

for row in db:nrows(“SELECT * FROM products WHERE mobileId = '”…i…"’ AND colourof = ‘’") do

http.request{
url = “http://www.seltex.co.uk/library/gallery/pic_compression.php?id="..row.id.."&size=100”,
sink = ltn12.sink.file(myFile),
}

end[/lua]
But this is not the way I need it to work, I need the io.open line inside that for loop like I have done below, but for some reason this causes an error and I just cant figure out what the problem is
[lua] pathToDownload = system.pathForFile( “image”…i…".jpg", system.DocumentsDirectory )

for row in db:nrows(“SELECT * FROM products WHERE mobileId = '”…i…"’ AND colourof = ‘’") do
myFile = io.open( pathToDownload, “w+b” )
http.request{
url = “http://www.seltex.co.uk/library/gallery/pic_compression.php?id="..row.id.."&size=100”,
sink = ltn12.sink.file(myFile),
}

end[/lua] [import]uid: 119673 topic_id: 22704 reply_id: 322704[/import]

What is the error message?

Are you trying to download a single file or multiple files?

Where is “i” being incremented?
[import]uid: 19626 topic_id: 22704 reply_id: 90575[/import]

If you are opening multiple files, you’d better close that file handler at some point. [import]uid: 70391 topic_id: 22704 reply_id: 90587[/import]

@green.castle, I believe the sink closes the the file when its done downloading. [import]uid: 19626 topic_id: 22704 reply_id: 90592[/import]

@green.castle, I believe the sink closes the the file when its done downloading. [import]uid: 19626 topic_id: 22704 reply_id: 90593[/import]

i is being incremented inside another for loop which this code is within

I cant remember the error, will check when I get home from work [import]uid: 119673 topic_id: 22704 reply_id: 90719[/import]

Sorry for the long delay, hopefully someone can still help me. I have pasted the error below.

Copyright © 2009-2012 A n s c a , I n c .
Version: 2.0.0
Build: 2012.766
The file sandbox for this project is located at the following folder:
(/Users/macuser/Library/Application Support/Corona Simulator/Seltex DB-76CD6AC788A4E1112911330E00863587)
WARNING: Failed to find image(image3.jpg)
Runtime error
/Users/macuser/Desktop/Seltex DB/first.lua:78: attempt to index local ‘rect’ (a nil value)
stack traceback:
[C]: ?
/Users/macuser/Desktop/Seltex DB/first.lua:78: in function
?: in function ‘dispatchEvent’
?: in function ‘gotoScene’
/Users/macuser/Desktop/Seltex DB/main.lua:5: in main chunk
Runtime error: /Users/macuser/Desktop/Seltex DB/first.lua:78: attempt to index local ‘rect’ (a nil value)
stack traceback:
[C]: ?
/Users/macuser/Desktop/Seltex DB/first.lua:78: in function
?: in function ‘dispatchEvent’
?: in function ‘gotoScene’
/Users/macuser/Desktop/Seltex DB/main.lua:5: in main chunk
[import]uid: 119673 topic_id: 22704 reply_id: 93360[/import]

Well here is the error:

/first.lua:78: attempt to index local ‘rect’ (a nil value)

It is in the file first.lua at line 78.

You are referencing a variable called rect and are trying to do something with it, however it’s nil/empty.

[import]uid: 19626 topic_id: 22704 reply_id: 93373[/import]

Yes! Thank you, That has helped me a lot. Much appreciated! [import]uid: 119673 topic_id: 22704 reply_id: 93392[/import]