• Log in or sign up for an account here: https://www.sythe.org/login

How to make a simple updater

Covey

Creator of EliteSwitch

Retired Sectional Moderator
Visual Basic Programmers
Joined
Sep 9, 2005
Sythe Gold
9
Messages
4,510
Age
17
Location
Fuckin' BAM!
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.
 

Attachments

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
 
you make Covey sad :(

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

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


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

That was to prevent mis-haps from speds putting letters in the update file.
 
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?
 
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?
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.
 
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.
 
Runescape Gamblingrunescape gambling
Back
Top