Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I'm creating a library system so far i've come to a step where i need to calculate and late fees occured by members. How can i achieve this.
The fee they pay is based on the number of days late. for e.g no days late = 3
charege should = £2
total fee = £2


Please can someone try to help me achieve this task.

here is my code:
VB
Dim latecharge, total As Decimal
Dim days As Integer

If txtdays.Text < 0 Then
    MsgBox("error !", MsgBoxStyle.Critical)
Else

End If

Select Case days
    Case 1 To 5
        txtlate.Text = 2
    Case 6 To 10
        txtlate.Text = 5
    Case 11 To 15
        txtlate.Text = 7.5
    Case 16 To 20
        txtlate.Text = 10
    Case Is > 20
        MsgBox("Remove member")
End Select

latecharge = days
txtlate.Text = latecharge
but it dont seem to be working can someone kindly point out whats wrong.
Posted
Updated 12-Feb-12 5:32am
v2

1 solution

Basically your code makes no sense...
txtDays is, I presume, a regular TextBox[^] that is probably not validated. But let's assume, for this example, txtDays can only hold numeric values.
If the number of days entered is negative you show a MessageBox[^], may I suggest using the MessageBox.Show Method[^] (.NET) instead of MsgBox[^] (VB).
The next part of your code is a Select Case Statement[^] which checks for the value of the days variable. However, days is never set and thus will always be 0.
So now, let's say days IS set somewhere, you then show the amount of pounds this person has to pay. Well, I would certainly wait with returning my books, because after 20 days I only get a MessageBox and appearently don't have to pay for anything :)
The next part of your code is just the weirdest... You're saying latecharge is equal to days (which still isn't set) and then txtLate.Text is equal to latecharge... You might as well set txtLate.Text to days immediately. However, since you are using this TextBox to show the fee this person has to pay you are overwriting that value... Besides, the user already knows the days because he or she entered this himself! Also, your total variable does nothing and is just sitting there.
Now consider this:
VB
Dim daysLate As Integer
' Check if the entered value is numeric.
If Not Integer.TryParse(txtDays.Text, daysLate) Then
    MessageBox.Show("Please enter a numeric value.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
    If daysLate < 0 Then
        MessageBox.Show("Please enter a value higher than 0.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
    Else
        Select Case days
            Case 1 To 5
                txtLate.Text = "2"
            Case 6 To 10
                txtLate.Text = "5"
            Case 11 To 15
                txtLate.Text = "7.5"
            Case 16 To 20
                txtLate.Text = "10"
            Case Is > 20
                MessageBox.Show("This member has exceeded the maximum number of days late.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Select
    End If
End If
Now this would work, however... If the library is going to use different fees or days you will have to rewrite your software and re-deploy! So I suggest you store the days and fees in a database somewhere and recover them here...
However, since you seem to be quite lost as to what to do and how to do it I suggest you start reading some books first. There is plenty of reference material, both on the internet and in the library you are writing this software for.
By the way, is this homework? If it is I suggest you study a bit harder :)
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 12-Feb-12 14:53pm    
Unlike you, I did not get patience to read this boring and wrong question to the very end, but it looks like I can trust that your approach is quite correct.
Good notes about poor maintenance and the attempt to encourage OP to learn.
My 5.
--SA
Sander Rossel 12-Feb-12 16:43pm    
Thanks for the trust! And the vote! :)
alom_93 12-Feb-12 17:53pm    
Thanks for your help.... i understand what your saying, however i was following a tutorial from a handout somebody gave to me and this is where it lead me. I am now understanding your work and it makes better and more sense to me than what i wrote. Anyway i have a question.. on the form i have another text box called additional cost, the value of additional cost should be added to latecharge to produce a total fee, that is where the total variable was meant to come in. However i am a little confused on how i can make this possible can u help me please? thanks btw its not a homework, its just some excercises im trying out to gain some knowledge
Sander Rossel 12-Feb-12 18:01pm    
How about:
Dim totalFee As Integer = CInt(txtLate.Text) + CInt(txtAdditionCost.Text)
txtTotalFee.Text = totalFee.ToString
Just a thought, not sure what your form and code look like...
Don't forget to accept the answer that helped you, so others will know you've been helped too! :)
alom_93 12-Feb-12 18:19pm    
Will try it tomorrow, if not i will post my code and you can help me correct my mistakes.
Once sorted will accept the soloution.
Many thanks for the help so far, much appreciated!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900