Results 1 to 26 of 26

Thread: [RESOLVED] Flashing text

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Resolved [RESOLVED] Flashing text

    Hey,
    I have tried putting a timer on the form, and put a timer.tick sub routine to change the colour of the text but no sucess please may someone help me
    Thanks,
    Mike

  2. #2
    Hyperactive Member jp26198926's Avatar
    Join Date
    Sep 2008
    Location
    General Santos City, Philippines
    Posts
    310

    Re: Flashing text

    Quote Originally Posted by Surfymike
    Hey,
    I have tried putting a timer on the form, and put a timer.tick sub routine to change the colour of the text but no sucess please may someone help me
    Thanks,
    Mike
    did u already set the timer's interval?

    try this:
    Code:
    Text1.Forecolor =  Rnd * RGB (123,123,123)
    "More Heads are Better than One"

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Flashing text

    Welcome to the forums.
    Quote Originally Posted by Surfymike
    I have tried putting a timer on the form, and put a timer.tick sub routine to change the colour of the text but no sucess please may someone help me
    Post what you did.

  4. #4
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Flashing text

    Quote Originally Posted by Surfymike
    Hey,
    I have tried putting a timer on the form, and put a timer.tick sub routine to change the colour of the text but no sucess please may someone help me
    Thanks,
    Mike
    Timer.Tick in VB6 ??
    Are you using the timer control that ships with VB6 or some third party control?
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Flashing text

    Quote Originally Posted by Pradeep1210
    Timer.Tick in VB6 ??
    Are you using the timer control that ships with VB6 or some third party control?
    Perhaps this would have been .Net instead?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Re: Flashing text

    im using the VB6 timer and i thought timer.tick is a valid sub routine where it executes whenever the interval has been reached

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Re: Flashing text

    i have set the timers interval and put the code in and no luck

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Re: Flashing text

    I have tried:
    Private Sub Timer1_Timer()
    Text3.ForeColor = Rnd * RGB(123, 123, 123)
    End Sub
    and
    Private Sub Timer1_Tick()
    Text3.ForeColor = Rnd * RGB(123, 123, 123)
    End Sub

  9. #9
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Flashing text

    Try this:
    vb Code:
    1. Private Sub Timer1_Timer()
    2.     Text3.ForeColor = RGB(Rnd *123, Rnd * 123, Rnd * 123)
    3. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Re: Flashing text

    grim,
    still no luck, im pretty new to timers so what do i need on the form load for timer to check if its the timer or the code?

  11. #11
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Flashing text

    vb Code:
    1. Sub Form_Load()
    2.     Timer1.Interval = 1000
    3.     Timer1.Enabled = True
    4. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  12. #12
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Flashing text

    You could put in a BreakPoint in your Timer event so you could check if it is firing or not.
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  13. #13

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Re: Flashing text

    have put the interval in and put it to enabled and still nothing,
    what is a break point?
    and you think its the timer code thats wrong or the code that is making the text flash

  14. #14
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Flashing text

    A break point is an essential debugging tool.

    In VB when you are in a code module you will see, to the left of the white area you type you code in, a grey bar about 1cm thick.

    If you click in that grey area on the same line of some code it will enter a break point (the code line will now be highlighted), when you run you code from now on it will stop at the break point and allow you to step through your code using the F8 button to see what is happening.
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  15. #15

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Re: Flashing text

    Thanks for telling me bout the break point,
    its doing the sub however the text is not changing,
    so can you help me develop the actual code that makes it flash/change colour

    thanks

  16. #16

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Re: Flashing text

    i put the interval at 10 and now it sort of changes colour but was wanting it t flash rather than change colour any ideas?

  17. #17
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Flashing text

    increase interval to 100 or 1000 (1000=1 sec)
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  18. #18
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Flashing text

    right the timer control is fairly simple. add the following code to a Form.

    vb Code:
    1. Private Sub Form_Load()
    2. Timer1.Interval = 10000     'interval in milliseconds 10000 = 10 seconds
    3. Timer1.Enabled = True
    4. End Sub
    5.  
    6. Private Sub Timer1_Timer()
    7.  
    8. 'this will fire after 10 seconds !!
    9.  
    10. MsgBox "10 seconds reached"
    11.  
    12. 'do stuff
    13.  
    14. End Sub
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  19. #19
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Flashing text

    to get it to flash just set you interval lower to say 1 second (1000)
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  20. #20
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Flashing text

    right, i have just looked and seen i have just repeated what Pradeep posted concerning the timer !!

    So you don't need to change anything, just the Interval setting to 1000 !
    Please Mark your Thread "Resolved", if the query is solved & Rate those who have helped you



  21. #21

    Thread Starter
    New Member
    Join Date
    Nov 2008
    Posts
    15

    Re: [RESOLVED] Flashing text

    it works thanks everyone for helping
    i shall be giving good feedback

  22. #22
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: [RESOLVED] Flashing text

    Surfymike

    FWIW, "flash" is a somewhat vague word in this context.

    One possible meaning could be that the text alternates
    between being visible, and not being visible (ie, on-off).

    Another is that it alternates between colors (say, red-black).
    Another is that it alternales between boldface and normal.

    If any of the above are appealing, then you might consider
    using the Mod function. If, for example, you have settled
    on a 1 second interval, then, if the second is even, the
    text could be "on", and if the second is odd, the text
    could be "off".

    You've indiciated that you've resolved this, but if the
    above is appealing but confusing, holler.

    Spoo

  23. #23
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: [RESOLVED] Flashing text

    Surfymike:

    A little birdie told me you might be interested

    These two code frags are from Pradeep1210

    Code:
    Sub Form_Load()    
       Timer1.Interval = 1000    
       Timer1.Enabled = True
    End Sub 
    
    Private Sub Timer1_Timer()    
       Text3.ForeColor = RGB(Rnd *123, Rnd * 123, Rnd * 123)
    End Sub
    To have the text alternately flash red|black, you could modify
    the second sub as follows:

    Code:
    Private Sub Timer1_Timer()    
       sec = Second(Now)
       resu = sec Mod 2
       If resu = 0 Then
          Text3.ForeColor = vbRed
       ElseIf resu = 1 Then
          Text3.ForeColor = vbBlack
       Endif
    End Sub
    .. where:

    Now is a function that returns your computer's system date/time,
    Second is a function that returns an integer from 0 to 59, ie, the seconds portion of the time.
    Mod
    is an operator that divides 2 numbers and returns only the remainder.
    Here, I have used "sec" and "2".
    -- if sec is even, resu = 0
    -- if sec is odd, resu = 1.
    This, then, enables the ForeColor branches to execute as desired.

    With some tinkering, you could get the following results:
    -- text is visible|not visible (on|off)
    -- text is bold|normal
    -- flashing happens more|less rapidly

    HTH
    Spoo
    Last edited by Spoo; Dec 3rd, 2008 at 03:02 PM.

  24. #24
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: [RESOLVED] Flashing text

    Quote Originally Posted by Spoo
    ...

    To have the text alternately flash red|black, you could modify
    the second sub as follows:

    Code:
    Private Sub Timer1_Timer()    
       sec = Second(Now)
       resu = sec Mod 2
       If resu = 0 Then
          Text3.ForeColor = vbRed
       ElseIf resu = 1 Then
          Text3.ForeColor = vbBlack
       Endif
    End Sub
    ...

    HTH
    Spoo
    It could have been even easier. Since you are looking at only 2 values, a boolean is more suited for it. Why go round and round to achieve a simple thing.

    Code:
    Private Sub Timer1_Timer()    
       Static resu As Boolean
       resu = Not resu
       Text3.ForeColor = IIf(resu, vbRed, vbBlack) 
    End Sub
    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  25. #25
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: [RESOLVED] Flashing text

    Pradeep

    The main reason I chose to go round and round was that I was not
    familiar with Static

    I read up a little on it, but must confess to still being rather confused
    by its purpose. No doubt, your code is much more efficient than my
    previous post.

    Be that as it may, would the following accomplish the same thing?

    in declarations:
    Code:
    Public resu as Boolean
    ..then, the timer sub:
    Code:
    Private Sub Timer1_Timer()    
       resu = Not resu
       Text3.ForeColor = IIf(resu, vbRed, vbBlack) 
    End Sub
    As the time sub will repeatedly trigger, is it not even more efficient
    to remove the Static line altogether (and put it in the
    declarations, where it executes only one time)?

    Am I missing something? As I say, I'm not quite sure of the benefit
    of the Static statement.

    Spoo

  26. #26
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: [RESOLVED] Flashing text

    Static variable inside a procedure (sub or function) is just like a class/form level variable but the scope is that procedure only. It is not visible outside the procedure. However it will retain its values just like any other class/form level variable between subsequent calls to the procedure.


    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

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



Click Here to Expand Forum to Full Width