|
-
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
-
Nov 29th, 2000, 12:32 PM
#2
Junior Member
Could you use?
If (CDbl(Temp1) >= CDbl(left(temp2, len(temp2)-3)) Then
greaterThanOrEqual = True
Else
greaterThanOrEqual = False
End If
in place of the
If (Temp1 >= temp2) Then
greaterThanOrEqual = True
Else
greaterThanOrEqual = False
End If
This should convert the string to a double then compare them
[Edited by jm3ksc on 11-29-2000 at 12:35 PM]
-
Nov 29th, 2000, 12:37 PM
#3
Thread Starter
Lively Member
NM... i figured it out. =P
Ok I guess u can cast everything to a double and and just do a normal >= compare. Pretty simple.
-cLocKwOrk
-
Nov 29th, 2000, 12:38 PM
#4
Thread Starter
Lively Member
Thanks for the help jm3ksc. Funny. I figured it out just as u posted it. =)
-
Nov 29th, 2000, 12:51 PM
#5
Junior Member
No Problem
I know what a pain it can be sometime, was hoping I could finally help someone, since all I ever do is just come here for help...
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
|