problem with calling procedure from Module

Sangpo

Registered User.
Local time
Tomorrow, 05:14
Joined
Jul 7, 2012
Messages
35
Hi all

Yesterday one Sir had expaline me when to use and atvantage of module. Since then Im working hard to learn Module piece by piece. So I have written following code in the module for calculating the increase of salary (percentage wise base on current salary) and simuentaly to calculate total salary after increament. I need the result to be display in the form. bound.
Code written in module :
Public Function calculate(basic As Double, percent As Integer)
Dim totalAllowance As Double
Dim payAfterAllowance As Double
totalAllowance = (basic * percent / 100)
totalAllowance = (totalAllowance + basic)
End Function

Name given to each text boxes are:
For basic salary . text box name=textbasic
Textbox name inputing percentage=textallowancepercent
Texbox name for displaying allwoance amount= Texttotalallowance Texbox name for dispalyingTotal salary after allwoance= textpayafterallowance


Private Sub cmdcalculate_Click()
Texttotalallowance = calculate(textbasic) & (textallowancepercent)
textpayafterallowance = calculate(textbasic) & (textallowancepercent)
End Sub

When I click button (namecmdcalculate) it is not working. I get augumnet is not optional.
I request you all to throw light on this. whic i would appreciate la.

with regards.
Mr. sangpo
 
A function is designed to return a value, so you have to assign a value to the function. Consider...
Code:
Public Function calculate(basic As Double, percent As Integer)
  calculate = (basic * percent / 100) + basic
End Function
This function has one line, and the calculation is assigned to the name of the function.

Also, the parameters when you call a function are separated by commas. Consider...
Code:
Private Sub cmdcalculate_Click()
  Texttotalallowance = calculate(textbasic, textallowancepercent)
  textpayafterallowance = calculate(textbasic, textallowancepercent)
[COLOR="Green"]  'but those two calculations are the same, you see that?[/COLOR]
End Sub
Hope this helps,
Mark
 
Dear Sir,
I have corrected my original code above with following code you have suggested:
It solved about 95 % of my problems ie it calculates total amount of salary after adding allowance.. But it is not displaying or showing total amount of allowance in the desinated textbox named Texttotalallowance. When i change the code "calculate = (basic * percent / 100) + basic" to "calculate = (basic * percent / 100)" then it is showing total allownace but not total salary. I have tried to solve this but couldn't at all. So please i request for your further support.
***************************
Public Function calculate(basic As Double, percent As Integer)
calculate = (basic * percent / 100) + basic
End Function
*******************************************************
Private Sub cmdcalculate_Click()
Texttotalallowance = calculate(textbasic, textallowancepercent)
textpayafterallowance = calculate(textbasic, textallowancepercent)
'but those two calculations are the same, you see that?
End Sub
 
Dear Mark,

Please treat my second request as cancelled. because with the idea and suggestion that you have provided helped me to solve now.
i have written seperate function or code for that.
thank you once more.
Sangpo
 
Good for you for solving the problem Mr. Sangpo, and thank you for posting back with your success!
Mark
 

Users who are viewing this thread

Back
Top Bottom