none
Form shows "not responding" while code executes in background RRS feed

  • Question

  • For a project I'm working on (and teaching myself on, so please be gentle) I would like to include a version check to alert to a newer version being available on a sharepoint.

    I would prefer this to be unobtrusive if possible but still automatic so I wanted the update check to run in the background while the form is displayed and usable and to update a label caption on the form to provide the alert.

    I have implemented something which is probably not very elegant but does the job. The form becomes unresponsive for several second though and shows "Not responding". I think this is happening during "FolderExists" or "Setfolder" since it is a network location and may take a little time.

    If anyone has any advice on how to either prevent not responding or on a better implementation in general, I'd be grateful. There is likely to be only one version of the file on the sharepoint at any one time (depending on the person maintaining it) so iterating through files should be quick. The version will be simply the date and time in their filename as in 201406301746_filename.dotm.

    Thanks in advance

    Code below...

    myForm is non-modal to allow code to execute in the background and called using this code:

       myForm.Show
       DoEvents
       myForm.UpdateStatus (UpdateTest)
    

    The sub myForm.UpdateStatus is as follows:

    Public Sub UpdateStatus(status As Integer)
        Dim StatusString As String
        If status = -1 Then
            StatusString = "Update: Server could not be reached"
        ElseIf status = 1 Then
            StatusString = "Update: A new version is available" & vbNewLine
        ElseIf status = 0 Then
            StatusString = "Update: None available"
        End If
        myForm.updateLabel.Caption = StatusString
    
    End Sub

    And finally UpdateTest Looks like this...

    Function UpdateTest()
    
        Dim folder As folder
        Dim f As File
        Dim fs As New FileSystemObject
            If fs.FolderExists("//my/sharepoint/url") Then
                Set folder = fs.GetFolder("//my/sharepoint/url")
                Dim newestver As String
                newestver = "0"  'newestver is used to store the highest date/version found on the sharepoint'
                For Each f In folder.Files
                    Dim ver As String
                    If Len(f.Name) = 38 Then
                        ver = Left(f.Name, 12)
                        If Val(ver) > Val(newestver) Then   'if version for current file is higher than newestver'
                            newestver = ver                 'it becomes newestver'
                        End If
                    End If
                Next f
                If Val(versionforcheck) < Val(newestver) Then    'versionforcheck is global variable'
                    UpdateTest = 1    ' New version available'
                Else
                    UpdateTest = 0    ' No new version'
                End If
            Else
                UpdateTest = -1     'Server unreachable'
            End If
    End Function
    





    Monday, June 30, 2014 4:46 PM

Answers