?
Solved

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

Posted on 1998-11-06
9
Medium Priority
?
139 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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 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…
Suggested Courses

752 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