Results 1 to 16 of 16

Thread: How to make Intervals

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Unhappy

    Heres my problem (aside from not programming too good )..I am making a program. 1 main form, 2 control buttons, 1 text box. I want to to work so that the user cant type in a number like 10 into the textbox then press the first command button and every 10 seconds the form color will change to something different. Then when the 2nd command button is pressed the changes stop and it goes back to the original form color..Im not really sure how to do this, any help is greatly appreciated in advance, thanx.

  2. #2
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Thumbs up

    Ill create you a simple sample application. ill give you the code tommarow 8-21
    Matt

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Cool cool

    Cool thanks...I know its more than likely something very simple to do but im limited on how much learn time I can get in for vb and im still (in my opinion) not gettin any better at it but oh well all in its own time I guess...thanx again

  4. #4
    Guest
    here ya go, add 2 Command Buttons, a TextBox, and a Timer.

    Code:
    Dim RndColor As Integer
    
    Private Sub Command1_Click()
        Timer1.Interval = Val(Text1.Text) * 1000
        Timer1.Enabled = True
    End Sub
    
    Private Sub Command2_Click()
        Timer1.Enabled = False
        Me.BackColor = vbButtonFace
    End Sub
    
    Private Sub Timer1_Timer()
    'random number 1 to 5
        RndColor = Int((Rnd * 5) + 1)
    
        With Me
            Select Case RndColor
                Case 1
                    .BackColor = vbGreen
                Case 2
                    .BackColor = vbRed
                Case 3
                    .BackColor = vbYellow
                Case 4
                    .BackColor = vbBlue
                Case 5
                    .BackColor = vbApplicationWorkspace
            End Select
        End With
    End Sub

  5. #5
    Guest
    Here is the form color code:

    Code:
    'Timer set at 100 (faster results: set interval to 1)
    'Form_Load:  
    Timer1.Interval = 100
    Timer1.Enabled = False
    
    Private Sub Timer1_Timer()
    Me.BackColor = QBColor(Rnd * 15)
    End Sub
    
    Private Sub Command1_Click()
    Timer1.Enabled = True
    End Sub
    
    Private Sub Command2_Click()
    Timer1.Enabled = False
    End Sub

  6. #6
    Guest
    Matthew:

    I set the timer interval to 1, now I have a headache, be careful, that code is likely to cause siesures

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Talking COOL

    Wow! thanx! I guess im happy cause im not that good so help is HIGHLY appreciated. Mabye I can be that good someday to just be able to post code help to people on here. Thanx a million to all of you you sent me some assistance!

  8. #8
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330

    Talking try this

    I worked out this
    'in a module
    Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

    'in general
    Option Explicit
    Dim backclr As Long ' declare the variable publicly to hold form1.backcolor

    Private Sub Cmdstart_Click()
    Timer1.Enabled = True 'enabled timer
    backclr = Form1.BackColor 'set the value of backcolor as soon as you hit the button
    End Sub

    Private Sub cmdstop_Click()
    Timer1.Enabled = False ' disable timer
    Form1.BackColor = backclr 'set the backcolor to the original
    End Sub

    Private Sub Timer1_Timer()
    Dim time As Integer
    time = Val(Text1.Text) & "000" 'set time = to text1.text and add the zeros to convert to seconds sience its in milliseconds
    Sleep (time) 'API call sleep for the time in textbox
    Form1.BackColor = QBColor(Rnd * 15) ' set the backcolor to a random value
    End Sub

    hope this helps
    Matt

  9. #9
    Hyperactive Member MPrestonf12's Avatar
    Join Date
    Jun 1999
    Location
    NY
    Posts
    330
    oh yeah and set imter interval to 1, enabled = false
    Matt

  10. #10

    Thread Starter
    Member
    Join Date
    Apr 2000
    Posts
    35

    Thumbs up great!

    This is awesome, Im glad I got replies from different people who code it somewhat differently, it helps me to understand how to not set myself linear when thinking of how to put something "into action". Much thanks to everyone who posted. Im out

    -CraZy 8

  11. #11
    Guest
    Hehe, Dennis, set it to black and white and you'll have to go lie down .

    Code:
    Private Declare Sub Sleep Lib "kernel32" _
    (ByVal dwMilliseconds As Long)
    
    Private Sub Timer1_Timer()
    Me.BackColor = &H0&
    Sleep 100
    Me.BackColor = &HFFFFFF
    Sleep 100
    End Sub
    You can also use RGB doing it as well for the 255 color effect ;].

    Code:
    Me.BackColor = RGB((Rnd * 255), (Rnd * 255), (Rnd * 255))

  12. #12
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yep, but it's better to use the simplest way
    Code:
    Me.BackColor = int(rnd * &H1000000)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  13. #13
    Guest
    Yeah, but it would be even better if John would stop thinking about Mrs. Le Pont and fix that number problem


  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yeah, that really get's non my nerves
    Code:
    1000000000000000000000000000000000000000000000000000000
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  15. #15
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    What?!?!? Let me try again
    Code:
    int(rnd * &H100000000000000000000000000000000000000000)
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  16. #16
    Guest
    now That is screwed up!

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