![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
This program makes 2 billion computations and I try to display the Start Time in a TextBox when the program starts and then display the Ending Time in another TextBox after all the computations are completed. But it doesn't display anything until all the computations are completed and then the Start Time and Ending Time are the same. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Starts the computation Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time Dim ElapsedTime As TimeSpan 'for calc of elapsed time Dim i As Long 'Loop control variable Dim result As Double 'TextBox2.Text = DateTime.Now.ToString TextBox2.Text = StartTime.ToString 'Console.Write(StartTime) 'I replaced the "Thread.Sleep(5000) with the For loop below 'Thread.Sleep(5000) 'sleep for 5 seconds For i = 1 To 2000000000 result = ((9.154 * 33 - 111.268) / (5.539 - 4.56501)) Next ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime) Dim ElapsedTimeText As String Dim EndingTime As DateTime = DateTime.Now 'ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'} & _ ' "{2,3:#0's'} {3,7:##0'ms'}", _ ElapsedTimeText = String.Format("{1,3:#0'm'} {2,3:#0's'} {3,7:##0'ms'}", _ ElapsedTime.Hours, ElapsedTime.Minutes, ElapsedTime.Seconds, ElapsedTime.Milliseconds) 'Bob wrote this as this is his code modified a little: although this is my code I don't understand how I get away with the above call to 'String.Format as the overloaded String.Format method doesn't, as far as I can see, 'support this number of arguments TextBox1.Visible = True TextBox8.Visible = True TextBox5.Visible = True TextBox6.Visible = True TextBox7.Visible = True TextBox9.Visible = True TextBox10.Visible = True 'MsgBox("My formatting yields: " & ElapsedTimeText) 'MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString) TextBox4.Text = StartTime.ToString TextBox6.Text = ElapsedTimeText TextBox7.Text = ElapsedTime.ToString TextBox8.Text = (i - 1).ToString TextBox10.Text = result.ToString End Sub End Class Is there a way to get this program to display the Start Time in a TextBox immediately when the program starts running and then about 9 seconds later display the Ending Time? Thanks in advance for your help. JungleJim74 |
#3
| |||
| |||
|
|
You are using an application (button2_click event). Try using application.doevents after each call to the clock. It will refresh your textbox then and there. -- Quack, I wouldn''t be asking this if I were anything but... "JungleJim74" wrote: This program makes 2 billion computations and I try to display the Start Time in a TextBox when the program starts and then display the Ending Time in another TextBox after all the computations are completed. But it doesn't display anything until all the computations are completed and then the Start Time and Ending Time are the same. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Starts the computation Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time Dim ElapsedTime As TimeSpan 'for calc of elapsed time Dim i As Long 'Loop control variable Dim result As Double 'TextBox2.Text = DateTime.Now.ToString TextBox2.Text = StartTime.ToString 'Console.Write(StartTime) 'I replaced the "Thread.Sleep(5000) with the For loop below 'Thread.Sleep(5000) 'sleep for 5 seconds For i = 1 To 2000000000 result = ((9.154 * 33 - 111.268) / (5.539 - 4.56501)) Next ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime) Dim ElapsedTimeText As String Dim EndingTime As DateTime = DateTime.Now 'ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'} & _ ' "{2,3:#0's'} {3,7:##0'ms'}", _ ElapsedTimeText = String.Format("{1,3:#0'm'} {2,3:#0's'} {3,7:##0'ms'}", _ ElapsedTime.Hours, ElapsedTime.Minutes, ElapsedTime.Seconds, ElapsedTime.Milliseconds) 'Bob wrote this as this is his code modified a little: although this is my code I don't understand how I get away with the above call to 'String.Format as the overloaded String.Format method doesn't, as far as I can see, 'support this number of arguments TextBox1.Visible = True TextBox8.Visible = True TextBox5.Visible = True TextBox6.Visible = True TextBox7.Visible = True TextBox9.Visible = True TextBox10.Visible = True 'MsgBox("My formatting yields: " & ElapsedTimeText) 'MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString) TextBox4.Text = StartTime.ToString TextBox6.Text = ElapsedTimeText TextBox7.Text = ElapsedTime.ToString TextBox8.Text = (i - 1).ToString TextBox10.Text = result.ToString End Sub End Class Is there a way to get this program to display the Start Time in a TextBox immediately when the program starts running and then about 9 seconds later display the Ending Time? Thanks in advance for your help. JungleJim74 |
#4
| |||
| |||
|
|
This program makes 2 billion computations and I try to display the Start Time in a TextBox when the program starts and then display the Ending Time in another TextBox after all the computations are completed. But it doesn't display anything until all the computations are completed and then the Start Time and Ending Time are the same. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'Starts the computation Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time Dim ElapsedTime As TimeSpan 'for calc of elapsed time Dim i As Long 'Loop control variable Dim result As Double 'TextBox2.Text = DateTime.Now.ToString TextBox2.Text = StartTime.ToString 'Console.Write(StartTime) 'I replaced the "Thread.Sleep(5000) with the For loop below 'Thread.Sleep(5000) 'sleep for 5 seconds For i = 1 To 2000000000 result = ((9.154 * 33 - 111.268) / (5.539 - 4.56501)) Next ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime) Dim ElapsedTimeText As String Dim EndingTime As DateTime = DateTime.Now 'ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'} & _ ' "{2,3:#0's'} {3,7:##0'ms'}", _ ElapsedTimeText = String.Format("{1,3:#0'm'} {2,3:#0's'} {3,7:##0'ms'}", _ ElapsedTime.Hours, ElapsedTime.Minutes, ElapsedTime.Seconds, ElapsedTime.Milliseconds) 'Bob wrote this as this is his code modified a little: although this is my code I don't understand how I get away with the above call to 'String.Format as the overloaded String.Format method doesn't, as far as I can see, 'support this number of arguments TextBox1.Visible = True TextBox8.Visible = True TextBox5.Visible = True TextBox6.Visible = True TextBox7.Visible = True TextBox9.Visible = True TextBox10.Visible = True 'MsgBox("My formatting yields: " & ElapsedTimeText) 'MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString) TextBox4.Text = StartTime.ToString TextBox6.Text = ElapsedTimeText TextBox7.Text = ElapsedTime.ToString TextBox8.Text = (i - 1).ToString TextBox10.Text = result.ToString End Sub End Class Is there a way to get this program to display the Start Time in a TextBox immediately when the program starts running and then about 9 seconds later display the Ending Time? Thanks in advance for your help. JungleJim74 |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |