Adblock breaks this site

How to make a simple updater

Discussion in 'Programming General' started by Covey, Apr 30, 2008.

  1. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    How to make a simple updater

    You will find a Source Code Project download attached to the bottom of this post.

    Difficulty: Beginner

    Controls that are needed:
    1 x Label named "Label1"
    1 x Label named "Label2"
    1 x CommandButton named "cmdUpdate"
    1 x Microsoft Internet Transfer Control named "Inet1" (Press CTRL + T and scroll down the list to add this control to your project)

    Resources needed:
    A server you can upload .txt files to.

    Step 1.
    Upload a .txt file to your server with a version number in it. (1.0 for example)

    Step 2.
    Copy and paste this code to your Form. (be sure to fill out the Private Constants correctly)
    Code:
    Option Explicit
    Private Const strCurrentVersion As Double = "0.1"
    Private Const strVersionURL As String = "Path_To_Version_Here"
    Private Const strDownloadURL As String = "Path_To_File_Here"
    
    Private Sub cmdUpdate_Click()
        Dim strLatestVersion As Double
        If Inet1.StillExecuting = True Then
            Exit Sub 'If the inet1 control is busy than exit the sub (prevents stillexecuting error)
        End If
        cmdUpdate.Enabled = False
        strLatestVersion = Val(Inet1.OpenURL(strVersionURL))
        Label1.Caption = "Current version: " & strCurrentVersion
        Label2.Caption = "Latest version: " & strLatestVersion
        If Val(strLatestVersion) > Val(strCurrentVersion) Then
            If MsgBox("An update is available." & vbNewLine & "Your version: " & strCurrentVersion & vbNewLine & "Latest version: " & strLatestVersion & vbNewLine & vbNewLine & "Would you like to update now?", vbQuestion Or vbYesNo, "Update Now?") = vbYes Then
                'launch update using the strDownloadURL constant
            Else
                'did not want to update
            End If
        End If
        cmdUpdate.Enabled = True
    End Sub
    Step 3.
    Run and test your program.
     

    Attached Files:

  2. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    How to make a simple updater

    Awww, come on. You had a naming thing going on, why stop there.
    Make the labels lblCurrent and lblLatest.

    Your file doesn't need to be any specific extension, .update, .leel, or nothing will also suffice (as long as it isn't a restricted file type (.htaccess or .htpassword))

    Val() returns a double, so using it over CDbl() doesn't bring any advantages.

    You also made strLatestVersion a double when you pulled it down from the Inet control. using Val() in your if statement is redundant.


    Very nice work though ;) I just feel like being a bastard
     
  3. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    How to make a simple updater

    you make Covey sad :(

    My bad, just got what you meant by this.
    Yer it was originally a Double but i decided to change em to strings to keep the "." in the whole number version (1.0, 2.0 etc). But evidentally i only changed the variable name not the type. :eek:


    That was to prevent mis-haps from speds putting letters in the update file.
     
  4. Teizhcial

    Teizhcial Guest

    Referrals:
    0
    How to make a simple updater

    Very nice, I have a few idea's on how I can use this.

    Also instead of reading a hosted txt file would it be possible to get the update through a site's html source?
     
  5. Jazz00006

    Jazz00006 Apprentice
    Visual Basic Programmers

    Joined:
    Aug 26, 2005
    Posts:
    807
    Referrals:
    0
    Sythe Gold:
    0
    How to make a simple updater

    Yes, it is possible. But it depends on your HTML source, there is not 1 universal function for all.

    If you would like help, post a link to your page, either I or someone else will write a function for you.
     
  6. Bodom_

    Bodom_ Guest

    Referrals:
    0
    How to make a simple updater

    Hey I used this code, when I click OK on update, it doesn't download anything? Can you please supply with a demo of a downloader, thanks.
     
  7. Covey

    Covey Creator of EliteSwitch
    Retired Sectional Moderator Visual Basic Programmers

    Joined:
    Sep 9, 2005
    Posts:
    4,510
    Referrals:
    9
    Sythe Gold:
    9
    Discord Unique ID:
    807246764155338833
    Discord Username:
    Covey#1816
    How to make a simple updater

    SpEd...

    See that little attachment on my first post?
     
< [Source] Simple BlackJack Game. | i need someone to make me a program! >


 
 
Adblock breaks this site