473,321 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Can anyone help me with this code?

I am making a retail price calculator for a school project. We are to write an application that accepts the wholesale cost and its markup percentage. We have to verify the values entered for IsValidCost are between 0 & 5000 and for IsValidMarkup are between 5 and 800. I have pasted the code I have so far, but every time I try to run it, I get the message "Please enter a price between $1.00 and $1000000."
Any help will be greatly apprecitated!

April

'Project 1 Ch6
'April McKenna
'November 17, 2008
'Challenge to create a calculator that will let a user enter the wholesale price
' and the markup percentage to get the retail price.

'Retail Price = Wholesale * (1+ Markup / 100)

Public Class Form1
' Validates wholesale cost, markup cost and calculates retail price
Private Sub btnGetRetail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGetRetail.Click
Dim dPrice As Decimal
Dim dMarkup As Decimal
Dim dRetailPrice As Decimal

If IsValid(dPrice) Then
Call CalculateRetail(dPrice, dMarkup, dRetailPrice)
Call DisplayRetail(dRetailPrice)
End If
End Sub
Private Function IsValid(ByRef dPrice As Decimal, _
ByRef dMarkup) As Boolean
Return IsValidCost(dPrice) AndAlso _
IsValidMarkup(dMarkup)

End Function
Private Function IsValidCost(ByRef dPrice As Decimal) As Boolean
'Validates that the price entered are numeric and not negitive

Const c_dPriceLow As Decimal = 1
Const c_dPriceHigh As Decimal = 5000
Dim sMessage As String = String.Format( _
"Please enter price between {0:c} and {1:c}", _
c_dPriceLow, c_dPriceHigh)
Try
dPrice = Convert.ToDecimal(txtPrice.Text)
' Price validation
If dPrice >= c_dPriceLow And dPrice <= c_dPriceHigh Then
Return True
Else
MessageBox.Show(sMessage)
txtPrice.Focus()
txtPrice.SelectAll()
Return False
End If

Catch ex As FormatException
MessageBox.Show(sMessage)
txtPrice.Focus()
txtPrice.SelectAll()
Return False
End Try

End Function
Private Function IsValidMarkup(ByRef dMarkup As Decimal) As Boolean
'Validates that the markup entered is between 5 and 800

Const c_dMarkupLow As Decimal = 1
Const c_dMarkupHigh As Decimal = 5000
Dim sMessage As String = String.Format( _
"Please enter a mark up between {0:c} and {1:c}", _
c_dMarkupLow, c_dMarkupHigh)

Try
dMarkup = Convert.ToDecimal(txtPrice.Text)
' Price validation
If dMarkup >= c_dMarkupLow And dMarkup <= c_dMarkupHigh Then
Return True
Else
MessageBox.Show(sMessage)
txtPrice.Focus()
txtPrice.SelectAll()
Return False
End If

Catch ex As FormatException
MessageBox.Show(sMessage)
txtMarkUp.Focus()
txtMarkUp.SelectAll()
Return False
End Try

End Function
Private Sub CalculateRetail(ByVal dPrice As Decimal, _
ByRef dMarkup As Decimal, _
ByRef dRetailPrice As Decimal)

' Calculate payment amount
dRetailPrice = dPrice * (1 + dMarkup / 100)

End Sub
Private Sub DisplayRetail(ByVal dRetailPrice As Decimal)

' Display discount, tax, payment

txtRetailPrice.Text = dRetailPrice.ToString("c")

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'End the application by closing the form
Me.Close()
End Sub
End Class
Nov 21 '08 #1
1 1124
tlhintoq
3,525 Expert 2GB
@aprillynn82
First: placing code tags around your code makes it much more easy to read as code, as you can see above.

Second: The Posting Guidelines are pretty clear about help when it comes to school work. It's pretty frowned upon for the folks here to help with school work, because in the long run helping someone to slide by when they need more attention from the instructor really isn't helping them.

But a couple tips that don't actually solve it for you...
1) In your catch statement I might recommend you display the exception message instead of your custom 'sMessage'.
2) Breakpoints. Use breakpoints and walk through the code line by line, double checking the values of your variables.
3) Never trust your assumptions. You are assuming that your message is the fault of the values, but since the same message appears in the event of an exception, you really don't know.
Nov 23 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Greg Steele | last post by:
Does anyone have a copy or know where I can get an installation executable for chiliReports 2.0 from chili! soft? The company I'm working for bought a copy several years ago, then moved their...
13
by: C++fan | last post by:
The following code is for list operation. But I can not understand. Could anyone explain the code for me? /* * List definitions. */ #define LIST_HEAD(name, type) struct name { type...
1
by: Mike | last post by:
I got the code below from an earlier post but I can't get it to work (I get an error on the "for (i=0; i<a.length; i++)" line) Anyone have code that works for cookies with keys? > Anyone...
6
by: Danny Lesandrini | last post by:
I'm using an Access database to drive a web site and the colors of various table backgrounds are stored in Access. I want users of the Access database to be able to select colors for the site, but...
13
by: penguin732901 | last post by:
Checking back for discussions, there was a lot of talk about 2000 being slower than 97, but not so much lately. What is the latest opinion? Anyone care to set up a poll for how many NG members...
4
by: Hai Nguyen | last post by:
I'm learning C sharp and do not like vb much. I'm creatiing a wepage using panel to test myself. I tried to use these code below, which is written in VB, and to transform them to c sharp but I got...
2
by: Kevin Walzer | last post by:
Does anyone use the Tkdnd module that comes with Tkinter to allow drag-and-drop of Tkinter widgets in your application? (Not the binary extension that hooks into Xdnd and OLE-dnd on Windows.) I've...
6
by: placid | last post by:
Hi all, I'm looking for anyone who is working on a project at the moment that needs help (volunteer). The last project i worked on personally was screen-scraping MySpace profiles (read more at...
169
by: JohnQ | last post by:
(The "C++ Grammer" thread in comp.lang.c++.moderated prompted this post). It would be more than a little bit nice if C++ was much "cleaner" (less complex) so that it wasn't a major world wide...
1
Eclipse
by: Eclipse | last post by:
G'day all Can anyone explain the difference in the results to me as I don't understand why specifying the directory name in two different ways could give a different answer. In CODE 1 below i...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.