VB Percentage-VBForums
Results 1 to 6 of 6

Thread: VB Percentage

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2007
    Location
    A Village called Wrenbury, In Cheshireq
    Posts
    22

    VB Percentage

    Right i have no coding at the min, but i was wondering how do you get VB to work out the percentage of a value.

    I have to enter a value (money) into a text box, then i click on a button which takes the value from that text box, add 17.5% and then puts the value back into another text box.

    How would i do this?

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: VB Percentage

    Answer this question:

    If you had to work out what 5% of 100 was, on paper, how would you do it?
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2007
    Location
    A Village called Wrenbury, In Cheshireq
    Posts
    22

    Re: VB Percentage

    so would it be?

    (text box name/17.5) *100 + textbox name

  4. #4
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: VB Percentage

    Bingo.

    However, you can't do math on a string, so you would need to convert the textbox contents to a numeric value. CInt or CLng or Val would do nicely.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  5. #5
    Super Moderator Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    11,925

    Re: VB Percentage

    or try this

    Code:
    Private Sub CommandButton1_Click()
    'Val to convert text to number
    '0.175 because 17.5%
    
    Text1.Text = Val(Text1.Text) + Val(Text1.Text) * 0.175
    'OR
    
    'Comment whichever is applicable
    'format to change it back to currency
    Text1.Text = Format((Val(Text1.Text) + Val(Text1.Text) * 0.175), "£0.00")
    
    End Sub
    The poster formerly known as koolsid
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved

    Microsoft MVP: 2011 - Till Date IMP Links : Acceptable Use Policy, FAQ

    MyGear:
    Sony VGN-FZ27G with a triple boot between (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008) and (Win7+Office 2010+VS2010) || Sony VPCCB-45FN with a Win7+Office 2010+VS2010. VM: (XP+Office 2003+VB6), (VISTA+Office 2007+VS2008), (Win8+Office 2010+VS2012) || Mac Book Pro (10.6.8) with Office 2011

  6. #6
    Lively Member
    Join Date
    Aug 2007
    Posts
    86

    Re: VB Percentage

    or
    Code:
    text2.text = clng(text1.text) * 1.175

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.