I have two/1 problems that when you compound them they get rather interesting/irritating. My internet connection is whacky. Sometimes I can be connected 24-48 straight hours and not get disconnected, other times I connect and get disconnected 5 seconds later. You never know what to expect one minute to the next. Also I never know what speed to expect, it maybe 1-2Kb/s or it maybe 500-600 Kb/s. Again, you never know what to expect. This is causing all kinds of havoc with my program when it goes to download the weather maps. At times it goes through and it grabs all of them without blinking an eye other times I end up getting disconnected from the internet while downloading(Timed out) or get the connection with the server dropped(Unable to complete request).

I've decided since I have everything else right now somewhat stable to see if I can eliminate these issues. I think I have the detection of the internet signal taken care of but I know from testing, with the slow connection, that I still can get the Unable to complete request...it happened earlier this morning.

It appears the Unable to complete request is always coming from a dropped connection with the server, even though it might be a dropped connection with my ISP(I still have connection to the internet when I get the error. I can stop the program and restart it and it will continue on downloading.)

What I want to have happen is for it to check before it goes to download any image, it first checks the internet connection to make sure it's present. Then if it loses the internet connection(server connection, especially) it will automatically go back up and rerun the code and try to make the connection again and continue on downloading. I may put something in place for setting a limit on the number of times that it will go back up and check but right now I'm just more interested in the harder part...getting it to go back up and rerun the code to download again when it would otherwise come up with Unable to complete request.

One thing I have really never understood that well is error trapping. From looking at old message I see you can trap the message but I'm still unsure as to how to do it. I know the error would be icRequestFailed/35756. I don't know if it best done through Select Case or what and from other parts of the program(copy and paste from old messages) I see they have did it the error trapping as part of a class module. Kinda got the idea where I'm lost. Hence why I haven't put anything into the Handler section as of yet. (NOTE:I just added in the Handler section as I was copying the code over from VB. I haven't actually run the program with the any part of the Handler included).

Here is what I have so far.

Code:
Option Explicit

Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long

Private Const FLAG_ICC_FORCE_CONNECTION = &H1

Private Sub Form_Load()
Dim strDate as string, Model(4) as String, MDay(81) as String, FLength as Long, strBin() as Byte
Dim Counter1 as Integer, Counter2 as Integer, Counter3 as Integer
        For Counter1 = 1 To 4
            For Counter2 = 1 To 81
                If UCase(Dir$("D:\C Drive\Convert\GFSMaps\" & strDate & Model(Counter1) & MDay(Counter2) & ".gif")) <> "" Then GoTo nxtHour
                
'check for internet connection, if connection is present download the image if not come back up and check for connection again(I think = 1 is true, it appears like it is, it does what I want it to at least)
CheckConn:
                If InternetCheckConnection("http://mag.ncep.noaa.gov/GemPakTier/MagGemPakImages/gfs/" & strDate & "/" & Model(Counter1) & "/gfs_namer_" & MDay(Counter2) & "_1000_500_thick.gif", FLAG_ICC_FORCE_CONNECTION, 0&) = 1 Then
                    On Error Goto Handler
                    strBin = Inet1.OpenURL("http://mag.ncep.noaa.gov/GemPakTier/MagGemPakImages/gfs/" & strDate & "/" & Model(Counter1) & "/gfs_namer_" & MDay(Counter2) & "_1000_500_thick.gif", icByteArray)
                    FLength = Inet1.GetHeader("Content-length")
                    If FLength < 10000 Then Exit For 
                    If Left(strBin, 51) = "<html><head><title>JBossWeb/2.0.0.GA - Error report" Then
                        Counter2 = 81
                        FLength = 0
                        GoTo nxtHour
                    End If
                    Counter3 = FreeFile
                    Open "D:\C Drive\Convert\GFSMaps\" & strDate & Model(Counter1) & MDay(Counter2) & ".gif" For Binary Access Write As Counter3
                    Put #Counter3, , strBin
                    Close Counter3
                Else
                    GoTo CheckConn
                End If
nxtHour:
            Next Counter2
        Next Counter1
        Exit Sub
Handler:
End Sub