Library tutorials & articles
Using the Inet Control
Saving the file
tempbuf = bytes()
'If the URL returned any thing, put the first
'50 characters in a buffer, Error messages
'will be found here.
If Len(strResult) > 50 Then
buf = Left(strResult, 100)
Else
buf = bytes()
End If
'Catch a time out error
If Err = 35761 Then
tout = tout + 1
Status = "Timed out: " & tout
Err.Clear
Exit Function
'If nothing is returned, it usually means
'that the server was not found.
ElseIf tempbuf = "" Then
snf = snf + 1
Status = "Server not found: " & snf
Exit Function
'if nothing is returned, it usually means that
'the server was found, but the requested file was
'not present.
ElseIf InStr(1, buf, "404") Then
fnf = fnf + 1
Status = "File not found: " & fnf
Exit Function
Else
'Otherwise, everything is OK
OK = OK + 1
Status = "File was downloaded successfully: "
& OK
End If
If the downloaded string is larger than 50 chars then transfer the first 100 characters to the buffer so that the error messages can be searched for. 35761 is the time out error.
'Get a file number
fn = FreeFile
'Open a binary file and load data into it!
Open sOutPutFile For Binary Access Write As #fn
Put #fn, , bytes()
DoEvents
'Close the open file
Close #fn
Now its time to write the information retrieved from the remote server to the local file. We have used FreeFile function here, FreeFile function returns an integer representing the next file number available for use by the open statement.1-255 file numbers can be used to open files not accessible to other applications. Use file numbers in the range 256-511 for files accessible from other applications. SOutPutFile is the name of the output file provided by the user. We have opened the file for binary access. Put the downloaded bytes into the newly opened file. After writing the content to the file, close the file. That's it. I used this component to download image files from remote computers and it always worked fine.
Private Sub Class_Terminate()
Set Form1 = Nothing
End Sub
In the class_terminate() event of the class, destroy the form on which we placed the control.
Related articles
Related discussion
-
Run-time error '91'
by crazyidane (0 replies)
-
Problem handling Redirects with MSXML2.XMLHTTP
by brandoncampbell (2 replies)
-
vbinputbox pauses code while it waits on response. How can I reproduce that?
by brandoncampbell (1 replies)
-
Sending SMS in VB 6
by sirobnole (6 replies)
-
Comboxbox listindex in ActiveX Control
by brandoncampbell (1 replies)
Dear all,
how if i want to post data http using inet ? please give me how to step by step ..
how to using inet
thank u so much
uniwaly
uniwaly[at]gmail.com
how would i use Inet to connect to a website... as in a yahoo website? say i want to use inet to log in to yahoo...
i would have text1 be the username. text2 the password, and then use a command button that when it is clicked, it will log me into yahoo on whatever server i would choose.... i am not good at Inet so a full code would be good... with the server http://login.yahoo.com/config/login
i have some errors in this program.When i download the pdf files from the remote server,it's ok.But exe and zip file are not ok.When zip files are downloaded,Time out error shows and exe files show server not found.So i can't solve this problem and i think it takes much time to download the pdfs which sizes are round about 500 k or more.So i would like to know that problem and then i would like to know the way of the executes method and get data and save in the desired location with executes.
okay give me a few hours and i'll do a bit o research and get back to you on that....
its very strange behaviour if its from VSI... PD i'd understand... wierd!
what did you use to distribute this again? was it PD wziard or VSI?
Yes
First I tried VSI, then when that didn't work right I tried the PD wizard. When I fixed the component registration one computer had it installed with VSI and the other with the PD wizard, so BOTH methods had the same problem.
COM is a pain. I've had alot of issues with registering new versions of components because of the compatibility settings etc.
what did you use to distribute this again? was it PD wziard or VSI?
One of the computers is Win2k, the other is Win XP Pro. (Both had the same problem, both fixed the same way)
So how would one go about fixing it if it is the com server? (I'll be looking into it myself, but have never messed with that type of thing before, stupid classes never tought us about distribution)
hmmm it looks like an installation issue then... the COM server may have the 'Self Register' attribute set or something...
I thought your using Windows 2000 so i told you WinNT folder... yes under Windows XP and now Windows.NET its back to 'Windows\System32'!
MSINET.OCX was already in that directory, unregistered and reregistered and it now works. (does this mean the installer wasn't registering it like it is suposed to? If so, what can be done to fix this in the installer?)
-- Note, I did this with both computers with IIS, the one on the XP Pro computer it was under Windows\system32, as it doesn't have a WINNT folder
okay this is what i want you to do...
get your MSINET.OCX file and place it in the winnt/system32 folder(your running IIS right?) then goto
Start>Run type in 'Command' enter 'regsvr32 /u " and the path to the OCX file... then do the same except without the "/u" and then it will tell you if it was successfully registered.
do this on the server side.
I should probably add that I have gotten the control to work when placed on a form in a standard VB executable project. (mind, I didn't try installing that one on a different computer, but it worked on the computer Visual Studio is on)
I'm hosting it myself. As for properly registering the MSINET.OCX, no clue, I didn't do anything special in reguards to it when I installed Visual Studio. I Used the Package and Deployment Wizard instead and it had the exact same problem. I opened the Setup.Lst file and the MSINET.OCX file was listed in there. Here is the contents of that file:
[Bootstrap]
SetupTitle=Install
SetupText=Copying Files, please stand by.
CabFile=wwHTML.CAB
Spawn=Setup1.exe
Uninstal=st6unst.exe
TmpDir=msftqws.pdw
Cabs=1
[Bootstrap Files]
File1=@VB6STKIT.DLL,$(WinSysPathSysFile),,,7/15/00 1:00:00 AM,101888,6.0.84.50
File2=@COMCAT.DLL,$(WinSysPathSysFile),$(DLLSelfRegister),,5/31/98 1:00:00 AM,22288,4.71.1460.1
File3=@STDOLE2.TLB,$(WinSysPathSysFile),$(TLBRegister),,6/3/99 1:00:00 AM,17920,2.40.4275.1
File4=@ASYCFILT.DLL,$(WinSysPathSysFile),,,3/8/99 1:00:00 AM,147728,2.40.4275.1
File5=@OLEPRO32.DLL,$(WinSysPathSysFile),$(DLLSelfRegister),,3/8/99 1:00:00 AM,164112,5.0.4275.1
File6=@OLEAUT32.DLL,$(WinSysPathSysFile),$(DLLSelfRegister),,4/12/00 1:00:00 AM,598288,2.40.4275.1
File7=@msvbvm60.dll,$(WinSysPathSysFile),$(DLLSelfRegister),,8/18/01 5:00:00 AM,1388544,6.0.92.37
[Setup]
Title=wwTools
DefaultDir=$(ProgramFiles)\wwTools
AppExe=wwHTML.dll
AppToUninstall=wwHTML.dll
[Setup1 Files]
File1=@MSINET.OCX,$(WinSysPath),$(DLLSelfRegister),$(Shared),5/22/00 1:00:00 AM,115920,6.0.88.62
File2=@wwHTML.dll,$(AppPath),$(DLLSelfRegister),,10/3/02 8:42:03 AM,24576,1.0.0.0
; The following lines may be deleted in order to obtain extra
; space for customizing this file on a full installation diskette.
;
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
; XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX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Firstly, do you have full access to the server? As in ar eyou hosting it or is some comapny doing it?
secondly did you proeprly register the msinet.ocx COM component?
The relivent code is realy simple:
Public Function GetHtml(sURL as string) as string
GetHtml = Inet1.OpenURL(sURL)
End Function
This function takes a string and as you can see, calls the Inet control's OpenURL function using the passed URL. The returned value is the source code of the requested document.
I had to stop the IIS prosses because I couldn't delete the old DLL while it was running (file in use error).
The dependency wasn't listed as an OCX in the Installer program (it was listed as some extention with an M, can't remember it, and am on a different computer ATM). Note, I also installed it on my XP Pro computer and got the same error. (the XP Pro one has VS .NET installed.) The version of VS I'm using to create this is VS 6 Pro, the version of .NET on my XP Pro computer is .NET Academic (full Proffesional version with Academic tools).
The precice error is as follows:
Error Type:
wwTools (0x800A0153)
Component 'MSINET.OCX' or one of its dependencies not correctly registered: a file is missing or invalid
/test1/html.asp, line 8
If you care to see the error for yourself (and if my DNS is functioning properly) visit my HTLM retrieval Test Page It is suposed to retrieve the Google home page source code and display the page.
My DNS is working on my end, still don't know if it's working for off of my local network.
the MSINET.OCX is what your after... not the DLL...
I dont understand why the IIS process should be stopped and restarted? We distributed this same file and had no problem what so ever. I have heard of a licensing issue on some distribution of VS or VB what distro have you got? We're got VS6 Enterprise so if you have any Enterprise distros your not likely to have any problems.
What exactly does your application do?
Thanks for the suggestion, tried that after I read this, even varified that the msinet was added as a dependency. Unfortunatly, even after unregistering the dll and running the new installer I got the same error. (always stopping the IIS service before removing and restarting after installing). I'm thinking at this point it's a problem with the computer I'm installing it on. (it's running Win2K, but it's a fairly old computer). Unfortunatly the only other computer in the house with IIS running is a Win XP pro computer with .Net installed. Not very good for testing weather it would work or not after distribution.
what you need to do is to redistribtue the file 'MSINET.OCX' and register the COM Server on their machine... I recommed you go and download Microsoft Visual Studio Installer 1.1 and use that to distribtue your application, its build on MSI technology giving your users the abilty to remove and 'goback/repair' failed installations...
URL : http://msdn.microsoft.com/vstudio/downloads/tools/vsi11/default.asp
Good Luck!
Mind you, I'm not doing exactly what this example shows. (I'm creating a simple control to retrieve the contents of a remote web page, simple 1 function accepts 1 string, the URL, and returns the contents). However, this would be a problem even if I did exactly what the example project was depicting. The problem is when I registered the DLL on a different computer (the computer with VS 6 doesn't have IIS) and set up a simple asp page I got the following error:
"Error Type:
wwTools (0x800A0153)
Component 'MSINET.OCX' or one of its dependencies not correctly registered: a file is missing or invalid"
My project is wwTools (will be a collection of tools eventualy). I did install the VB Runtime DLL's obtained from Microsoft and still I get this error.
What exactly am I missing? What do I need to do to get this to work on a computer without VS 6?
Sorry... I think that's a typo. Try objHTTP.Protocol = icHTTP. I'll update the tutorial asap
I got error.
Error: Method or data member not found
I can't find a way to fix this problem. Maybe somebody could send me complete project of that?
This thread is for discussions of Using the Inet Control.