Solved

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

Posted on 1998-11-06
9
130 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
Comment Utility
'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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:visualbasic_18
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 8

Expert Comment

by:MikeP090797
Comment Utility
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
Comment Utility
how to get the same time
0
 
LVL 8

Expert Comment

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

Author Comment

by:visualbasic_18
Comment Utility
I just need to find a very accurate time
0
 
LVL 8

Expert Comment

by:MikeP090797
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
VBA to format 3 77
VB6 convert MSHFlexgrid1 cells no2 2 50
vba find the last empty column 10 81
Using "ScreenUpdating" 6 45
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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.
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now