View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
RyanH RyanH is offline
external usenet poster
 
Posts: 586
Default Which is more efficient?

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
--
Cheers,
Ryan


"smartin" wrote:

RyanH wrote:
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!


Just a SWAG...

You're not typing Quantity in the latter example, so there may be some
cost in allocating a variant there. But in 10-100 iterations I can't
imagine there is a significant difference between the two versions.

If you're curious, why not set up an experiment with timing variables?
It could be fun. You might need to expand the number of iterations a few
powers of ten to get meaningful results though.

For added interest, try figuring out the runtime differences declaring
Qty as Integer and Long. You might be surprised.