• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4377
  • Last Modified:

VB6 - random 2 min - 5 min delay + hide app from task manager

I need code to effect a random delay from 2 to 5 minutes, and I need the program to not show up on the task manager.  This is for a practical joke ;-)

Thanks.
0
SilentBob
Asked:
SilentBob
1 Solution
 
anvCommented:
try this code...

add 2 timer Controls into ur application

set Timer2 Interval =5000 (i.e 5 Seconds) at design time

and paste this code...

Private Sub Form_Activate()
    Randomize (5)
    Dim i!
    i = Rnd() * 1000
    If ((i >= 2000) And (i <= 5000)) Then
        Timer1.Interval = i
    Else
        Timer1.Interval = 2000
    End If
End Sub

Private Sub Timer1_Timer()
    Me.Visible = False
    Timer2.Enabled = True
    Timer1.Enabled = False
End Sub

Private Sub Timer2_Timer()
    Timer1.Enabled = True
    Me.Visible = True
    Timer2.Enabled = False
End Sub
0
 
fds_fatboyCommented:
This "practical joke" code looks like it could be used for malicious purposes. For that reason I will not answer.

anv
That code will not work for the following reasons:
- Randomize (5) - will seed the timer, so that  - i = Rnd() * 1000 - will always return the same result into i.
- If ((i >= 2000) And (i <= 5000)) Then - will never be true i will always be less than 1000 because rnd() returns a number greater or equal to  0 and less than 1.

The timers will cause the form to flash on and off in 2 second intervals.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is how to get a random delay between 2 and 5 minutes using a Timer control:

Option Explicit

Private targetTime As Date

Private Sub Form_Load()
    Call pickNextTime
    Timer1.Interval = 1000 ' check currentTime against targetTime every second
    Timer1.Enabled = True
End Sub

Private Sub pickNextTime()
    ' Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
    Dim secs As Integer
    secs = Int((300 - 120 + 1) * Rnd + 120) ' 2 - 5 minutes in seconds
    targetTime = DateAdd("s", secs, Now())
    Debug.Print targetTime
End Sub

Private Sub Timer1_Timer()
    If Now() > targetTime Then
        Timer1.Enabled = False
       
        ' do something in here
        MsgBox "hi"
       
        Call pickNextTime
       
        Timer1.Enabled = True
    End If
End Sub
0
 
SilentBobAuthor Commented:
Hi all.  I worked out the timer part already thanks.  Just need to hide the app from trivial investigation.  Yes, I am aware this code can be used for malicious purposes, and could be a real headache for someone who doesn't know a lot about computers, but what I intend to code will not hurt anyone, and will definitely not go past a joke.  I understand trust is a rare comodity on a public group such as this where most people are strangers, so if you don't beleive me, that's cool.

Cheers,

0
 
anvCommented:
split points between all..
0

Featured Post

Get your problem seen by more experts

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

Tackle projects and never again get stuck behind a technical roadblock.
Join Now