-
Apr 10th, 2008, 08:57 AM
#1
Thread Starter
Junior Member
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?
-
Apr 10th, 2008, 09:05 AM
#2
Re: VB Percentage
Answer this question:
If you had to work out what 5% of 100 was, on paper, how would you do it?
-
Apr 10th, 2008, 09:12 AM
#3
Thread Starter
Junior Member
Re: VB Percentage
so would it be?
(text box name/17.5) *100 + textbox name
-
Apr 10th, 2008, 09:13 AM
#4
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.
-
Apr 10th, 2008, 09:14 AM
#5
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
-
Apr 10th, 2008, 09:17 AM
#6
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|