Results 1 to 15 of 15

Thread: Flashing back ground ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Flashing back ground ?

    I have tried to develop and application that enable a background to flash in each second, I wanted to use a counter to count up from I=1 to 100 if 'I' is odd then the background color should be red, if 'I' is even, the background color should be green.

    but the problem is, I could not find the code related to the integer parity...

    any help would be appreciated

    Thank you

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Flashing back ground ?

    Use teh Mod operator. Use your counter variable with it and if the result is 0 then flash one color and if is 1 then flash the other color.
    Are you using a timer control too?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Re: Flashing back ground ?

    the following is the code I have tried to use

    Option Explicit
    Dim I As Integer

    Private Sub FlashButton_Click()
    For I = 1 To 10 Step 1
    If Parity(I) = odd Then 'the code of this line is wrong need the right one
    FlashButton.BackColor = vbGreen
    End If
    If Parity(I) = even Then 'the code of this line is wrong need the right one
    FlashButton.BackColor = vbRed
    End If
    Next I

    End Sub

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Re: Flashing back ground ?

    Quote Originally Posted by RobDog888
    Use teh Mod operator. Use your counter variable with it and if the result is 0 then flash one color and if is 1 then flash the other color.
    Are you using a timer control too?
    I have tried the timer previously but I could not find a way to work it out

    could you please re-explain with more details what you have stated?

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Re: Flashing back ground ?

    Quote Originally Posted by RobDog888
    Use teh Mod operator. Use your counter variable with it and if the result is 0 then flash one color and if is 1 then flash the other color.
    Are you using a timer control too?
    I wanted the background to flash in each second ! each second it swaps the color

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Flashing back ground ?

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Timer1.Enabled = True
        Timer1.Interval = 1000
    End Sub
    
    Private Sub Timer1_Timer()
        Static iCount As Integer
        iCount = iCount + 1
        If iCount = 10 Then Timer1.Enabled = False 'Flash for 10 secods
        If iCount Mod 2 = 1 Then
            'Flash code first color
        Else
            'flash code other color
        End If
    End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Flashing back ground ?

    Quote Originally Posted by M C Benzerari
    I wanted the background to flash in each second ! each second it swaps the color
    Um, well you need a different color to make the background flash. It needs to change between one color and another in order to provide you a "flash" effect.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  8. #8
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Flashing back ground ?

    Quote Originally Posted by M C Benzerari
    I wanted the background to flash in each second ! each second it swaps the color
    If timer is set to 1000, how about,

    Private Sub Timer1_Timer()
    Static flipflop As Integer
    flipflop = Not flipflop
    If flipflop Then
    Form1.BackColor = vbRed
    Else
    Form1.BackColor = vbYellow
    End If
    End Sub

  9. #9
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Flashing back ground ?

    The timer1 event procedure will fire every 1000 ms which is every second.

    The code will change from one color to another every second.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Re: Flashing back ground ?

    Thanks all for the reply I will try your code and let you know very soon today...

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Thumbs up Re: [resolved] Flashing background ?

    Thanks Rob your code works OK

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Thumbs up Re: [Resolved] Flashing back ground ?

    Thanks Edgemeal your code as well worked OK

    I have spent 3 days looking to do so finally VB Forum is really a wonderful rescuer

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Re: Flashing back ground ?

    But why the 'flashing' start straight forward after the form is launched in design time, I wanted it to start when I click on button ?

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    82

    Thumbs up Re: [resolved] Flashing back ground ?

    Quote Originally Posted by M C Benzerari
    But why the 'flashing' start straight forward after the form is launched in design time, I wanted it to start when I click on button ?
    I found it I have to add the following code to form code:

    Timer1.Enabled = False

    it is done

  15. #15
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Flashing back ground ?

    Cool, we are glad to have helped.

    Ps, dont forget to Resolve your thread from the Thread Tools menu so others know its solved.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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