free counters
Diberdayakan oleh Blogger.

Senin, 08 Oktober 2012

Floor and Ceil in VB6

by Unknown  |  in Visual Basic 6 at  Senin, Oktober 08, 2012

In VB6 there is no built-in for Floor and Ceil function like in C language.
Let me explain for one who don't know what the purpose of Floor and Ceil, Floor is used for getting the lowest Value of number after the number is rounded and Ceil is use for getting the highest value of number after number is rounded.
for example:
  number = 21,45
 Floor(number) = 21
 Ceil(number) = 22

To overcome this, we can make a module for Floor and Ceil.
Here is the code (kudos for Mario Reynoso for the Code):



'>>--------------------------------------------------------------------------------
'Floor and Ceiling function
'Source http://mario-reynoso.blogspot.com/2009/01/ceiling-y-floor-en-vb6.html
'Devuelve el entero más pequeño no menor que X.
'Ejemplo: Ceiling(1.23) = 2, Ceiling(-1.23) = -1
Public Function Ceiling(ByVal x As Double) As Long
Ceiling = -Int(x * (-1))
End Function
'Devuelve el entero más grande no mayor que X.
'Ejemplo: Floor(1.23) = 1, Floor(-1.23) = -2
Public Function Floor(ByVal x As Double) As Long
Floor = (-Int(x) * (-1))
End Function
'
'<<--------------------------------------------------------------------------------


insert the code to the new module and save it.
To use the function, you can call it directly from you form like this:
Floor(variableNameOrControl)
Ceiling(variableNameOrControl)


0 comments:

Silahkan tinggalkan komentar anda: