CodeItBetter Programming Another VB Programming Blog

VB 6 equivalent functions to .Net’s Floor & Ceiling functions

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'Math - VB 6 equivalent functions to .Net's Floor & Ceiling functions
Option Explicit
 
Public Function Floor(ByVal dblValue As Double) As Double
    Dim myDec As Long
    myDec = InStr(1, CStr(dblValue), ".", vbTextCompare)
    If myDec > 0 Then
        Floor = CDbl(Left(CStr(dblValue), myDec)) + 1
    Else
        Floor = dblValue
    End If
End Function
'How can I call this function:
'Debug.Print Floor(3.356)
'Will display 4

Public Function Ceiling(ByVal dblValue As Double) As Double
    Dim myDec As Long
    myDec = InStr(1, CStr(dblValue), ".", vbTextCompare)
    If myDec > 0 Then
        Ceiling = CDbl(Left(CStr(dblValue), myDec))
    Else
        Ceiling = dblValue
    End If
End Function
'How can I call this function:
'Debug.Print Ceiling(3.356)
'Will display 3
Filed under: Math Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.