Now, let's writing the programme coding for the above programme design.
At the end, your programme will look like below listing:Select Case Val(txtSalQty.Text) Case 1 To 2 txtBonus.Text = "2%" Case 3, 4 txtBonus.Text = "3%" Case 5 To 6 txtBonus.Text = "4.5%" Case 7 To 8 txtBonus.Text = "6.5%" Case 9 txtBonus.Text = "10%" Case Else txtBonus.Text = "15%" End Select txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _ Val(Left(txtBonus.Text, Len(txtBonus.Text) _ - 1)) / 100
Let's test your programme to check whether it's correct or not.Private Sub cmdCalBonus_Click() Select Case Val(txtSalQty.Text) Case 1 To 2 txtBonus.Text = "2%" Case 3, 4 txtBonus.Text = "3%" Case 5 To 6 txtBonus.Text = "4.5%" Case 7 To 8 txtBonus.Text = "6.5%" Case 9 txtBonus.Text = "10%" Case Else txtBonus.Text = "15%" End Select txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _ Val(Left(txtBonus.Text, Len(txtBonus.Text) _ - 1)) / 100 End Sub
According to the Bonus Table if Sales Quantity = 5, so the Bonus Percentage should equal to 4.5%. So the Bonus Amount = 5 X 100 X 4.5 / 100. And the result is 22.5. So your program should like below screenshot.
Now I'll explain how the programme works.
txtBonusAmt.Text = Val(txtSalQty.Text) * Val(txtPriceUnit.Text) * _
Val(Left(txtBonus.Text, Len(txtBonus.Text) _
- 1)) / 100
Mybe you think that this is a complex statement. But in fact it's just a simple statement.Val(txtSalQty.Text) convert text "5" into number 5
Val(txtPriceUnit.Text) convert text "100" into number 100
Because txtBonus.Text = "4.5%" (this is a text) so:
Len(txtBonus.Text) will return 4, and Len(txtBonus.Text) - 1 will return 3
Left(txtBonus.Text, Len(txtBonus.Text) - 1) equals to Left("4.5%",4-1) will return "4.5"
Then Val(Left(txtBonus.Text, Len(txtBonus.Text) - 1)) equal to Val("4.5") will return number 4.5
So the above formula will equal to:
txtBonusAmt.Text = Val("5")*Val("100")*Val(Left("4.5%",Len("4.5%")-1))/100
<=> txtBonusAmt.Text = 5 * 100 * 4.5 / 100
<=> txtBonusAmt.Text = 22.5
1 comments:
Designing of form is convinent in saple programs....
cathrin disusa
Cash Online Get Easy cash at your door step
Post a Comment