Round() in VB5?

I am going back and forth from VB5 and 6.
But my problem is this: How do you use the round funciton in VB5?
as in
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

there isn't a round() function in VB5.
it was added in vb6

you could try this equivalent:

Public Function Round(dbl As Double, dp As INteger) As Double
round = format(dbl, "#." & string(dp, "#")
End Function

(sorry this was written on the fly, forgive any mistakes)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BTW if you add any Global function to a VB project, with the same name as an existing VB function, then VB will use *YOUR* version in deference to the intrinsic function.

So... If you put the above code in a project, it will be used *both* in VB5 and VB6.
jagoodieAuthor Commented:
Wow, that was fast.
Looks good.
Thanks a bunch.
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

no probs.
jagoodieAuthor Commented:
why am i getting a type mis match?
Have you put the final bracket in? (I misesd it out)

The problem was that I had written "#.",which implies a digit otherwise nothing, meaning that - for example

 Round(0,x) = "."

the code was returning a string, whereas the function expected a double. Replacing "#." with "0." corrects the problem. "0" implies a digit otherwise zero.

This is copied directly from VB. It's tested!

Public Function Round(dbl As Double, dp As Integer) As Double
Round = Format(dbl, "0." & String(dp, "#"))
End Function
jagoodieAuthor Commented:
yes, thank you. this works much better.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.