Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:57:27+00:00 2026-06-08T01:57:27+00:00

I have a case where i need to generate millions of unique codes. For

  • 0

I have a case where i need to generate millions of unique codes. For this I have created a generate function where the random number is generated. I call this function from a for loop and add the generated number on a list box. my code is as follow

  for i=1 to val(txtnumber.txt)
       mynum=generate()
  next

I have created a lable on form where i wanted to display the no of secs elapsed while processing the loop. I used timer control as

     timer1.start()
     for i=1 to val(txtnumber.text)
        mynum=generate()
        listbox1.items.add(mynum)
     next
     timer1.stop

and on timer1_tick function

     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Label1.Text = Val(Label1.Text) + 1
     End Sub

but when i click generate button, all numbers are generated, but timer doesnot shows time elapsed.

I may have missed something, so please help me out

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:57:28+00:00Added an answer on June 8, 2026 at 1:57 am

    This is probably best handled in a BackgroundWorker. Place one on the form and set its WorkerReportsProgress=True. Also, placing a million numbers in a ListBox probably isn’t a good idea, so I omitted that.

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
      Button1.Enabled = False
      BackgroundWorker1.RunWorkerAsync()
    End Sub
    
    Private Sub BackgroundWorker1_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs) Handles BackgroundWorker1.DoWork
      Dim started As DateTime = Now
      For i As Integer = 1 To val(txtnumber.txt)
        mynum=generate()
        BackgroundWorker1.ReportProgress(i, Nothing)
      Next
      Dim ended As TimeSpan = Now.Subtract(started)
      BackgroundWorker1.ReportProgress(0, ended.TotalSeconds.ToString)
    End Sub
    
    Private Sub BackgroundWorker1_ProgressChanged(ByVal sender As Object, ByVal e As ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
      If e.UserState IsNot Nothing Then
        Label1.Text = e.UserState.ToString()
      Else
        Label1.Text = e.ProgressPercentage.ToString
      End If
    End Sub
    
    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
      Button1.Enabled = True
    End Sub
    

    Your label should be updating correctly when the worker reports the ProgressChanged event.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have develop this function which uses recursion to call itself. I need to
I have a case where I need to select a random item, but I
I have a case where I need to load bitmap from a resource dll
I have a use case where I need to call a (non-static) method in
I need to generate a random number that is between a minimum value and
Possible Duplicate: Generate random number with non-uniform density I try to identify/create a function
I have a case where I need to update a jqgrid based on some
I have a very specific case that I need to debug. I need to
I have a use case where I only need to store certain fields to
I have a complicated problem, and I need help. I have a base case,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.