Program runs without errors, unfortunately it will not calculate the days overdue. Any Suggestions? I have attached the code as a pdf, i have also done this as an IF, THEN, ELSE statement with the exact same results, but it will not let me upload it. Help!

Private Sub calculateFees (ByVal intDays As Integer, ByRef decTotalDue As Decimal)
            If intDays <= 3 Then
            decTotalDue = dec Fee
            Else
            If intDays > 3 Then
            decTotalDue = CDec((intDays - 3) * 1.5 + decFee)
            End If

If you right-click the file and "Send To" => "Compressed (Zipped) Folder", you can attach it.

Have you checked the value of "intDays" after you call "getDaysOut(intDays)"?

You have the following:
Private Sub getDaysOut(intDays As Integer)

it should be:
Private Sub getDaysOut(ByRef intDays As Integer)

If you don't include "ByRef", the default is to pass the parameter "ByVal".

An alternative is:

    Private Function getDaysOut() As Integer
        Dim intDays As Integer = 0

        Console.Write("How many days did the customer have the DVD? ")

        If Int32.TryParse(Console.ReadLine(), intDays) Then
            getDaysOut = intDays
        Else
            getDaysOut = 0
        End If

    End Function

Usage:

Dim intDays As Integer = 0
intDays = getDaysOut()

        ...

Resource:
How to: Force an Argument to Be Passed by Value (Visual Basic)

...When you pass a variable by reference, you must use the ByRef keyword to specify this mechanism.

The default in Visual Basic is to pass arguments by value...

Edited 2 Years Ago by cgeier

You might try rewriting it as a function without the global as in

Private Function calculateFees (ByVal intDays As Integer, ByVal decFee As Decimal) As Decimal

    If intDays <= 3 Then
        return decFee
    Else
        return CDec((intDays - 3) * 1.5 + decFee)
    End If

End Function

I'm assuming decFee is defined as Decimal. In the calling code you would do

fee = calculateFees(numdays, decfee)

Edited 2 Years Ago by Reverend Jim

Interesting. Your OP was about calculating late fees yet you post an unrelated project to calculate the average of midterm and final exams. As for "using modules, not functions", that statement does not apply because you can use functions in modules.

Sorry I did post the wrong one, I believe this assignment has turned my brain into mush! I agree with the statement about modules/functions Reverend Jim, however I have to abide by the instructors wishes...

I have attached the correct file. Thanks

Small correction then. Add a ByRef to

Private Sub getDaysOut(ByRef intDays As Integer)

so that the entered value of intDays is returned to the calling code. I have to say, though, that by insisting you use a Sub rather than a Function, your instructor is teaching you bad habits.

Edited 2 Years Ago by Reverend Jim

I think that you don't understand the difference between sub, function, module, and class.

Here's a basic description:

A "Function" is basically a "Sub" that returns a value.

Functions and Subs (as well as other things) are contained within Classes and/or Modules.

Reverend Jim, you ROCK! Thank you so much, I really appreciate your help and advice! BTW my instructor doesn't "teach" anything, it's an online class and the book written specifically for the course at the college, is Extremely Vague! When I ask for clarification, he tells me to read the book! Thanks again!

P.S. I have attached the corrected program for future reference

This question has already been answered. Start a new discussion instead.