Quantcast

Jump to content


Photo

[vb6 to vb.net] Need help porting this function


  • Please log in to reply
5 replies to this topic

#1 Backslash

Backslash
  • 47 posts

Posted 24 October 2009 - 04:08 PM

Public Sub DownloadFile(ByVal URL As String, ByVal Path As String)
 	Dim Filenum As Integer, strHTML As String
 	If Dir(Path) <> vbNullString Then Kill(Path)
 	Filenum = FreeFile()
 	strHTML = GetWrapper(URL)
 	If strHTML <> vbNullString Then
 	strHTML = StripHeaders(strHTML)
 	Open Path For Output As Filenum 
 	Print #Filenum, strHTML 
 	Close(Filenum)
 	End If
	End Sub

Im getting errors at Open, Path, For, #, and Close. If you need to know what errors, just ask. My namespace is:

Option Strict Off
Option Explicit On


Imports VB = Microsoft.VisualBasic
Imports System.Text.RegularExpressions
Imports System
Imports System.Text
Imports System.Runtime.InteropServices
Imports System.IO
Imports System.Net
Imports System.IO.Compression
Imports System.Runtime.Serialization.Formatters.Binary


Thanks!

Edited by Backslash, 24 October 2009 - 04:10 PM.


#2 artificial

artificial
  • 186 posts


Users Awards

Posted 24 October 2009 - 06:26 PM

I don't understand why you can't just access the page like you would any other HTTP request, and save the file like you would any other?

http://www.freevbcod...Code.Asp?ID=733

#3 Backslash

Backslash
  • 47 posts

Posted 24 October 2009 - 09:35 PM

what do you mean? ive tried many methods, this is my last one :p

oh, im getting an error that 'open' and 'close' is not declared

Edited by Backslash, 25 October 2009 - 12:41 AM.


#4 Dan

Dan
  • Resident Know-It-All

  • 6382 posts


Users Awards

Posted 25 October 2009 - 12:35 PM

Open and Close were old VB6 functions that weren't ported over.

Instead of using this methodology - use a StreamWriter instead - used for writing to a file.

#5 Johnbon

Johnbon
  • 1228 posts

Posted 11 February 2010 - 04:01 PM

or use my.computer.network.downloadfile

#6 Waser Lave

Waser Lave

  • 25516 posts


Users Awards

Posted 11 February 2010 - 04:06 PM

or use my.computer.network.downloadfile


I presume they wanted it to download the Neopets captcha image, in which case yours wouldn't work as it wouldn't send the right cookies.

To just download general files it would be fine though.


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users