[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Joke Program

Posted on 1999-12-10
8
Medium Priority
?
228 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:jbetts
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 1

Expert Comment

by:jflemin
ID: 2272578
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
 
LVL 1

Expert Comment

by:jflemin
ID: 2272588
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
 
LVL 14

Accepted Solution

by:
mcrider earned 400 total points
ID: 2272633
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 32

Expert Comment

by:Erick37
ID: 2272699
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
 
LVL 32

Expert Comment

by:Erick37
ID: 2272728
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
 

Author Comment

by:jbetts
ID: 2277161
Not as much details provided as later answers from other people
0
 

Author Comment

by:jbetts
ID: 2277164
Very good answer, I liked the amount of detail you provided.  Also worked successfully.
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2277204
Thanks for the points! Glad I could help!


Cheers!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

612 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question