Results 1 to 6 of 6

Thread: mathematical operations on text boxes

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    mathematical operations on text boxes

    Hello
    I have got the following code
    Code:
     CableLos = CableLoss.Text + OTSR_splitterLoss.Text
    i stick the value 3 in cableloss.text
    and 3 in OTSR_splitterloss.text

    and i get the value 33 !!

    can you guys tell me how to do a sum on these two text boxes.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: mathematical operations on text boxes

    One of many ways would be to use the Val statement.
    VB Code:
    1. CableLos = Val(CableLoss.Text) + Val(OTSR_splitterLoss.Text)
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3
    Fanatic Member Psyrus's Avatar
    Join Date
    Jul 2000
    Location
    NJ
    Posts
    602

    Re: mathematical operations on text boxes

    A good thing to remember is that any time that you use math on user input to be sure to convert it to a number. You can use Val() as RobDog suggested or one of the conversion functions.

    CByte() - Byte
    CInt() - Integer
    CLng() - Long
    CDbl() - Double
    CSng() - Single
    CCur() - Currency
    Chris

    VB 6.0 Calendar App Video Gamers Group
    Don't forget to rate people if they helped you.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2005
    Posts
    1,069

    Re: mathematical operations on text boxes

    thanks dudes
    i used the ccur to convert it to currencies

    what would the difference between vall and ccur be?

    does val return fractional numbers?

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: mathematical operations on text boxes

    Quote Originally Posted by Psyrus
    A good thing to remember is that any time that you use math on user input to be sure to convert it to a number. You can use Val() as RobDog suggested or one of the conversion functions.

    CByte() - Byte
    CInt() - Integer
    CLng() - Long
    CDbl() - Double
    CSng() - Single
    CCur() - Currency
    Unless it's a date, then use CDate()
    Tengo mas preguntas que contestas

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: mathematical operations on text boxes

    Quote Originally Posted by vb_student
    does val return fractional numbers?
    Val returns whole numbers. If you did a val on 3.5, it would return 4

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width