We help IT Professionals succeed at work.

Alternative to Visual Basic Mod

rocky050371
rocky050371 asked
on
491 Views
Last Modified: 2008-03-03
I dont want to use the visual basic mod function, is there a .net alternative?
Comment
Watch Question

Commented:
Mod is an operator.  There is no .NET alternative, as it's a language construct, the same way that the + operator or the = operator are.  In C#, you would use % for the same concept.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
What are you trying to achieve that you need the Mod operator, but don't want to use it?

Bob

Author

Commented:
I can acieve the same with a divide but it would have been simpler
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
So, what's wrong with the Mod operator?

    Dim n As Integer = 5

    If n Mod 2 = 0 Then
    End If

Bob

Author

Commented:
I dont want to include visual basic compatability. My choice, Iwant to tell the user how many sms messages they are sending, so if they type more than 160 then 1 more than 360 2 etc
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
I used the Mod operator without VB6 Compatibility.

Bob

Author

Commented:
I mean without ther namesspace micorosft.visualbasic

Author

Commented:
sorry must have been me

Commented:
You don't need that namespace for the mod operator any more than you need it for +, =, <, > etc.  It's a language feature, not part of that namespace.

Author

Commented:
I had just said that
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
I did that without a reference to Microsoft.VisualBasic.

Bob

Commented:
>I did that without a reference to Microsoft.VisualBasic.

Yep, that's what I meant in http:#a19701100
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
I wasn't quite sure what you meant.

Bob
Ark
CERTIFIED EXPERT

Commented:
   Private Function fMod(ByVal x1 As Integer, ByVal x2 As Integer) As Integer
        fMod = x1 - x2 * (x1 \ x2)
    End Function
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Hmmm, all that work, and nada, niente.  Ah, well, c'est la vie.

Bob

Author

Commented:
I have credited you a fair bit today :-)
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.