|
-
Nov 13th, 2012, 01:18 PM
#1
Thread Starter
New Member
Rate calculation for project
As a heads up, I am a complete and utter newbie to both visual basic, as well as coding in general. I have no idea which of my questions have glaringly obvious solutions or make me look like an idiot. Please remember that everybody starts from somewhere?
I have recently begun to learn VB, and as part of my college's project we have to build a rate calculator. It has to work like this.
The user enters a number of days, for example, 17. I am to have coded a daily, weekly and fortnightly rate beforehand, and the code should break down the number of days entered (17) into one fortnightly rate, then add on three extra days of the daily rate automatically. The end figure should then be displayed in a read only textbox, letting the user know the end fee charged.
After reading my VB book and skimming the internet, as well as talking to classmates... I honestly have no idea how to do this.
Could someone please give me a template or example of code that would let me do this? I realize this forum is probably not meant for newbies pestering you all for help instead of figuring things out on their own, but I genuinelly have tried and everything in my book just seems like jargon. I can't even tell which chapter I need to read to learn to do this...
I will stop rambling now. Anyway, any help will be appreciated. If not, sorry for bothering you guys.
-
Nov 13th, 2012, 01:27 PM
#2
New Member
Re: Rate calculation for project
The first thing I would do is figure out the math.
-
Nov 13th, 2012, 01:37 PM
#3
Thread Starter
New Member
Re: Rate calculation for project
It's supposed to do the maths itself.
The user has like 10 different choices of items to pick from, each item has a different daily/weekly/fortnightly rate for how long they rent it. They pick the item (rdo1 to choose option 1 I guess) and then they enter in the number of days they want to have the item for. The rates have all been coded in, and it's supposed to just calculate itself, using fortnightly and weekly first if they apply and then adding on the daily to make up for any additional days.
I can't really tell if I am making sense... I am completely self-aware of my own ineptitude here. I just have no idea how to code a system when they can enter in a number of days and then that number goes through a tiered system to calculate a fee. Literally no idea. Which is why I'm asking you guys for help.
Heres an example
Car 1 daily = 10 weekly = 60 fortnightly = 110
If they type in 15 days, I need the code to automatically say it'll cost them 120... somehow? I know it must be possible somehow, since that's what we were assigned
-
Nov 13th, 2012, 01:58 PM
#4
Re: Rate calculation for project
If you create a new project and add a button and textbox (both using the given names of Button1 and TextBox1) the following might give you a place to begin:
vb.net Code:
'Declare a sub to handle all your calculations etc.
Private Sub GetPeriodRate(UserTextBox As TextBox)
Dim daycount As Integer 'Declare a variable to hold the number of days.
'Step 1 - converting the content of the TextBox to a number (number of days) that can
' be used in our calculations. This is usually accomplished by the TryParse method.
If Not Integer.TryParse(UserTextBox.Text, daycount) Then
MessageBox.Show("Invalid data entered in the textbox - expecting an integer number.")
TextBox1.SelectAll() 'Select all text in the textbox and give it focus
TextBox1.Focus()
Exit Sub
End If
'NOTE: You might want to add a check here or modify the one above,
'so the entered number is allways positive.
'Step 2 - using the number of days to calculate the number of fortnights, weeks and days.
Dim fortnights, weeks, days As Integer
fortnights = daycount \ 14 'The \ operator is integer division.
weeks = (daycount Mod 14) \ 7 'Mod is tradition modulo - weeks ofc will allways be 1 or 0.
days = daycount Mod 7
'Used to display the current progress - has no importance for calculations and can be removed.
'The underscore '_' is used to seperate a command-line that spans more than one actual line.
MessageBox.Show(String.Format("{0} days is equivalent to {1} fortnights, {2} weeks and {3} days.", _
daycount, fortnights, weeks, days))
'Step 3 - doing the actual calculations:
Dim total_rate As Decimal
'This will most likely involve multiplying fortnights, weeks and days with the appropriate rates
'and adding the results together to get a total rate. Something like:
' total_rate = fortnight * fortnight_rate + weeks * week_rate + days * day_rate
'This final result should probably then be displayed to the user in a MessageBox, TextBox or similar.
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
GetPeriodRate(TextBox1)
End Sub
It should just be pasted into the Form1 class.
Regards Tom
In truth, a mature man who uses hair-oil, unless medicinally , that man has probably got a quoggy spot in him somewhere. As a general rule, he can't amount to much in his totality. (Melville: Moby Dick)
-
Nov 14th, 2012, 05:37 AM
#5
Thread Starter
New Member
Re: Rate calculation for project
Thank you so much! I was utterly clueless, that looks perfect as a template for what to do!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|