Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Ok, I have this code below, when a form will appear, a message box spam will be in processed.

Private Sub form_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
timer.Start()

Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrnote.Tick
        MsgBox("I got you!", vbCritical, "LOL")


However, I want that only 10 messagebox to appear then after that it will be topped, and another form will appear. How to do this? It's a prank software, I'm doing.
Posted
Updated 7-Apr-11 10:46am
v2
Comments
HimanshuJoshi 7-Apr-11 16:46pm    
Added pre tags around code.

Use static variable:
VB
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrnote.Tick
Static iCount as Integer
    if iCount <10 then MsgBox("I got you!", vbCritical, "LOL")
    iCount = iCOunt +1

or global variable:
VB
Dim iCount As Integer = 0
Private Sub timer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrnote.Tick
    if iCount >10 then MsgBox("I got you!", vbCritical, "LOL")
    iCOunt = iCount+1
 
Share this answer
 
Comments
555336 7-Apr-11 17:26pm    
but when it stops, i want to make another form to appear, how to do that?
Albin Abel 8-Apr-11 11:45am    
My 5
i_share7 17-Sep-16 17:06pm    
Instead of :
iCount = iCount + 1

It's easier to do:

iCount += 1

Just to help things to keep tidy! :)
[Adding to the previous answer you got from losmac]

First of all you don't need a static or global variable here, you can make your count variable a member field in the form derived class.

And on the 11th call, stop the timer, and show your new form (all this can be done in the timer tick handler).
 
Share this answer
 
Comments
Albin Abel 8-Apr-11 11:46am    
agreed. No need of static here. My 5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900