Solved

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

Posted on 1998-11-06
9
135 Views
Last Modified: 2010-04-30
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
0
Comment
Question by:visualbasic_18
  • 5
  • 4
9 Comments
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 200 total points
ID: 1443612
'Put this in the declaration part of your form:
Private Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long

Put this before the calculation
Dim lStart as long
lStart=GetTickCount()
'Calculations....
Labe1.Text=Cstr((GetTickCount()-lStart)/1000)
0
 

Author Comment

by:visualbasic_18
ID: 1443613
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 ?
0
 

Author Comment

by:visualbasic_18
ID: 1443614
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.
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:visualbasic_18
ID: 1443615
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 ?
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1443616
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.
0
 

Author Comment

by:visualbasic_18
ID: 1443617
how to get the same time
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1443618
It's impossible, there is no way to control it. Why do you need to do it anyway?
0
 

Author Comment

by:visualbasic_18
ID: 1443619
I just need to find a very accurate time
0
 
LVL 8

Expert Comment

by:MikeP090797
ID: 1443620
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
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question