#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    84
    Rep Power
    5

    Is this acceptible coding??


    Hello people,

    Context: I have this little peice of code that I just need to display something on a caption label for about 5 seconds so that the user see's the success or failure of an action they have done.

    This is the excerpt, is this Ok? Could this be done any better? It does work, but sometimes it doesn't...

    'I want a delay here, I'll do it when I figure it out
    Dim EndTime As String
    EndTime = (Now.ToString("ss") + 5)

    Do Until (EndTime = CStr((Now.ToString("ss"))))
    Application.DoEvents()
    Loop

    'reset the form
    Call Init_form()

    Thanks,

    MRb
  2. #2
  3. ASP.Net MVP
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Aug 2003
    Location
    WI
    Posts
    4,378
    Rep Power
    1510
    Well, I'd normally avoid the use of Application.DoEvent() entirely, but in the interest of brevity I'll at least give you these corrections:

    Code:
    Dim EndTime As DateTime = Now.AddSeconds(5)
    
    While Now < EndTime
        Application.DoEvents()
    End While
    
    'reset the form
    Init_form()
    All that converting to and from strings is messy and slow
    Primary Forum: .Net Development
    Holy cow, I'm now an ASP.Net MVP!

    [Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

    http://twitter.com/jcoehoorn
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    84
    Rep Power
    5
    Hello F'Lar,

    Well once again you've proven really helpful. Thank you for you advice, and now I see why other areas of my program are slower than I was expecting, string conversions.

    I have another question to ask but I'll start another thread for that

    Thank's again.

    MRb

IMN logo majestic logo threadwatch logo seochat tools logo