DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   visualbasic (http://www.daniweb.com/code/visualbasic.html)
-   -   TempMsg ( Tempory Message ) (http://www.daniweb.com/code/snippet311.html)

cookware_ok visualbasic syntax
Jul 11th, 2005
Easily allows temporary message to be displayed on any label for a programmable length of time.
This is a very simple way to display a temporary message on an existing label (or textbox)without doing a lot of coding.

  1. Private Function TempMsg(tempMessage As String, timeInSecs As Single, whichLabel As Object)
  2. ' ========================
  3. ' Author: CookWare Ok
  4. ' ========================
  5. ' Function may be Public or Private as needed. Remember if used in a module use
  6. ' WhichForm.WhichLabel format to pass parameter to the function.
  7. ' EXAMPLE: Call TempMsg(myMessage, myTime, myForm.myLabel)
  8. ' ========================
  9. ' You Must included timer and timer code shown below
  10. ' ========================
  11. ' Private Sub timMsg_Timer()
  12. ' timMsg.Interval = 0
  13. ' timMsg.Enabled = False
  14. ' bMsgOn = False
  15. ' End Sub
  16. ' ========================
  17. ' You must also Dim bMsgOn As Boolean (either Public or Private as needed)
  18. ' =======================
  19. Dim myMsg As String
  20. myMsg = whichLabel ' Stores currently displayed message
  21. bMsgOn = True
  22. If timeInSecs > 10 Then ' Limits time interval to 10 seconds ( May be changed as you see fit )
  23. timeInSecs = 10
  24. End If
  25. timMsg.Interval = timeInSecs * 1000 ' converts timeInSecs to milliseconds
  26. timMsg.Enabled = True ' Starts timer
  27. Do Until bMsgOn = False ' Do tempMessage until time is elapsed
  28. DoEvents
  29. whichLabel = tempMessage
  30. Loop
  31. whichLabel = myMsg ' Restores original message
  32. End Function
  33.