![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#11
| |||
| |||
|
|
Hans, I believe that my problem is caused by the fact the you MVPs put in a snippet of code that will do the job but you don't tell me what I have to include in my code to get the snippet to compile and run successfully. You assume that everybody knows how to include all entries that will make your snippet compile and run but that is just not so. I say this respectfully: You MVPs are so very advanced that you have forgotten what it is like to be a beginner. Have a good day. Respectfully, JungleJim74 |
|
"Hans Kesting" wrote: JungleJim74 formulated the question : I am using Visual Studio 2003 and am trying to compute and display the elapsed time that my computer takes to calculate ((2.154*33)-161.376 / (3.541*7)). I have the interface prepared and the program makes this calculation 2,000,000,000 in 5 seconds. I display the start time and the end time with start = Now and end = Now and this works OK for the display purposes. But I do not know how to compute the elapsed time. I have declared the variables "start"and ënd" as strings and this declaration may be the source of my trouble. Thanks in advance for any help on this. JungleJim74 Just a note: if that formula is a copy from your test-program, then you might end up testing the wrong thing! The compiler already performs calculations with fixed numbers, so runtime the formula would be replaced by a single value. A formula "a=2*3" is compiled as "a=6". Hans Kesting |
#12
| |||
| |||
|
|
Thank you Hans but I am beginning to believe that I am in over my head and that I need to study VB.NET a lot more BEFORE I try to write and compile this tyoe of program. I have tried to follow all of the responses posted to my request for help but no matter which one I try all I get is compiler errors. If the code does not compile you sure cannot run an executable. But I thank you both again for trying to help me. JungleJim74 (I'm 81 years old and I guess I just don't have it anymore) "Hans Kesting" wrote: JungleJim74 formulated the question : I am using Visual Studio 2003 and am trying to compute and display the elapsed time that my computer takes to calculate ((2.154*33)-161.376 / (3.541*7)). I have the interface prepared and the program makes this calculation 2,000,000,000 in 5 seconds. I display the start time and the end time with start = Now and end = Now and this works OK for the display purposes. But I do not know how to compute the elapsed time. I have declared the variables "start"and ënd" as strings and this declaration may be the source of my trouble. Thanks in advance for any help on this. JungleJim74 Just a note: if that formula is a copy from your test-program, then you might end up testing the wrong thing! The compiler already performs calculations with fixed numbers, so runtime the formula would be replaced by a single value. A formula "a=2*3" is compiled as "a=6". Hans Kesting |
#13
| |||
| |||
|
|
Hans, Here is some sample code which produces an elapsed time value. Note that I am not an expert at this stuff. So my sample code might not be the best, but I don't think that it will lead you astray. I used the VS IDE/designer but did not place any controls on the form. -------------------------------------------------------------------------- Option Explicit On Option Strict On ' always use the two options above because they allow the compiler ' to catch things which can cause run time errors Imports System.Threading ' System.Threading needed for the Sleep function Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time Dim ElapsedTime As TimeSpan 'for calc of elapsed time Dim ElapsedTimeText As String ' for displaying elapsed time Thread.Sleep(1000) 'sleep for 1 second ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime) ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'}" & _ " {2,3:#0's'}{3,7:##0'ms'}", _ ElapsedTime.Hours, ElapsedTime.Minutes, _ ElapsedTime.Seconds, ElapsedTime.Milliseconds) ' although this is my code (I can't blame it on anyone else), I ' don't understand how I get away with the above call to ' String.Format as the overloaded String.Format method doesn't, ' so far as I can see, support this number of arguments ' the formatting specification is not intuitive and documentation can ' be difficult to find. But if you look at the doc for String Members ' and then the Format method and then follow the link to ' Composite Formatting I think you'll find pretty decent documentation. MsgBox("My formatting yields: " & ElapsedTimeText) MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString) End Sub End Class ----------------------------------------------------------------------------------- Good Luck, Bob "JungleJim74" <JungleJim74 (AT) discussions (DOT) microsoft.com> wrote in message news:F55DE265-6E07-4F1F-9496-08314D182002 (AT) microsoft (DOT) com... Thank you Hans but I am beginning to believe that I am in over my head and that I need to study VB.NET a lot more BEFORE I try to write and compile this tyoe of program. I have tried to follow all of the responses posted to my request for help but no matter which one I try all I get is compiler errors. If the code does not compile you sure cannot run an executable. But I thank you both again for trying to help me. JungleJim74 (I'm 81 years old and I guess I just don't have it anymore) "Hans Kesting" wrote: JungleJim74 formulated the question : I am using Visual Studio 2003 and am trying to compute and display the elapsed time that my computer takes to calculate ((2.154*33)-161.376 / (3.541*7)). I have the interface prepared and the program makes this calculation 2,000,000,000 in 5 seconds. I display the start time and the end time with start = Now and end = Now and this works OK for the display purposes. But I do not know how to compute the elapsed time. I have declared the variables "start"and ënd" as strings and this declaration may be the source of my trouble. Thanks in advance for any help on this. JungleJim74 Just a note: if that formula is a copy from your test-program, then you might end up testing the wrong thing! The compiler already performs calculations with fixed numbers, so runtime the formula would be replaced by a single value. A formula "a=2*3" is compiled as "a=6". Hans Kesting |
#14
| |||
| |||
|
|
Meant for JungleJim74 for Hans. Sorry. "eBob.com" <eBob.com (AT) totallybogus (DOT) com> wrote in message news:uhxDFZD8JHA.4632 (AT) TK2MSFTNGP02 (DOT) phx.gbl... Hans, Here is some sample code which produces an elapsed time value. Note that I am not an expert at this stuff. So my sample code might not be the best, but I don't think that it will lead you astray. I used the VS IDE/designer but did not place any controls on the form. -------------------------------------------------------------------------- Option Explicit On Option Strict On ' always use the two options above because they allow the compiler ' to catch things which can cause run time errors Imports System.Threading ' System.Threading needed for the Sleep function Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time Dim ElapsedTime As TimeSpan 'for calc of elapsed time Dim ElapsedTimeText As String ' for displaying elapsed time Thread.Sleep(1000) 'sleep for 1 second ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime) ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'}" & _ " {2,3:#0's'}{3,7:##0'ms'}", _ ElapsedTime.Hours, ElapsedTime.Minutes, _ ElapsedTime.Seconds, ElapsedTime.Milliseconds) ' although this is my code (I can't blame it on anyone else), I ' don't understand how I get away with the above call to ' String.Format as the overloaded String.Format method doesn't, ' so far as I can see, support this number of arguments ' the formatting specification is not intuitive and documentation can ' be difficult to find. But if you look at the doc for String Members ' and then the Format method and then follow the link to ' Composite Formatting I think you'll find pretty decent documentation. MsgBox("My formatting yields: " & ElapsedTimeText) MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString) End Sub End Class ----------------------------------------------------------------------------------- Good Luck, Bob "JungleJim74" <JungleJim74 (AT) discussions (DOT) microsoft.com> wrote in message news:F55DE265-6E07-4F1F-9496-08314D182002 (AT) microsoft (DOT) com... Thank you Hans but I am beginning to believe that I am in over my head and that I need to study VB.NET a lot more BEFORE I try to write and compile this tyoe of program. I have tried to follow all of the responses posted to my request for help but no matter which one I try all I get is compiler errors. If the code does not compile you sure cannot run an executable. But I thank you both again for trying to help me. JungleJim74 (I'm 81 years old and I guess I just don't have it anymore) "Hans Kesting" wrote: JungleJim74 formulated the question : I am using Visual Studio 2003 and am trying to compute and display the elapsed time that my computer takes to calculate ((2.154*33)-161.376 / (3.541*7)). I have the interface prepared and the program makes this calculation 2,000,000,000 in 5 seconds. I display the start time and the end time with start = Now and end = Now and this works OK for the display purposes. But I do not know how to compute the elapsed time. I have declared the variables "start"and ënd" as strings and this declaration may be the source of my trouble. Thanks in advance for any help on this. JungleJim74 Just a note: if that formula is a copy from your test-program, then you might end up testing the wrong thing! The compiler already performs calculations with fixed numbers, so runtime the formula would be replaced by a single value. A formula "a=2*3" is compiled as "a=6". Hans Kesting |
#15
| |||
| |||
|
|
JungleJim74 was thinking very hard : Hans, I believe that my problem is caused by the fact the you MVPs put in a snippet of code that will do the job but you don't tell me what I have to include in my code to get the snippet to compile and run successfully. You assume that everybody knows how to include all entries that will make your snippet compile and run but that is just not so. I say this respectfully: You MVPs are so very advanced that you have forgotten what it is like to be a beginner. Have a good day. Respectfully, JungleJim74 True, it has been a while since I was a beginner (and I am not an MVP, that is a sort of official title - but never mind that). On the other hand it is difficult to answer at the precise level: If I answer at a very basic level, then someone with already some experience might also feel offended (plus it would take a lot more time to answer a question). It is not always clear what level the poster has. Also I usually want to point the asker in the right direction, so he/she can get more information and learn how things work, rather than just give "finished" code. You are right: sometimes a code snippet can illustrate the point better. But then a further complication pops in: I am a C# programmer and apparently you are using VB.Net. For framework issues (such as how the TimeSpan and DateTime struct work) that is not a problem (C# and VB use the same framework), but for code snippets it is: I have to guess at the VB syntax. But let's try: I assume in the snippets that there is a method 'PerformCalculation' that performs the calculations you want to measure. Also you will need to place this code in a method where you can execute it. ' Calculate a time using DateTime Dim start as DateTime Din end as DateTime start = DateTime.Now PerformCalculation end = DateTime.Now Dim elapsed as TimeSpan elapsed = end - start Console.WriteLine(elapsed.TotalMilliseconds) ' Calculate using Stopwatch Dim sw as new System.Diagnostics.Stopwatch sw.Start PerformCalculation sw.Stop Console.WriteLine(sw.ElapsedMilliseconds) As for a second remark: if you have in you code something like: result=((2.154*33)-161.376 / (3.541*7)) try replacing that with result = 64.571 to find out if that makes any difference in speed (it shouldn't) Hans Kesting "Hans Kesting" wrote: JungleJim74 formulated the question : I am using Visual Studio 2003 and am trying to compute and display the elapsed time that my computer takes to calculate ((2.154*33)-161.376 / (3.541*7)). I have the interface prepared and the program makes this calculation 2,000,000,000 in 5 seconds. I display the start time and the end time with start = Now and end = Now and this works OK for the display purposes. But I do not know how to compute the elapsed time. I have declared the variables "start"and ënd" as strings and this declaration may be the source of my trouble. Thanks in advance for any help on this. JungleJim74 Just a note: if that formula is a copy from your test-program, then you might end up testing the wrong thing! The compiler already performs calculations with fixed numbers, so runtime the formula would be replaced by a single value. A formula "a=2*3" is compiled as "a=6". Hans Kesting |
#16
| |||
| |||
|
|
Meant for JungleJim74 for Hans. Sorry. "eBob.com" <eBob.com (AT) totallybogus (DOT) com> wrote in message news:uhxDFZD8JHA.4632 (AT) TK2MSFTNGP02 (DOT) phx.gbl... Hans, Here is some sample code which produces an elapsed time value. Note that I am not an expert at this stuff. So my sample code might not be the best, but I don't think that it will lead you astray. I used the VS IDE/designer but did not place any controls on the form. -------------------------------------------------------------------------- Option Explicit On Option Strict On ' always use the two options above because they allow the compiler ' to catch things which can cause run time errors Imports System.Threading ' System.Threading needed for the Sleep function Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim StartTime As DateTime = DateTime.Now 'for calc of elapsed time Dim ElapsedTime As TimeSpan 'for calc of elapsed time Dim ElapsedTimeText As String ' for displaying elapsed time Thread.Sleep(1000) 'sleep for 1 second ElapsedTime = DateTime.op_Subtraction(DateTime.Now, StartTime) ElapsedTimeText = String.Format("{0,2:#0'h'} {1,3:#0'm'}" & _ " {2,3:#0's'}{3,7:##0'ms'}", _ ElapsedTime.Hours, ElapsedTime.Minutes, _ ElapsedTime.Seconds, ElapsedTime.Milliseconds) ' although this is my code (I can't blame it on anyone else), I ' don't understand how I get away with the above call to ' String.Format as the overloaded String.Format method doesn't, ' so far as I can see, support this number of arguments ' the formatting specification is not intuitive and documentation can ' be difficult to find. But if you look at the doc for String Members ' and then the Format method and then follow the link to ' Composite Formatting I think you'll find pretty decent documentation. MsgBox("My formatting yields: " & ElapsedTimeText) MsgBox("TimeSpan.ToString yields: " & ElapsedTime.ToString) End Sub End Class ----------------------------------------------------------------------------------- Good Luck, Bob "JungleJim74" <JungleJim74 (AT) discussions (DOT) microsoft.com> wrote in message news:F55DE265-6E07-4F1F-9496-08314D182002 (AT) microsoft (DOT) com... Thank you Hans but I am beginning to believe that I am in over my head and that I need to study VB.NET a lot more BEFORE I try to write and compile this tyoe of program. I have tried to follow all of the responses posted to my request for help but no matter which one I try all I get is compiler errors. If the code does not compile you sure cannot run an executable. But I thank you both again for trying to help me. JungleJim74 (I'm 81 years old and I guess I just don't have it anymore) "Hans Kesting" wrote: JungleJim74 formulated the question : I am using Visual Studio 2003 and am trying to compute and display the elapsed time that my computer takes to calculate ((2.154*33)-161.376 / (3.541*7)). I have the interface prepared and the program makes this calculation 2,000,000,000 in 5 seconds. I display the start time and the end time with start = Now and end = Now and this works OK for the display purposes. But I do not know how to compute the elapsed time. I have declared the variables "start"and ënd" as strings and this declaration may be the source of my trouble. Thanks in advance for any help on this. JungleJim74 Just a note: if that formula is a copy from your test-program, then you might end up testing the wrong thing! The compiler already performs calculations with fixed numbers, so runtime the formula would be replaced by a single value. A formula "a=2*3" is compiled as "a=6". Hans Kesting |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |