Results 1 to 5 of 5

Thread: [RESOLVED] Check for newer version inside program

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    24

    Resolved [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:
    1. The program reads a file from the Internet. Said file contains the number of the latest version.
    2. The program compares its version with the version inside the text file.
    3. 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:
    1. How can I make VB6 load a file that was uploaded to the Internet (and read its contents)?
    2. 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.

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    Member
    Join Date
    Oct 2007
    Posts
    34

    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..

  4. #4
    Frenzied Member some1uk03's Avatar
    Join Date
    Jun 2006
    Location
    London, UK
    Posts
    1,675

    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:\")
    _____________________________________________________________________

    ----If this post has helped you. Please take time to Rate it.
    ----If you've solved your problem, then please mark it as RESOLVED from Thread Tools.



  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    Portugal
    Posts
    24

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width