Consulting

Results 1 to 16 of 16

Thread: Fade a splash screen

  1. #1
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location

    Fade a splash screen

    Hey guys and hello from the first timer ...

    I'm looking for a simple, easy for me to understand code to fade out an intro splash screen I'm using in my spreadsheets.

    So far I have been directed to a couple of sites (thanks to those people) and picked up the following but way to complicated for me and one of them was very unstable. (made my spreadsheet invisible)

    http://www.vbaexpress.com/kb/getarticle.php?kb_id=166

    http://www.xcelfiles.com/SplashScrn.html

    Can any one help me ...... Thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Here is a simple example
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Hi Jacko and welcome to VBAX
    I've combined a couple of known techniques to make an example (attached - only tested in Excel 2003 so far). IMHO the best solution to your requirement will involve using Windows API functions for the timer and form transparency, so not exactly basic but hardly rocket science either. I've thrown a few comments in but please post back if anything isn't clear.

    Code derived from:
    Using Windows timers by Chip Pearson and
    Transparent Userform at Colo's Excel Junk Room
    K :-)

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Killian
    I've combined a couple of known techniques to make an example (attached - only tested in Excel 2003 so far). IMHO the best solution to your requirement will involve using Windows API functions for the timer and form transparency.
    Interesting, you interpreted fading literally, I just interpreted it as a splash screen that would time out.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Yeah, I was quite impressed by Colo's transparency sample but I never had the oppotunity to use it for anything... and then I saw the word "fade" ! I'm not a huge fan of code that doesn't actually add functionality but it's a fun script to play with
    K :-)

  6. #6
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    Thanks for your reply ..... really appreciated...

    Unfortunately I got the following error message -

    Compile error
    Syntax error

    and the following line highlighted..

    TimerID = SetTimer(0&, 0&, TimerSeconds, AddressOf TimerProc)

    I'm using XP and MS Office 97, if that may mean anything..

    Any clues.....

  7. #7
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    Thanks for the reply - yours is similar to the one I'm currently using. The fade adds a new dimension dont you think...

  8. #8
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    And there's more,

    Tried it on MS Office 2003 and it works great can u set it up for 97...

    Love your work..

  9. #9
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Glad you like it...
    Unfortunately, getting it to work in 97 is going to be a challenge since the AddressOf operator is unsupported.
    It's tempting to use Application.OnTime or other easily accessible VBA time related stuff but I'm not sure there's a way of using any of these with fractions of a second (which we need for animating)
    I think the best option is write your own equivalent function for AddressOf by using the older VBA Win API functions. This won't run in Office2000+ so if we use the conditional compilation directive we can have one command for 97 and another for 2000+.

    So, in your form code:
    1. Add the required function declarations

    Private Declare Function GetCurrentVbaProject Lib "vba332.dll" _
        Alias "EbGetExecutingProj" (hProject As Long) As Long
    Private Declare Function GetFuncID Lib "vba332.dll" Alias _
        "TipGetFunctionId" (ByVal hProject As Long, ByVal strFunctionName As String, _
        ByRef strFunctionId As String) As Long
    Private Declare Function GetAddr Lib "vba332.dll" Alias _
        "TipGetLpfnOfFunctionId" (ByVal hProject As Long, ByVal strFunctionId As String, _
        ByRef lpfn As Long) As Long
    2. Add this new function to be used in 97

    Private Function AddrOf(strFuncName As String) As Long
    '   Returns a function pointer of a VBA public function given its name. This function
    '   gives similar functionality to the VBA6 AddressOf param type.
    Dim hProject As Long
        Dim lngResult As Long
        Dim strID As String
        Dim lpfn As Long
        Dim strFuncNameUnicode As String
    Const NO_ERROR = 0
    ' The function name must be in Unicode, so convert it.
        strFuncNameUnicode = StrConv(strFuncName, vbUnicode)
    ' Get the current VBA project
        Call GetCurrentVbaProject(hProject)
    ' Make sure we got a project handle
        If hProject <> 0 Then
            ' Get the VBA function ID (whatever that is!)
            lngResult = GetFuncID(hProject, strFuncNameUnicode, strID)
    ' We have to check this because we GPF if we try to get a function pointer
            ' of a non-existent function.
            If lngResult = NO_ERROR Then
                ' Get the function pointer.
                lngResult = GetAddr(hProject, strID, lpfn)
    If lngResult = NO_ERROR Then
                    AddrOf = lpfn
                End If
            End If
        End If
    End Function
    3. Change the StartTimer routine to conditionally compile the correct statement for the version of VBA being used[VBA]Sub StartTimer()

    TimerSeconds = 250 'timer interval (in milliseconds)
    #If VBA6 Then 'compiled in only Excel 2000 and the later version
            TimerID = SetTimer(0&, 0&, TimerSeconds, AddressOf TimerProc)
        #Else 'compiled in Excel 97
            TimerID = SetTimer(0&, 0&, TimerSeconds, AddrOf("TimerProc"))
        #End If
    End Sub
    That should do it... it seems to work fine for me but I would recommend some extensive testing (both versions) to be sure you trap any errors - particularly unexpected return values from the API functions since they can be somewhat unpredictable.

    Enjoy...
    K :-)

  10. #10
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Now that's what I call sexy! Nice code Killian, think I'll use it myself!
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  11. #11
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    Love your work ..... but way above my head....

    Is it possible for you to amend the original code u sent to run under Excel 97...

    Many thanks from down under...

  12. #12
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    Many thanks from down under...
    ... happy to help. Now if you could just arrange for Glenn McGrath to retire now he's got his 500 (preferably before play resumes) I'd be grateful

    Here's a file with the new code added that works with all Office versions.
    K :-)

  13. #13
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by Jacko
    Love your work ..... but way above my head....

    Is it possible for you to amend the original code u sent to run under Excel 97...

    Many thanks from down under...
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  14. #14
    Administrator
    Chat VP
    VBAX Guru johnske's Avatar
    Joined
    Jul 2004
    Location
    Townsville, Australia
    Posts
    2,872
    Location
    Quote Originally Posted by Killian
    ... Now if you could just arrange for Glenn McGrath to retire now he's got his 500 (preferably before play resumes) I'd be grateful ...
    You wish!...
    You know you're really in trouble when the light at the end of the tunnel turns out to be the headlight of a train hurtling towards you

    The major part of getting the right answer lies in asking the right question...


    Made your code more readable, use VBA tags (this automatically inserts [vba] at the start of your code, and [/vba ] at the end of your code) | Help those helping you by marking your thread solved when it is.

  15. #15
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by johnske
    You wish!...
    Don't worry, that natural born Englishman, Kevin Pietersen, and our home grown Geraint Jones will wear him out before the end of the series, and that will retire him (and, yes I do ...).
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  16. #16
    VBAX Regular
    Joined
    Jul 2005
    Posts
    6
    Location
    Thanks for your help...

    The fading is working perfectly on all systems inc. 2003, 2000 and 97..

    As mentioned - love your work..

Posting Permissions

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