locked
VB.NET not letting me use Fix conversion function RRS feed

  • Question

  • I am working on a Windows Store app, and I need to get the Integer portion of a value at many places in my code (not an unusual thing to need), and I do not want rounding, which means CInt will not satisfy my needs. The Fix function in the Microsoft.VisualBasic namespace looks like it does exactly what I want, but it gives me the following error:

    'Fix' is not declared. It may be inaccessible due to its protection level.

    But in the documentation that I have found online at:

    http://msdn.microsoft.com/en-us/library/1ee1y7xa(v=vs.95).aspx

    it looks like all I should need is the Microsoft.VisualBasic namespace and assembly (both of which I have). Why won't it let me use the Fix method? Has it been removed for Windows Store app projects? Has it been replaced by some other function? What should I be using? Thanks.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Thursday, November 21, 2013 4:18 AM

Answers

  • The page you link to is for Silverlight. The Fix method is not available for Windows Store apps.

    Methods available for Windows Store apps will say so in the Version Information section. See .NET for Windows Store apps for more information on using .Net in a Windows Store app.

    --Rob

    Thursday, November 21, 2013 6:34 AM
    Moderator

All replies

  • The page you link to is for Silverlight. The Fix method is not available for Windows Store apps.

    Methods available for Windows Store apps will say so in the Version Information section. See .NET for Windows Store apps for more information on using .Net in a Windows Store app.

    --Rob

    Thursday, November 21, 2013 6:34 AM
    Moderator
  • Have a look at the Math.Floor and Math.Ceiling functions. The Floor function should do what you want for positive numbers and Ceiling function for negative numbers. I would suggest writing a function that wraps these two so you can call it generically and let your utility function handle the logic of which library function to use.

    Good luck!


    • Edited by HomeGrownCoder Thursday, November 21, 2013 6:00 PM Added hyperlinks
    Thursday, November 21, 2013 7:44 AM
  • I'm actually going to use the Math.Truncate method, but I will still probably write a utility function just so my code is shorter (I would have been using Fix in a lot of places, so a 3-character "Fix" function is a lot shorter than a 13-character "Math.Truncate" function). I actually knew about all the Math methods I could use, I just wanted something shorter to make my code easier to use, and was wondering why I couldn't use a method that I thought was built-in. But I guess this explains why I can't use it, so I guess I'll need to use Plan B (a utility function). I sometimes why so many previously available methods & functions get removed, the apps get compiled, so wouldn't they be the same to the runtime in the end anyway?

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Thursday, November 21, 2013 4:07 PM