Link to home
Start Free TrialLog in
Avatar of jbetts
jbetts

asked on

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.
Avatar of jflemin
jflemin

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
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
ASKER CERTIFIED SOLUTION
Avatar of mcrider
mcrider

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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
Avatar of jbetts

ASKER

Not as much details provided as later answers from other people
Avatar of jbetts

ASKER

Very good answer, I liked the amount of detail you provided.  Also worked successfully.
Thanks for the points! Glad I could help!


Cheers!