Solved

Help with my update functions...

Posted on 2004-08-03
18
394 Views
Last Modified: 2012-05-05
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
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 7
18 Comments
 
LVL 67

Author Comment

by:sirbounty
ID: 11703730
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
 
LVL 14

Expert Comment

by:aelatik
ID: 11703788
Make the one that you are calling from the form PUBLIC. The other function is called internally by the BAS module himself
0
 
LVL 14

Expert Comment

by:aelatik
ID: 11703850
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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 67

Author Comment

by:sirbounty
ID: 11703902
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
 
LVL 67

Author Comment

by:sirbounty
ID: 11703913
Made the first function public - how's the rest look to you?  Okay?
0
 
LVL 67

Author Comment

by:sirbounty
ID: 11703963
>>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
 
LVL 67

Author Comment

by:sirbounty
ID: 11704120
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
 
LVL 67

Author Comment

by:sirbounty
ID: 11704250
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
 
LVL 67

Author Comment

by:sirbounty
ID: 11704395
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
 
LVL 14

Expert Comment

by:aelatik
ID: 11704665
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
 
LVL 14

Expert Comment

by:aelatik
ID: 11704694
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
 
LVL 14

Expert Comment

by:aelatik
ID: 11704725
>> 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
 
LVL 67

Author Comment

by:sirbounty
ID: 11705300
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
 
LVL 67

Author Comment

by:sirbounty
ID: 11705369
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
 
LVL 14

Accepted Solution

by:
aelatik earned 500 total points
ID: 11705666
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
 
LVL 67

Author Comment

by:sirbounty
ID: 11706098
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
 
LVL 14

Expert Comment

by:aelatik
ID: 11706200
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
 
LVL 67

Author Comment

by:sirbounty
ID: 11706706
Yes'sir - I copied your code and then just adjusted the actual server name information...
Thanx again -and thanx for the return explanation... : )
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month5 days, 16 hours left to enroll

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question