I am working on a program that consists of three event procedures (in other words, three different task buttons: “Select Media and Estimated Fund,” “Add Agencies,” and “Generate
Your inputboxes are incorrect, if an invalid value is entered consistently the routine will drop through to the next lines of code!
They should appear as below.
Do
inputtedData = InputBox("Please Enter a balance for SAVINGS account between $500.00 and $3000.00", "Initial Savings Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceSavings = CType(inputtedData, Single)
If initialBalanceSavings > 3000 Or initialBalanceSavings < 500 Then MsgBox("Please enter a balance for SAVINGS account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceSavings >= 500 And initialBalanceSavings <= 3000
Do
inputtedData = InputBox("Please Enter a balance for CORPORATE account between $500.00 and $3000.00", "Initial Corporate Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceCorporate = CType(inputtedData, Single)
If initialBalanceCorporate > 3000 Or initialBalanceCorporate < 500 Then MsgBox("Please enter a balance for CORPORATE account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceCorporate >= 500 And initialBalanceCorporate <= 3000
Finally all the code is DEFINATELY NOT in the "btnMediaEstimatedFund" Procedure, as there is no calculation for the total values, neither is any consideration given to the fact that the calculation is for FUTURE years. in fact the KEY CALCULATION portions are missing!
What I mean is if you wish to generate a calculated figure for the year 2016, and now is 2013, then where is your accounting for the interest at 7% and 5%? I cannot see anywhere where it actually get calculated.
the subroutine which you "Dont know" how to create is no different from the subroutines you have created for your button/textbox/listbox events!
You pass parameters in and it does the calculation and if it is a SUB thats the end of it! and if it is a function then it returns a value or an object.
To create a Sub routine you give it a name an a list of parameters, if neccessary, you may have subroutines and functions without parameters but a function must ALWAYS return a value/object.
Sub ThisIsMySubroutine(MyParam1 as string, My Param2 as Object)
' code here
End Sub
Function ThisIsMyFunction(MyParam1 as string, My Param2 as Object) As Boolean
' code here
End Function
I'm sure you know already that the parameter and return data types can be any acceptable or recognized data types.
With regards to your last comment (beginning with.. Also, I am having one small..) If you swap the code and put your ORIGINAL code back, you will STILL have that same issue!
Okay, so one last more code sample and pointer.
So to stop your program (10% yours 90% mine hahaha) from asking for the input you can enclose it in an if statement...
If checkBoxSavings.Checked Then
Do
inputtedData = InputBox("Please Enter a balance for SAVINGS account between $500.00 and $3000.00", "Initial Savings Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceSavings = CType(inputtedData, Single)
If initialBalanceSavings > 3000 Or initialBalanceSavings < 500 Then MsgBox("Please enter a balance for SAVINGS account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceSavings >= 500 And initialBalanceSavings <= 3000
End If
If checkBoxCorporate.Checked Then
Do
inputtedData = InputBox("Please Enter a balance for CORPORATE account between $500.00 and $3000.00", "Initial Corporate Balance", "0.00")
If inputtedData = "" Then
MsgBox("User chose to Cancel calculation!")
Exit Sub
Else
initialBalanceCorporate = CType(inputtedData, Single)
If initialBalanceCorporate > 3000 Or initialBalanceCorporate < 500 Then MsgBox("Please enter a balance for CORPORATE account equal to or above $500.00 and no more than $3000.00", MsgBoxStyle.Critical, "Error")
End If
Loop Until initialBalanceCorporate >= 500 And initialBalanceCorporate <= 3000
End If
And for the interest here is a link for you, http://math.about.com/od/businessmath/ss/Interest.htm
Its an EXCEPTIONALLY good explanation because it shows the interest over more than 1 year, which is what this part of your question is asking...
Please be aware of the current year, 2013. Now, the report is prepared in year 2013, but the balance should be calculated for your selected year (e.g., 2015, 2016, 2017). Think about the topic of repetition to determine the ending balance during your selected year