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
num=round(1.235,2)
num=1.24
LVL 2
jagoodieAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
nutwissConnect With a Mentor Commented:
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)
0
 
nutwissCommented:
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.
0
 
jagoodieAuthor Commented:
Wow, that was fast.
Looks good.
Thanks a bunch.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
nutwissCommented:
no probs.
0
 
jagoodieAuthor Commented:
why am i getting a type mis match?
0
 
nutwissCommented:
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
0
 
jagoodieAuthor Commented:
yes, thank you. this works much better.
0
All Courses

From novice to tech pro — start learning today.