|
-
Nov 29th, 2000, 12:24 PM
#1
Thread Starter
Lively Member
I have a function that I created to handle the >= operations for two different types of numeric values. I am comparing numbers in a Excel worksheet which are actually strings. (does that make sense? Like "2.0" as a string, not a float). So I figured out that when I am passing floats they will always we less than or equal to 1 since the floats in this case are always going to be percentages. The #'s = to 1 or greater I treat as ints and cast them with CInt() and then do >=. This has worked until I got my new set of data which has floats in this form: "4.777777-E2", where this is actually ".04777777". It trys to do a string compare and 4.77777-E2 is greater than any other percentage since in using the string compare it looks at the first digit and compares the first digit of both strings to see which is greater.
Here is the code... If I knew how to cast a string to a float (if it is possible in VB) then this problem would have been solved a while ago.
Maybe some of u know what i can do:
Function greaterThanOrEqual(ByVal Temp1 As String, ByVal temp2 As String) As Boolean
If ((Temp1 <= 1) Or (temp2 <= 1)) Then ' they are floats.. use > compares
If (Temp1 >= temp2) Then
greaterThanOrEqual = True
Else
greaterThanOrEqual = False
End If
Else
If (CInt(Temp1) >= CInt(temp2)) Then
greaterThanOrEqual = True
Else
greaterThanOrEqual = False
End If
End If
Thanx in advance,
cLocKwOrk
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|