|
-
Feb 7th, 2008, 05:34 PM
#1
Thread Starter
Lively Member
Function to reverse integer?
Hi
Is there a function to reverse an integer?
For example ReverseInt(24) would return -24 or ReverseInt(-10) would return 10.
Thanks.
-
Feb 7th, 2008, 05:38 PM
#2
Re: Function to reverse integer?
See if this helps,
Code:
Private Function ReverseInt(Value As Integer) As Integer
If Value < 0 Then
ReverseInt = Abs(Value)
Else
ReverseInt = -Value
End If
End Function
-
Feb 7th, 2008, 05:41 PM
#3
Re: Function to reverse integer?
I've never heard of that as the 'reverse' of a number, the 'negative' is the usual way to describe it.
The way to do it is to simply use a - sign, eg:
Code:
MyVariable = 24 'set initial value
MyVariable = -MyVariable '"reverse" it
edit: hmm.. it seems I was quite slow, but at least I provided a different (and in this case simpler) solution!
-
Feb 7th, 2008, 05:51 PM
#4
Re: Function to reverse integer?
I've always used the ABS() command hehe, so what's it good for then?
-
Feb 7th, 2008, 06:16 PM
#5
Re: Function to reverse integer?
The Abs function returns the absolute (always positive) version of the number, whether it was already positive or not (so -10 and 10 would both give 10).
When/how that would be useful depends on what you are doing.. just like getting the negative of a number (as we did here) is.
-
Feb 7th, 2008, 06:20 PM
#6
Re: Function to reverse integer?
 Originally Posted by si_the_geek
whether it was already positive or not
Oh ya thats right, I need more coffee.
-
Feb 8th, 2008, 01:34 AM
#7
Re: Function to reverse integer?
Si's solution is obviously the best, but this appeals to my warped mind (only applies to whole numbers)
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
|