Joke Program

I should be able to figure this out, but I havn't worked on VB for a while and have forgot alot.

I want to create a program to flash up on the screen (form=visible) after a random time.  The form will remain visible for a random length of time (10-30 sec) then hide again for another random length of time (1-10 minutes).

Any help with the code...I am trying to make this a very small program so it does not take up too many system resources.
jbettsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jfleminCommented:
Dim siRandonTime as Single

siRandonTime = 0

' 10 - 30 seconds
Do Until siRandonTime >=10
     siRandonTime = Int((30 * Rnd) + 1)
Loop

siRandonTime = 0

' 0 - 10 minutes
Do Until siRandonTime >= 60
     siRandonTime = Int((600 * Rnd) + 1)
Loop
0
jfleminCommented:
Sorry. There were some typos

Dim siRandomTime as Single

siRandonTime = 0

' 10 - 30 seconds
Do Until siRandomTime >=10
    siRandomTime = Int((30 * Rnd) + 1)
Loop

siRandonTime = 0

' 1 - 10 minutes
Do Until siRandomTime >= 60
    siRandomTime = Int((600 * Rnd) + 1)
Loop
0
mcriderCommented:
Here is full example... If you want to use this, please reject the current answer and accept this as the answer:

1) Start a new project

2) Add a timer to the project

3) Paste the following code into the Declarations Section of the form and run the program.  The fist time the form will popup is 5 seconds after the program is started.

Cheers!


THE CODE:

Public WaitTime As Single
Private Sub Form_Load()
    Form1.Hide
    Form1.AutoRedraw = True
    Timer1.Interval = 5000
    Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
    Dim lWait1 As Integer
    Dim lWait2 As Integer
    Dim lTimer As Single
   
    If WaitTime < Timer Then
        Timer1.Enabled = False
        Randomize
        lWait1 = Int((30 * Rnd) + 10)
        lWait2 = Int((10 * Rnd) + 1)
        Form1.Show
        Form1.Cls
        Form1.Print "This form will hide in " + CStr(lWait1) + " seconds" + _
            " and will appear again in " + CStr(lWait2) + " minutes"
        lTimer = Timer + lWait1
        Do While Timer < lTimer
            DoEvents
        Loop
        Form1.Hide
        WaitTime = Timer + (60 * lWait2)
        Timer1.Enabled = True
    End If
End Sub
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Erick37Commented:
Here is another example.  If you use this you can reject the current answer and accept this comment as answer.

Private lCompare As Long

Private Sub Form_Load()
    Visible = False
    lCompare = 10 'Initial delay
    Timer1.Interval = 1000
    Randomize
End Sub

Private Sub Timer1_Timer()
    Static lSecs As Long
   
    lSecs = lSecs + 1
    If lCompare > lSecs Then Exit Sub
   
    If Visible Then
        Visible = False
        '1 to 10 minutes
        'Formula:
        'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
        lSecs = Int((541 * Rnd) + 60)
        lSecs = 0
    Else
        Visible = True
        '10 to 30 seconds
        lCompare = Int((21 * Rnd) + 10)
        lSecs = 0
    End If
End Sub
0
Erick37Commented:
Correction:

Private Sub Timer1_Timer()
    Static lSecs As Long
    
    lSecs = lSecs + 1
    If lCompare > lSecs Then Exit Sub
    
    If Visible Then
        Visible = False
        '1 to 10 minutes
        'Formula:
        'Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
        lCompare = Int((541 * Rnd) + 60) '<<< Correction
        lSecs = 0
    Else
        Visible = True
        '10 to 30 seconds
        lCompare = Int((21 * Rnd) + 10)
        lSecs = 0
    End If
End Sub
0
jbettsAuthor Commented:
Not as much details provided as later answers from other people
0
jbettsAuthor Commented:
Very good answer, I liked the amount of detail you provided.  Also worked successfully.
0
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.