Can tell me what's wrong with this code? This code doesn't seem to works and it pop up a thing that says INVAILDCASTEXCEPTION WAS UNHANDLED and it highlighted the statement of txtHousingAllowance.Text = txtBasicSalary.Text * 0.2 this. So can tell what the problem with it?
I am really struck with It. U are an expert in vb programming, can u help me to write code for me or u can mofify it if u dun mind..... In the second post i have the pic in but i dun noe how to write the code......
For the housing allowance: 20% of the basic salary
For the travel allowance: 5% of the basic salary
For the family allowance: $500
txtHousingAllowance.Text = txtBasicSalary.Text * 0.2
txtTravelAllowance.Text = txtBasicSalary.Text * 0.05
txtTotalAmount.Text = Val(txtBasicSalary.Text) + Val(txtOverTime.Text) + Val(txtHousingAllowance.Text) + Val(txtTravelAllowance.Text) + Val(txtFamilyAllowance.Text)
Another code is this it also had the same problem.
If txtCPFContribution.Text = 20 Then
txtCPFDeduction.Text = txtBasicSalary.Text * 0.33
ElseIf txtCPFContribution.Text = 18 Then
txtCPFDeduction.Text = txtBasicSalary.Text * 0.27
ElseIf txtCPFContribution.Text = 12.5 Then
txtCPFDeduction.Text = txtBasicSalary.Text * 0.185
ElseIf txtCPFContribution.Text = 7.5 Then
txtCPFDeduction.Text = txtBasicSalary.Text * 0.11
ElseIf txtCPFContribution.Text = 5 Then
txtCPFDeduction.Text = txtBasicSalary.Text * 0.085
End If
txtTotalDeduction.Text = Val(txtCPFDeduction.Text) + Val(txtInsuranceDeduction)
+ Reply to Thread
Results 1 to 4 of 4
-
-
Edit boxes contain TEXT, not numbers...VB tries to help and can sometimes convert one to the other automagically, but don't trust/rely on it (number 12 comes after 9, but the text "12" comes before "9" alphabetically). Always use the VAL function (as you have in some cases) when you need the NUMBER version of a text box value. To put a number back into a text box, I think you need to use the STR() function to convert it to text first
Trevor -
STR() will convert a number to a string but can be a bit crude and occasionally you get silly numbers like 2.999999999999999999999 instead of 3 dur to rounding errors.
Format() does the same except (as the name suggests) you can specify what the number will look like as a string. It's especially useful for decimals, insertion of thousand separators and dates
The format is quite simple Format(Target, "###") will ogive you a 3 digit string of number target Format(Target, "###.#") will force 1 (and only 1) decimal place with correct rounding so 1.66 becomes 1.7 etc.
Have a look here http://www.apostate.com/vb-format-syntax for more
Also (as an aside) have you validated the user input (ISNUMERIC is useful) to ensure a number is entered. str("f") is 0 which is not always what you want
Similar Threads
-
sony DAV-HDX589W multi code zone code
By sam1821 in forum DVD & Blu-ray PlayersReplies: 4Last Post: 7th May 2010, 15:37 -
testing thecoalman's suggestion of [code=php] test [/code] ... FAILED!
By vhelp in forum TestReplies: 1Last Post: 10th Jun 2009, 01:15 -
Need code for pioneeer bdp lx70 code for multi region ...
By SHERWOODSelectrical in forum DVD & Blu-ray PlayersReplies: 2Last Post: 21st Nov 2008, 12:42 -
PHP code used to generate code for Avysinth join mov and avi files
By lindylex in forum User guidesReplies: 0Last Post: 19th Sep 2008, 03:37 -
HTML code suitable for different sized Monitors; also code to embed
By wiseant in forum Off topicReplies: 3Last Post: 8th May 2008, 18:14