progolf069
Programmer
Can anybody help me out with this runtime error of: Runtime Error '50003' Unexpected Error. I know it relates to a file not being found over the internet. The purpose of the program that I have is this: I have a simple application that pulls an image off of the internet, and places the image in a picture box. Well, if the image is not avalible to be placed in the picture box (because it is not avalible online -- either not on the server, or the server is down/not avalible) you will receive this error. Does anybody want to try giving me ideas on how to set up an error handler, that might display a message box that mentions something about "server is unavalible right now, try later" If you have any ideas, please post them! Here is the code that I have so far For this application:
Code:
Option Explicit
Private Declare Function GetTempPath Lib "kernel32" _
Alias "GetTempPathA" (ByVal nBufferLength As Long, _
ByVal lpBuffer As String) As Long
Private Declare Function GetTempFileName Lib "kernel32" _
Alias "GetTempFileNameA" (ByVal lpszPath As String, _
ByVal lpPrefixString As String, ByVal wUnique As Long, _
ByVal lpTempFileName As String) As Long
Private Function GetPicFromHTTP(strURL As String) As Variant
Dim strTempPath As String * 512
Dim strTempFileBuff As String * 576
Dim strTempFile As String
Dim hFile As Long
Dim result As Long
Dim bytearray() As Byte
Dim strData As String
' Generate unique temporary filename
result = GetTempPath(512, strTempPath)
GetTempFileName strTempPath, "VBT", 0, strTempFileBuff
strTempFile = Left$(strTempFileBuff, InStr(strTempFileBuff, vbNullChar) - 1) + ".jpg"
bytearray() = Inet1.OpenURL(strURL, icByteArray)
'strData = Inet1.OpenURL("[URL unfurl="true"]http://www.wandtv.com/rdrimg.jpg";,[/URL] icString)
hFile = FreeFile
Open strTempFile For Binary As hFile
Put hFile, , bytearray
Close hFile
Set GetPicFromHTTP = LoadPicture(strTempFile)
Kill strTempFile
End Function
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdReload_Click()
picRadar.Visible = False
picRadar.Picture = GetPicFromHTTP("[URL unfurl="true"]http://www.wandtv.com/rdrimg.jpg")[/URL]
picRadar.Visible = True
End Sub
Private Sub Form_Load()
picRadar.Picture = GetPicFromHTTP("[URL unfurl="true"]http://www.wandtv.com/rdrimg.jpg")[/URL]
End Sub