Consulting

Results 1 to 10 of 10

Thread: Continually updating the statusbar

  1. #1
    VBAX Newbie
    Joined
    Apr 2012
    Posts
    4
    Location

    Continually updating the statusbar

    I am new to VBA (in fact any programing) so any help that you can give would be much appreciated.

    I am trying to write a script in Word 2010 that calculates theperiod of time it takes someone to read a word document out loud. I have managed to get everything working (seethe script below) and the output displayed on the Application Status Barhowever, I am stuck on one point.

    I am looking to have the application status bar continually updated as the user types in the document. Is there a way I can do this? Thanks for any help.

    Script
    Sub WordsPerMinute()
    ' Script to calculate the time it takes to read a presentation

    Dim intNoWordsPerMin As Integer
    Dim WordCount As Integer
    Dim WordsMin As Integer
    Dim WordsSec As Integer

    ' Set the number of words a minute someone can read a minute
    intNoWordsPerMin = 120

    ' Reads how many words in the document
    WordCount = CInt(ActiveDocument.Words.Count - 1)

    ' Calculates the number of words read in a minute
    WordsMin = WordCount / intNoWordsPerMin

    ' Calculates the remaining number words and how long it takes to read them in seconds
    WordsSec = (WordCount Mod intNoWordsPerMin) / intNoWordsPerMin * 60

    ' Displays the output on the Application Status Bar
    Application.StatusBar = "Duration of Script Approximately : " & Right(WordsMin + 100, 2) & ":" & Right(WordsSec + 100, 2)
    End Sub

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    "I am looking to have the application status bar continually updated as the user types in the document. "

    Not really. Changes to the status bar requires the execution of a procedure each time. Just typing does not fire a codable event. Moving the selection does, but not just typing.

    BTW: what does a user typing have to do with the time to takes to read?

  3. #3
    VBAX Newbie
    Joined
    Apr 2012
    Posts
    4
    Location
    Booooooooooo

    Thanks for the response though. To expand on what I am doing, I have some of my team that develop video script for teaching technical functions. They write the video scripts before they record it. One of the gold rules is the videos must not be greater than 10mins (We have found the engineers we are teaching only have a 10 minute attention span ). Hence the reason I was looking for a timer to give the guys writing the scripts an indication of how long it is going to take to read the script into the cammera.as they develop it (nothing worse than writing a lots of material that you are going to have to throw out because it is too long).

    Out of curiosity if I made the script continually loop with a sleep statement in it would they be able to interactive with the document whilst the macro is running?

  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Look up Do Events. Although generally no, macro code executing has focus. You can try using Sleep, but it may take a bunch of experimenting to (perhaps) get something that may work for you.
    I was looking for a timer to give the guys writing the scripts an indication of how long it is going to take to read the script
    Ae you saying there is some relationship between how fast someone is typing and how fast someone is reading and speaking

    Do tell. Would not a rather major factor be how fast someone types?

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Serious, why not just have the code you know works (calculating an estimated speaking time re: number of words) and train the writers to hit a hot key, or a button. It updates estimated the duration time. Trying to develop a continual update could be a bit of a pain, with little gain.

    Besides, a professional level writer should be able to make an fairly decent guess. 10 minutes of speaking is not that long, text wise.

  6. #6
    What the Word 2010 VBA help file says the Application.statusbar property is "roperty (Word)This property is no longer supported in Microsoft Word Visual Basic for Applications."

    But, the code does change the status bar, so it does still work.

    Doesn't unsupported mean unsupported??

  7. #7
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by BoatwrenchV8
    Doesn't unsupported mean unsupported??
    Heck, sometimes 'Supported' doesn't mean 'Supported'

    cnadams -- instead of timing the typing which probably is not a good indication of how long it will take some one to actually read it, could you use word count?

    i.e. 10 minutes at average of 100 wpm, = 1000 words.

    If your video script uses MS Word styles for stage directions vs. spoken lines, then you could only count the words in the appripriate style

    Paul

  8. #8
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    If your video script uses MS Word styles
    A big if. I await...

  9. #9
    VBAX Newbie
    Joined
    Apr 2012
    Posts
    4
    Location
    Hi guys, thanks for the response.

    Sorry when I put the word timer I did not mean how long it takes for the user to type the material. I mean time it would take to read out aloud the video script. The vba script calculates this time based on the average number of words you read per minute against the number of words in the document. This then give the person who is writing the video script a rough estimate on how long it will take them to read it aloud.

    This is the same calculation a news reporter uses when they are presenting a news story to give an indication on how long the news bulletin is going to run (I know because I use to build and install news room computers ).

    This bit of the script is working fine, what I was looking for was some way I could dynamically update the calculates as they user types out the video script, in the same way word updates the words counter on the status bar when you are writing a document.

    I will play around with do and sleep to see if this works, but I am guessing this is going to slow down the PC.

    By the sounds of it there isn’t a way of updating the information so as fumei suggests I will just have to get the user to hit the macro key periodically to get the latest figure.

    Thanks for your help.

  10. #10
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    I'm not a big fan of OnTime, but you can try this

    [vba]
    Option Explicit
    Public bStopUpdating As Boolean
    Public iUpdateFreq As Long
    Sub HowManyWords()
    Dim sMsg As String


    If bStopUpdating Then Exit Sub

    With ActiveDocument

    sMsg = "Paragraphs : " & Format(.ReadabilityStatistics(3).Value, "#,##0")
    sMsg = sMsg & " Words : " & Format(.ReadabilityStatistics(1).Value, "#,##0")
    sMsg = sMsg & " Characters : " & Format(.ReadabilityStatistics(2).Value, "#,##0")
    sMsg = sMsg & " Sentences : " & Format(.ReadabilityStatistics(4).Value, "#,##0")

    End With

    Application.StatusBar = sMsg

    Call Application.OnTime(Now + TimeSerial(0, 0, iUpdateFreq), "HowManyWords")
    End Sub
    [/vba]


    The attachment includes the rest of the macros, including Document events

    Paul
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •