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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: VB Percentage

    Answer this question:

    If you had to work out what 5% of 100 was, on paper, how would you do it?

  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
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  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
  •  



Click Here to Expand Forum to Full Width