Access VBA Code

This Access VBA is using a For Next loop and I understand most of the code but I have some areas that I'm not sure about. Can someone give me some in depth detail on the following code:


sngAmount = sngAmount + (sngAmount * (strRate / 100 / 12))

I understand the above is the formula for calculating the interest earned but I don't quite get dividing by "100" is that to make it currency to allow for two digits after the amount is achieved from the calculation?

I don't understand making the following variables as the data types chosen:

sngAmount
dblYear
strRate
intI being "Dim" As integer

Why not make them all "single" or "double" how is a string even used in a math problem?
CompoundRate.accdb
James CoatsComputer Info. Sys. StudentAsked:
Who is Participating?
 
KimputerCommented:
As a person would type in the percentage field in integers, the formula basically HAS to have the dividing by 100 to get to the real number to be calculated (the dividing by 12 is misleading though, as it's nullified by the * 12 in an earlier statement, and hence the For loop is a moot point too). The two digits was purely chosen for readability. It's a choice on how to display the number, nothing more.
Basically, you're reading too much behind it all.
0
 
Haris DulicCommented:
Hi,

division is done to turn the strRate to percentile and then divide it by 12 to make it monthly interest rate than the result in brackets is added to the sngAmount .

Did not quite understand the issue : Why not make them all "single" or "double" how is a string even used in a math problem? Please clarify?
0
 
IrogSintaCommented:
strRate is the Percentage Rate.  When working with percentages (4.5% for example), you would divide by 100 to give you .045 in your equation.  Not sure why it would be a String data type though.  I would think it would be a Double as well.  Unless they are including the % symbol along with it, but if that was so, then the formula would need to use VAL(strRate) to pull out the numeric portion.

Ron
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
James CoatsComputer Info. Sys. StudentAuthor Commented:
Thank you all very much this made things a lot more clear.
0
 
IrogSintaCommented:
Why not make them all "single" or "double" how is a string even used in a math problem?

This is a valid point.  I too am confused with the choices of Data Types here.  The variable strRate doesn't make sense at all, it should have been either Single or Double.  There also doesn't seem to be any basis on why the coder chose to make some as Single and others as Double.  YEAR should have been an Integer since it is a whole number.  Another option for YEAR would have been Byte since I doubt if you would ever use anything over 255 years in this project.

Ron
0
 
James CoatsComputer Info. Sys. StudentAuthor Commented:
Ron,

Thank you for this comment, sorry that I can not give you some points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.