• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 410
  • Last Modified:

Help with my update functions...

I haven't tested this yet, but would like:
A) Any suggestions for improving it and/or any oversight on my part and
B) To know how I kill this application, run an updater program (only replaces the existing exe) and then close the updater and restart the original?

Starter advice was given here (if you're interested): http:Q_21045254.html

Private Function CheckVersion()
    Dim strVersion As String, strMajor As Integer, strMinor As Integer, strRevision As Integer, strTemp() As String
    Dim strResp As String, blnMan As Boolean
    Open ("\\server\share\Vc.sct") For Input As #1
    Line Input #1, strVersion
    strTemp = Split(strVersion, ".")
    strMajor = strTemp(0)
    strMinor = strTemp(1)
    strRevision = strTemp(2)
    If strMajor > App.Major Then
        strResp = MsgBox("This version is out of date and incompatible with the current version." & _
            vbCrLf & "Would you like to update the application now?", vbYesNo)
            blnMan = True
            VersionUpdate strResp, blnMan
    End If
    If strMinor > App.Minor Then
        strResp = MsgBox("This version is out of date, but will still function properly." & vbCrLf & _
            "Would you like to update the applicaiton now?", vbYesNo)
        blnMan = False
        VersionUpdate strResp, blnMan
    End If
    If strRevision > App.Revision Then
        strResp = MsgBox("This version is okay, but there is a newer revision available." & vbCrLf & _
            "Would you like to update the application now?", vbYesNo)
        blnMan = False
        VersionUpdate strResp, blnMan
    End If
    Close #1
End Function

Private Function VersionUpdate(strResp As String, blnMan As Boolean)
    Select Case blnMan
        Case True
            If strResp = vbNo Then
                MsgBox "This application cannot continue and will close."
                Unload frmMain
            Else
                'update
            End If
        Case False
            If strResp = vbNo Then
                Exit Function
            Else
                'update
            End If
    End Select
End Function
0
sirbounty
Asked:
sirbounty
  • 11
  • 7
1 Solution
 
sirbountyAuthor Commented:
Hmm - so far, it's not finding my function from my form - do I have to make the first one (or both) public, or is there a way to reference the module -and if so, which is more 'efficient'?
0
 
aelatikCommented:
Make the one that you are calling from the form PUBLIC. The other function is called internally by the BAS module himself
0
 
aelatikCommented:
You could generate a batch file that does it for you :

Private Function VersionUpdate(strResp As String, blnMan As Boolean)
    Select Case blnMan
        Case True
            If strResp = vbNo Then
                MsgBox "This application cannot continue and will close."
                Unload Me
            Else
                Open "c:\temp.bat" For Output As #1
                    Print #1, "Del " & Replace(App.Path & "\" & App.EXEName, "\\", "\") & ".exe"
                    Print #1, "Copy \\server\share\sourcefilename.exe " & Replace(App.Path & "\" & App.EXEName, "\\", "\") & ".exe"
                    Print #1, "Del c:\temp.bat"
                Close #1
                Shell "c:\temp.bat", vbHide
                unload me
                Doevents
            End If
        Case False
            If strResp = vbNo Then
                Exit Function
            Else
                Open "c:\temp.bat" For Output As #1
                    Print #1, "Del " & Replace(App.Path & "\" & App.EXEName, "\\", "\") & ".exe"
                    Print #1, "Copy \\server\share\sourcefilename.exe " & Replace(App.Path & "\" & App.EXEName, "\\", "\") & ".exe"
                    Print #1, "Del c:\temp.bat"
                Close #1
                Shell "c:\temp.bat", vbHide
                unload me
                Doevents
            End If
    End Select
End Function
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
sirbountyAuthor Commented:
aelatik, wouldn't I need to kill the current running application first?  I realize I could do this via pskill, so along with your suggestion above, I could create a batch file in the user's workstation's temp folder that would contain

pskill myapplication.exe
del "app.path" (I realize this will need to be hard coded
copy new program
start new program
and then inside the vb app, delete the bat file

Does that sound do-able?
0
 
sirbountyAuthor Commented:
Made the first function public - how's the rest look to you?  Okay?
0
 
sirbountyAuthor Commented:
>>Print #1, "Del " & Replace(App.Path & "\" & App.EXEName, "\\", "\") & ".exe"
Print #1, "Copy \\server\share\sourcefilename.exe " & Replace(App.Path & "\" & App.EXEName, "\\", "\") & ".exe"
Print #1, "Del c:\temp.bat"<<

What's the replace for?  This appears to me to be deleting it from the server?  I think I follow what you're suggesting, but want to make sure...
I think all I'll need is
print #1, del app.path & "\" & app.exname

And do I open it for output or append?
0
 
sirbountyAuthor Commented:
Okay, I've added this function to run the batch file:

Private Function CodeCopy()
    Open (Environ("Temp") & "\sctupdate.cmd") For Output As #1
    Print #1, "@echo off"
    Print #1, "TSKill SCQtt.exe"               'easier than loading a 3rd party tool, when these will all be XP clients
    Print #1, "Del " & App.Path & "\SCQtt.exe"
    Print #1, "Copy \\server\share\SCqtt.exe " & App.Path & "\SCQtt.exe"
    Print #1, "Start " & Chr(34) & "C:\Program Files\SC Tracking\SCqtt.exe" & Chr(34)
    Print #1, "Del " & Environ("Temp") & "\sctupdate.cmd"
    Close #1
    Shell (Environ("Temp") & "\sctupdate.cmd")
End Function

Look okay?  I think that about does it - I just need to test it.
Will take any critique as well...
Btw, I fixed the missing Close #1 from the public function.
0
 
sirbountyAuthor Commented:
Hmm - okay, it apparently runs okay, but even after it's done its thing, it still prompts to update...I must be missing something... Help?
0
 
sirbountyAuthor Commented:
One problem was with tskill - I was referencing the filename.exe when it should be just the file (process) name without the extension, but it still asks me even after fixing that... :(
0
 
aelatikCommented:
Sorry i had to drive home, let me start from your first response.

>> What's the replace for?  This appears to me to be deleting it from the server?  I think I follow what you're suggesting, but want to make sure...

>> Replace(App.Path & "\" & App.EXEName, "\\", "\") & ".exe"

as you see its appending a backslash to the path, this because in case the path is not ending with a backslash or ends with a backslash. Its just removing the double one's.
0
 
aelatikCommented:
the function is OKAY, i usally make one number out of major & minor and check that against the newer version. but in your case you also do a check on the minor version and therefore its OKAY
0
 
aelatikCommented:
>> Hmm - okay, it apparently runs okay, but even after it's done its thing, it still prompts to update...I must be missing something... Help?

Did you set a higher version number on the other exe file ?
0
 
sirbountyAuthor Commented:
Got pulled away for the moment...
I'm re-checking now (versions) - but I believe I'm running the local one at 1.0.2 and trying to update to the newer one on the server share 1.0.3

I didn't use the replace function, I just hard-coded the trailing backslash...

I'm testing again now and will update shortly...
0
 
sirbountyAuthor Commented:
Hmm - no go...you think it's because I'm using shell?
Perhaps I should try shellwait?  Now I've got 1.0.2 locally and 1.0.5 remotely - still not updating properly... :(
0
 
aelatikCommented:
Try the Checkversion Function like this

Private Function CheckVersion()

    Dim strVersion As String
    Dim strMajor As Integer
    Dim strMinor As Integer
    Dim strRevision As Integer
    Dim strTemp() As String
    Dim strResp As String
    Dim blnMan As Boolean
   
    Open ("\\server\share\Vc.sct") For Input As #1
        Line Input #1, strVersion
    Close #1
   
    strTemp = Split(strVersion, ".")
    strMajor = CInt(strTemp(0))
    strMinor = CInt(strTemp(1))
    strRevision = CInt(strTemp(2))
   
    If strMajor > App.Major Then
        strResp = MsgBox("This version is out of date and incompatible with the current version." & vbCrLf & "Would you like to update the application now?", vbYesNo)
        blnMan = True
        VersionUpdate strResp, blnMan
    ElseIf strMinor > App.Minor Then
        strResp = MsgBox("This version is out of date, but will still function properly." & vbCrLf & "Would you like to update the applicaiton now?", vbYesNo)
        blnMan = False
        VersionUpdate strResp, blnMan
    ElseIf strRevision > App.Revision Then
        strResp = MsgBox("This version is okay, but there is a newer revision available." & vbCrLf & "Would you like to update the application now?", vbYesNo)
        blnMan = False
        VersionUpdate strResp, blnMan
    End If
   
End Function
0
 
sirbountyAuthor Commented:
So, it was the Cint...nice.  Does this just convert it to an integer?  And what's the difference between that and val(strTemp(2))?

Thanx again for all your help!!
0
 
aelatikCommented:
val extracts the numeric values out of it but does not perform a TYPE conversion.
Did you also use the IF statements the way i posted it ? I used elseif statements instead of 3 seperate IF statements.
0
 
sirbountyAuthor Commented:
Yes'sir - I copied your code and then just adjusted the actual server name information...
Thanx again -and thanx for the return explanation... : )
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

  • 11
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now