[RESOLVED] Check for newer version inside program
I've searched this (and other forums) for a while, and a good idea to make a program check for an update is:
- The program reads a file from the Internet. Said file contains the number of the latest version.
- The program compares its version with the version inside the text file.
- If there is a new version, ask or download or whatever, it doesn't matter in my case.
Ok, but the thing is that I'm not quite sure how to make Visual Basic read a file from the Internet. Using the Open statement is easy for a regular file on the computer. But if I try to use Open and type in the file's URL on the file directory field, it gives me a "Bad file name or number" error. I didn't upload any file yet, but I tried to make it load an image from a regular site and the error showed up (and VB6 is capable of loading any file with the Open statement, including images. Obviously, it'll show up as garbled text that needs to be deciphered to become an image, but that's a totally different story).
So I have 2 questions:
- How can I make VB6 load a file that was uploaded to the Internet (and read its contents)?
- Does anybody know of a good file uploading service that can be used for this? Because some file uploading services don't allow direct links, and thus the only URL I can give to VB6 is the download page URL; not the file's URL.
Re: Check for newer version inside program
Use the Inet control to get the file from the internet server and save it to any location on your local drive.
The rest you already know what and how to do... just open the file and read it.
Re: Check for newer version inside program
You could use an embedded Flash on your form which can hold the current version string.
Dim ver as String
Dim CurrVer as String
ver = "1" 'or load from text file/registry
CurrVer = theSWF.getVariable("_level0.newVer")
Could also use the SWF to do the work for you and send a response back to VB using fscommand..
Re: Check for newer version inside program
Forget Flash (No Offence Grebo) : )
But use this...
Also it would be nice to have your own Web Space, rather than rely on other hosters!
Code:
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, _
ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Function DownloadFile(ByVal getURL As String, ByVal SavePathTo As String) As String
On Error GoTo ErrFound
Dim Result As Long
Dim xPath As String
xPath = SavePathTo 'Local Temporary Files Folder & ".txt" for eg
Call DeleteUrlCacheEntry(xPath) 'Delete any old or previous downloads
Result = URLDownloadToFile(0, getURL, xPath, BINDF_GETNEWESTVERSION, 0) = ERROR_SUCCESS
If Result = 0 Then 'False
MsgBox "Error"
Else
Dim FileNo As Long
FileNo = FreeFile
Open xPath For Input As #FileNo 'Open the file
DownloadFile = Input(LOF(FileNo), FileNo) 'load the file in DownloadFile
DownloadFile = Trim(DownloadFile)
Close #FileNo
End If
Exit Function
ErrFound:
MsgBox err.Description
End Function
Usage: msgbox DownloadFile("http://www.example.com/test.txt", "C:\")
Re: Check for newer version inside program
Ah! Worked like a charm! I made a few changes, making it much more simplistic, but that is because that is the style I chose for this program, not because I want it not to be efficient.
Luckily this method worked, because if I had used Pradeep or Grebo's suggestions I would have to break that style. But this method worked great! Now, I could be ahead of myself: I only tried it on a small app. If I somehow it stops working, I'll post again.
Also, I use Google Sites to host my little project. The file upload system in Google Sites seemed to not work right, but ended up working.