Link to home
Start Free TrialLog in
Avatar of visualbasic_18
visualbasic_18

asked on

easy ?????????????

I have a math vb program.

And I would like to know how much time (sec or less) does
program need to find the asnwer. Because this is 200 points,
so I need experts to explain to me in detail, if it is
possible ? (please, bec. I am new)

in the form I have :
 some label and textbox for entering and displaying.
 a ok button - that will take the input and find out the
               answer.
My guess is : when user hit "ok" button, the timer should start and when answer is found out, then timer stop. The time that program need to find out the answer should be able
to be displayed in sec or sometime is .001 sec.

so in "ok" procedure , I have :

some declarations
.
.
.
.


do
'calculation
loop until ok = 0

display answer and time.



if you need more information, comment me, please.
or you can suggest you own program.

thank a lot
ASKER CERTIFIED SOLUTION
Avatar of MikeP090797
MikeP090797

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of visualbasic_18
visualbasic_18

ASKER

Thank you. here is my code :

Private Sub Command1_Click()
Dim lStart As Long
   
   
   
ok = 1
a1 = Val(inta.Text)
a2 = 1
a3 = 0
b1 = Val(intb.Text)
b2 = 0
b3 = 1
 lStart = GetTickCount()
Do

    If a1 = 1 Then
       X1.Text = a1
       X2.Text = a2
       x3.Text = a3
       ok = 0
    End If
    If b1 = 1 Then
       X1.Text = b1
       X2.Text = b2
       x3.Text = b3
       ok = 0
    End If
    If a1 > b1 Then
       a1 = a1 - b1
       a2 = a2 - b2
       a3 = a3 - b3
    End If
    If b1 > a1 Then
       b1 = b1 - a1
       b2 = b2 - a2
       b3 = b3 - a3
    End If
Loop Until ok = 0
 
c.Text = CStr((GetTickCount() - lStart) / 1000)
 
 
 
End Sub


am I right ?
If my code is right, then can you explain the meaning of this code to me :

1.  Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
2.  Dim lStart as long
3.  IStart=GetTickCount()        ' what is this ?
4.  Labe1.Text=Cstr((GetTickCount()-lStart)/1000)  ''what is Cstr ?

Why i never see the   (  1.  ) line of code, where do you get it and where I can find more information about it, because I can't this code in my vb book.

I have ran the program and it give me 0.064 for time. What does that means ? a sec or less than sec.
another question :

I inputed 12 and 41, when I got the answer, I pressed the ok button again and
again, but it gave me different time , why ?
I think the time should be same , because the input is same, why ?
The First line is a declaration of a Windows API procedure. Read the help on 'Declare' to get more info. GetTickCount returns the number of milliseconds (1/1000 of second) since the time Windows started, so when you compare the return values between 2 calls, you get the interval. The time is in seconds, so 0.something is less then a second. It gives different time on each run, because each time windows allocated specific time for your process, it's a normal phenomenon.
how to get the same time
It's impossible, there is no way to control it. Why do you need to do it anyway?
I just need to find a very accurate time
The time is as accurate as it gets, but it takes the algorithm a different time to run every time. It depends on a lot of factors, none of them are at your control. It's like if you measure how much time exactly it takes a program to load, you will find out it's never the same