Which is more efficient?

R

RyanH

I have a button that is used to make several calculations using a value from
a textbox (tbxQuantity) in my UserForm. This value could be used 10 to 100
times in one procedure. I was wondering what would be the most efficient way
of writng my equations. When I mean efficient I mean speed. Which is more
efficient?

Sub Calculate()

Dim Qty as Integer

Qty = Val(tbxQuantity)
Price = Cost * MarkUp * Qty

End Sub

or

Sub Calculate()

Price = Cost * MarkUp * Val(tbxQuantity)

End Sub

Thanks in Advance!
 
T

Tim Zych

Out of those options, the 2nd is faster in my simple test. 10,000,000
iterations clocked in approximately .455% faster (1.3174 seconds VS 1.3234
seconds). A few thousand iterations will not be noticeable.
 
R

RyanH

How do you do that time study? I would guess something like this. Tell me
if I am correct or if you have a better way.

Sub Calculate()

starttime = Format(Date, "mm.ssss")

'my code here

endtime = Format(Date, "mm.ssss")

End Sub
 
Joined
Jun 10, 2008
Messages
8
Reaction score
0
Ryan,



Use:

Sub Timerr()
Dim StartTime as Date
StartTime = Timer
<Code here>
Msgbox format(timer-StartTime, "0.00")
End sub


HTH

PeterA
 
Last edited:
D

Dave Peterson

Which one is easier for you to understand?

Which one is easier for you to modify when (not if) you have to?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top