Downloading files

[quote=88354:@Charles Fasano]That didn’t quite work. I got a NilObjectException on the:

ProgressBar.Maximum = totalBytes
part.

I know that. I was putting what the object is, not what I am calling it.[/quote]

It’s not the name of the ProgressBar. It would not compile and you would get a “This object does not exist”. I gather httpDownload is correctly initialized as your code has to be in ReceiveProgress to execute, so if the event fires, the httpDownload cannot be nil. The Nil object exception probably refers to totalBytes.

Are you sure the URL of your file is valid ? Have you tried it in a browser to see if it initiates a download ?

The URL is valid as when I get the NilObjectException the totalBytes has a number that does equal the file size. It downloads about 12KB before I get the error.

Right… I wasn’t thinking of it in the right context…

I’ve never seen a nilObjectException on an Integer… but perhaps.

I’m wondering if the window is still open when this occurs (or more likely, not finished opening). You could get a nil object if the window is closing, but the socket keeps a reference to the now nil progressbar… or if the window hasn’t created it yet…

Could be an order of execution problem… ie
window creates the socket
socket downloads the file in the socket.open event (synchronously)
progressbar is then created (but this never happens due to the error)

Check the contents of the window in the debugger and be sure the progressbar has a valid handle property when the nilobjectexception occurs.

OK. You do not help much by keeping your code sequestered. Without your project, none of us can help beyond asking questions. It can be anything and frankly, it is getting a little tedious to tell you what to do, to test here the solutions, or post code as Tim did immediately , and still get the same “it’s not working here” answer without a clue. This is making a charade out of a bug that we could spot in an instant given a chance to see the code and run it. You made your “All I want to do is download a file from the internet” last now for a week. The error you get can be anything. As we use to say “Garbage in, Garbage out”. Spending hours on an ill conceived program and attempt modifications without a clear understanding of what you do is a waste of time.

Have you at least tried the working project Paul Lefebvre posted above yesterday 4 hours before your last post ? Stop trying to fix your monster and start from his valid code. Then you can build on a solid foundation.

You are right. I must be tired as well. Then it is most probably httpSocket that turns nil for whatever reason. But as I stated above in this post, it is about time to stop conjecturing about unknown code and move on. I will now stop wondering if the cat is still alive in Shrödinger’s box.

This is the code I am using:

prbDownload.Maximum = totalBytes prbDownload.Value = bytesReceived
The error happens on totalBytes.

I feel like an idiot right now. The problem WAS that I was trying to close the Download Window. I didn’t realize that it was trying to do that before the Download was done. Once I stopped the Download Windows from closing, it worked properly.

Sorry for the mess I caused. Teach me for trying to write code at 3:00 in the morning.

[quote=88547:@Charles Fasano]This is the code I am using:

prbDownload.Maximum = totalBytes prbDownload.Value = bytesReceived
The error happens on totalBytes.[/quote]

[quote=88550:@Charles Fasano]I feel like an idiot right now. The problem WAS that I was trying to close the Download Window. I didn’t realize that it was trying to do that before the Download was done. Once I stopped the Download Windows from closing, it worked properly.
Sorry for the mess I caused. Teach me for trying to write code at 3:00 in the morning.[/quote]

I was going to tell you that your two lines of code where totally useless to guess what could have caused the error. Which you now understand why. It was not in the lines but elsewhere.

Next time you encounter issues, please post all relevant code, or better yet, put your project for download so we can analyse it and help.

Glad to read you finally caught the bug.

NB : You can still get rid of the window on the screen with window.visible = false, which does not stop execution.

The problem code happened much later on. I thought it would finish the HTTPSocket.Get first then continue executing code. I guess not.

The way my game starts off is that it checks to make sure the “data.dat” file exists and if not it asks the user to download a new copy. I still have work to do since if the file did exist, the download window needs to close and open the Main window without downloading anything. The “data.dat” file will be constantly updated as new stuff is added to the game.

I’ve reworked my code a bit so that the Window.Close is in a separate method that is only called either upon download completion or if the file already exits where it’s supposed to. This way it won’t prematurely close the Window like I was mistakenly doing before. I’ve got a lot to learn still but thanks for all of the help.

Another option is to have the downloads happening separately, not within windows. And only have windows checking on their progress. This way you can have a dismisable “activity” window that doesn’t interfere with your download progress.

I’m glad to see that you’ve got it worked out!

I will mention that my commercial package Activity Viewer has a socket subclass that handles progress display, pause/resume, and proxy resolution and is very simple to implement… if you’re interested.

[quote=89769:@jim mckay]I’m glad to see that you’ve got it worked out!

I will mention that my commercial package Activity Viewer has a socket subclass that handles progress display, pause/resume, and proxy resolution and is very simple to implement… if you’re interested.[/quote]

I’ve been looking for an excuse for a while to use your activity viewer :smiley: Looks so interesting…