[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 1998-11-06
9
Medium Priority
?
149 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 800 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month20 days, 4 hours left to enroll

872 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