473,322 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

doubt: setting intervals in a loop

Hi,

I'm a novice at .net, can anyone please tell me how i can set an interval in a for loop? for example if i want a message box saying "hello this is loop 1" to "hello this is loop 10" after every 3 seconds. Problem is once my program reaches the for loop, i get message boxes instantly one after the other. Not after every 3 secs. Can someone please guide me?

i tried this but to no avail

---------
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim i = 0
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Timer1.Enabled = True
  5.         Timer1.Interval = 3000
  6.     End Sub
  7.  
  8.     Private Sub command1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  9.         For i = 0 To 10
  10.             MsgBox("This is Loop " & i)
  11.  
  12.         Next i
  13.         Timer1.Enabled = False
  14.  
  15.     End Sub
  16. End Class
Sep 25 '07 #1
4 1030
nateraaaa
663 Expert 512MB
Hi,

I'm a novice at .net, can anyone please tell me how i can set an interval in a for loop? for example if i want a message box saying "hello this is loop 1" to "hello this is loop 10" after every 3 seconds. Problem is once my program reaches the for loop, i get message boxes instantly one after the other. Not after every 3 secs. Can someone please guide me?

i tried this but to no avail

---------
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.     Dim i = 0
  3.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  4.         Timer1.Enabled = True
  5.         Timer1.Interval = 3000
  6.     End Sub
  7.  
  8.     Private Sub command1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  9.         For i = 0 To 10
  10.             MsgBox("This is Loop " & i)
  11.  
  12.         Next i
  13.         Timer1.Enabled = False
  14.  
  15.     End Sub
  16. End Class
Try putting a Thread.Sleep(3000) before the Next i line in your code.

Nathan
Sep 25 '07 #2
Plater
7,872 Expert 4TB
You could also look into the Timer object (either the one in Windows.Forms or or one of the other ones) and only have the event fire every X amount of seconds
Sep 25 '07 #3
can you please remake the above program for me. I couldn't understand how to use thread.sleep or timers..
Sep 27 '07 #4
nateraaaa
663 Expert 512MB
can you please remake the above program for me. I couldn't understand how to use thread.sleep or timers..
see the following site for an example on how to use threading.

Nathan
Sep 27 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Salmo Bytes | last post by:
I want to make an animated gif that runs through one loop and then stops. But I want to invoke it at random time intervals...so, for instance, a tight head shot of a person's face winks at the...
7
by: vanisathish | last post by:
Hi All, 1 ) I am using the Date() function to get the current time. But it doesnt tell me the time value in millisec. Is there any API in javascript that returns the current time value with...
2
by: Mike | last post by:
I'm more unsure of myself these days: Given a result set of rows with discrete date intevals; but rows may be non contiguous in nature; Can a simple, non cursor driven query produce a result with...
14
by: Crirus | last post by:
This is more a logical problem than a VB. I have this situation: A timer that need to tick at each 10 minutes starting on minute 15 of curent hour. But I want to calculate the next tick...
4
by: barker7 | last post by:
In our app, we need to collect data at regular intervals (4, 8 or 16 seconds - user settable). The collection happens in a background thread. My first approach was to do the collection, which takes...
2
by: Rombolt | last post by:
Hi I have a MSSQL table with many time intervals stored as datetime. Each time interval is also assigned a numeric type that specifies what type of job was done during the time interval. I need to...
2
by: johnbkim | last post by:
I'm using JPGraph to plot temperature vs. time. Time is given as timestamps, so I use a callback function to print it as hours and minutes. Here's the graph and the code: ...
1
by: Yammi | last post by:
Ok, I know that there is a very smart programmer out there that can resovle my issue. I am trying to calculate time worked by 15 minute intervals. Example: ================= Emp 1 started...
1
by: lenygold via DBMonster.com | last post by:
I found this query on older thread and i can not uderstand output interval pairs: How to find min and max values in date intervals: -------------------------------------------------- Input:...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.