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
Thread: what wrong with this code?
Thread
-
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
-
PHP code used to generate code for Avysinth join mov and avi files
By lindylex in forum User guidesReplies: 0Last Post: 19th Sep 2008, 04:37 -
VHS captured wrong w/letter box, lost tape, need to remove letterbox code(s
By gentamicinman in forum Newbie / General discussionsReplies: 4Last Post: 3rd Dec 2006, 20:23 -
Region Free code for Samsung DVD-R130 (australian code)
By nicksanders in forum DVD & Blu-ray RecordersReplies: 0Last Post: 1st Aug 2006, 00:26 -
Time Code Wrong - Why
By BazookaJoe in forum Software PlayingReplies: 3Last Post: 11th Jul 2006, 13:00 -
New Toshiba drive indicates wrong region code!
By Darryl99 in forum DVD & Blu-ray WritersReplies: 0Last Post: 18th Mar 2004, 19:19
Statistics
Newest guides
Latest tool updates
New media comments



Quote