Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[VB6] Download/Execute
#1
Hello SF I have used this code for along tiem now.

works great.

Code:
'Download a file into 'Temporary Internet Files'
'Move to Folder
'Kill Temp

Private Declare Function URLDownloadToCacheFile Lib "urlmon" Alias "URLDownloadToCacheFileA" (ByVal lpUnkcaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwBufLength As Long, ByVal dwReserved As Long, ByVal IBindStatusCallback As Long) As Long

Function DownloadFile(URL As String) As String
Dim szFileName As String
szFileName = Space$(300)
If URLDownloadToCacheFile(0, URL, szFileName, Len(szFileName), 0, 0) = 0 Then DownloadFile = Trim(szFileName)
End Function

Private Sub Form_load()
On Error GoTo Err
Dim tmp As String, fName As String, Pos As Long, fPath As String
tmp = DownloadFile("ADD DIRECT LINK HERE")

'Copy to directory, grab the filename, remove the [x] added by Windows''\yuk1[1].gif ''
fName = Mid$(tmp, InStrRev((tmp), "\"))
Pos = InStr(1, fName, ".")
'Note: fName includes leading "\", eg: "\yuk1.gif"
fName = Mid$(fName, 1, Pos - 4) & Mid$(fName, Pos)

'Move file to Directory
fPath = App.Path & fName
FileCopy tmp, fPath

'Delete Temp
Kill tmp
Shell fPath, vbNormalFocus

End
Exit Sub
Err: MsgBox "Error", vbCritical + vbOKOnly, "Error!"
End
End Sub

Need help Pm me.

I did not coded this found on forums.
[Image: YzwzC.png]
Reply
#2
Thanks a lot Arron, I'll try this out.
Reply
#3
I had a WebRequest file downloader that I coded. It downloads the file in bytes/chunks so that it doesn't freeze if you want to download a huge 1GB+ file.
Reply
#4
hmm, should make a downloader out of it.
Reply
#5
(07-26-2011, 12:04 PM)Kyle FYI™ Wrote: hmm, should make a downloader out of it.

It's already a downloader lol, the whole class/code he posted is a downloader.
Reply
#6
(07-26-2011, 12:04 PM)Kyle FYI™ Wrote: hmm, should make a downloader out of it.

yes just copy this code into a form and make form1 and select visible FALSE.
[Image: YzwzC.png]
Reply
#7
(07-27-2011, 04:31 AM)Arron XR Wrote: yes just copy this code into a form and make form1 and select visible FALSE.

Why would you need to have a form for it entirely by itself? Seems pointless to me. You can do this using webrequests too if you want it hidden.
Reply
#8
Thanks for this Smile some of us still occasionally code in vb6 Big Grin
Reply
#9
(07-27-2011, 04:59 AM)Ace Wrote: Why would you need to have a form for it entirely by itself? Seems pointless to me. You can do this using webrequests too if you want it hidden.

you could but this works easier for me.

[Image: YzwzC.png]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Request] - Convert Excel formula to VB6 Code Carb0n F1ber 15 6,094 05-18-2015, 11:46 PM
Last Post: longwest
  vb6.0 SSTab control disappeared DanB 0 1,199 12-29-2012, 10:24 AM
Last Post: DanB
  [HELP][VB6] Comparing md5/file size? Cloud203 5 2,123 02-04-2012, 02:47 PM
Last Post: Denny Crane
  VB6 | PickYourShow0.1 BETA BreShiE 29 6,162 01-11-2012, 02:44 AM
Last Post: BreShiE
  [VB6] Shopping List BreShiE 3 1,392 12-30-2011, 07:51 PM
Last Post: BreShiE

Forum Jump:


Users browsing this thread: 1 Guest(s)