What are constrants?
- Can some one explain what constraints are in this application?
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents btnUS As System.Windows.Forms.Button
Friend WithEvents btnGB As System.Windows.Forms.Button
Friend WithEvents lblTax As System.Windows.Forms.Label
Friend WithEvents lblTotal As System.Windows.Forms.Label
Friend WithEvents btnCA As System.Windows.Forms.Button
Friend WithEvents lblTaxLabel As System.Windows.Forms.Label
Friend WithEvents lblTotalLabel As System.Windows.Forms.Label
Friend WithEvents txtDistance As System.Windows.Forms.TextBox
Friend WithEvents lblWeightLabel As System.Windows.Forms.Label
Friend WithEvents txtWeight As System.Windows.Forms.TextBox
Friend WithEvents lblDistanceLabel As System.Windows.Forms.Label
Friend WithEvents lblSubTotal As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.btnUS = New System.Windows.Forms.Button()
Me.btnGB = New System.Windows.Forms.Button()
Me.lblTax = New System.Windows.Forms.Label()
Me.lblTotal = New System.Windows.Forms.Label()
Me.btnCA = New System.Windows.Forms.Button()
Me.lblTaxLabel = New System.Windows.Forms.Label()
Me.lblTotalLabel = New System.Windows.Forms.Label()
Me.lblDistanceLabel = New System.Windows.Forms.Label()
Me.txtDistance = New System.Windows.Forms.TextBox()
Me.lblWeightLabel = New System.Windows.Forms.Label()
Me.txtWeight = New System.Windows.Forms.TextBox()
Me.lblSubTotal = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'btnUS
'
Me.btnUS.Location = New System.Drawing.Point(8, 128)
Me.btnUS.Name = "btnUS"
Me.btnUS.Size = New System.Drawing.Size(80, 23)
Me.btnUS.TabIndex = 3
Me.btnUS.Text = "Calculate US"
'
'btnGB
'
Me.btnGB.Location = New System.Drawing.Point(96, 128)
Me.btnGB.Name = "btnGB"
Me.btnGB.Size = New System.Drawing.Size(80, 23)
Me.btnGB.TabIndex = 4
Me.btnGB.Text = "Calculate GB"
'
'lblTax
'
Me.lblTax.Location = New System.Drawing.Point(200, 16)
Me.lblTax.Name = "lblTax"
Me.lblTax.Size = New System.Drawing.Size(64, 16)
Me.lblTax.TabIndex = 3
Me.lblTax.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'lblTotal
'
Me.lblTotal.Location = New System.Drawing.Point(200, 40)
Me.lblTotal.Name = "lblTotal"
Me.lblTotal.Size = New System.Drawing.Size(64, 16)
Me.lblTotal.TabIndex = 7
Me.lblTotal.TextAlign = System.Drawing.ContentAlignment.MiddleRight
'
'btnCA
'
Me.btnCA.Location = New System.Drawing.Point(184, 128)
Me.btnCA.Name = "btnCA"
Me.btnCA.Size = New System.Drawing.Size(80, 23)
Me.btnCA.TabIndex = 5
Me.btnCA.Text = "Calculate CA"
'
'lblTaxLabel
'
Me.lblTaxLabel.Location = New System.Drawing.Point(144, 16)
Me.lblTaxLabel.Name = "lblTaxLabel"
Me.lblTaxLabel.Size = New System.Drawing.Size(40, 16)
Me.lblTaxLabel.TabIndex = 9
Me.lblTaxLabel.Text = "Tax:"
'
'lblTotalLabel
'
Me.lblTotalLabel.Location = New System.Drawing.Point(144, 40)
Me.lblTotalLabel.Name = "lblTotalLabel"
Me.lblTotalLabel.Size = New System.Drawing.Size(40, 16)
Me.lblTotalLabel.TabIndex = 10
Me.lblTotalLabel.Text = "Total:"
'
'lblDistanceLabel
'
Me.lblDistanceLabel.Location = New System.Drawing.Point(8, 40)
Me.lblDistanceLabel.Name = "lblDistanceLabel"
Me.lblDistanceLabel.Size = New System.Drawing.Size(56, 16)
Me.lblDistanceLabel.TabIndex = 11
Me.lblDistanceLabel.Text = "Distance:"
'
'txtDistance
'
Me.txtDistance.Location = New System.Drawing.Point(72, 40)
Me.txtDistance.Name = "txtDistance"
Me.txtDistance.Size = New System.Drawing.Size(56, 20)
Me.txtDistance.TabIndex = 2
Me.txtDistance.Text = ""
'
'lblWeightLabel
'
Me.lblWeightLabel.Location = New System.Drawing.Point(8, 16)
Me.lblWeightLabel.Name = "lblWeightLabel"
Me.lblWeightLabel.Size = New System.Drawing.Size(48, 16)
Me.lblWeightLabel.TabIndex = 13
Me.lblWeightLabel.Text = "Weight:"
'
'txtWeight
'
Me.txtWeight.Location = New System.Drawing.Point(72, 8)
Me.txtWeight.Name = "txtWeight"
Me.txtWeight.Size = New System.Drawing.Size(56, 20)
Me.txtWeight.TabIndex = 1
Me.txtWeight.Text = ""
'
'lblSubTotal
'
Me.lblSubTotal.Location = New System.Drawing.Point(72, 72)
Me.lblSubTotal.Name = "lblSubTotal"
Me.lblSubTotal.Size = New System.Drawing.Size(48, 23)
Me.lblSubTotal.TabIndex = 14
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(272, 158)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.lblSubTotal, Me.txtWeight, Me.lblWeightLabel, Me.txtDistance, Me.lblDistanceLabel, Me.lblTotalLabel, Me.lblTaxLabel, Me.btnCA, Me.lblTotal, Me.lblTax, Me.btnGB, Me.btnUS})
Me.Name = "Form1"
Me.Text = "Shipping Calculator"
Me.ResumeLayout(False)
End Sub
#End Region
Const US_TAX_AMOUNT As Double = 0.065
Const GB_TAX_AMOUNT As Double = 0.0825
Const CA_TAX_AMOUNT As Double = 0.0775
Const CA_SERVICE_CHARGE As Double = 12.95
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnUS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUS.Click
Dim weight As Double
Dim distance As Double
weight = Double.Parse(txtWeight.Text)
distance = Double.Parse(txtDistance.Text)
Call calculateAmount(weight, distance, US_TAX_AMOUNT)
End Sub
Private Sub btnGB_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGB.Click
Dim weight As Double
Dim distance As Double
weight = Double.Parse(txtWeight.Text)
distance = Double.Parse(txtDistance.Text)
Call calculateAmount(weight, distance, GB_TAX_AMOUNT)
End Sub
Private Sub btnCA_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCA.Click
Dim weight As Double
Dim distance As Double
weight = Double.Parse(txtWeight.Text)
distance = Double.Parse(txtDistance.Text)
Call calculateAmount(weight, distance, CA_TAX_AMOUNT, CA_SERVICE_CHARGE)
End Sub
Sub calculateAmount(ByVal weight As Double, ByVal distance As Double, ByVal taxPercentage As Double, Optional ByVal serviceCharge As Double = 0)
Dim subTotal As Double
Dim tax As Double
Dim total As Double
subTotal = calculateSubTotal(weight, distance)
tax = calculateTax(taxPercentage, subTotal)
total = subTotal + tax + serviceCharge
Call displayResult(subTotal, tax, total)
End Sub
Function calculateSubTotal(ByVal weight As Double, ByVal distance As Double) As Double
Return weight * distance * 0.5
End Function
Function calculateTax(ByVal taxPercentage As Double, ByVal taxAmount As Double) As Double
Return taxPercentage * taxAmount
End Function
Sub displayResult(ByVal subtotal As Double, ByVal tax As Double, ByVal total As Double)
lblSubTotal.Text = Format(subtotal.ToString(), "Currency")
lblTax.Text = Format(tax.ToString(), "Currency")
lblTotal.Text = Format(total.ToString, "Currency")
End Sub
End Class
RobertBodling@yahoo.com
Answers
- Hi Robert. First off, please form your question a little more coherently. I don't even know what you mean by constraints. Provide some background to your question, and if there is a specific question regarding the code you have posted, indicate where in the code that would be. No one here is going to just load in your form without knowing what the question is.
Also, please do not post the entire code of your form. If your quesiton is about the logic of calculations then just post the code blocks relevant to the question.
Last, and just a suggestion, but consider removing your email address because people troll these forums looking for valid email addresses to spam. But really, no one is going to email you regarding this question - all answers will be within the thread itself.
If by some chance you are asking about where the constants are in this code then they are designated by the Const keyword, so these are your constants:
Const US_TAX_AMOUNT As Double = 0.065
Const GB_TAX_AMOUNT As Double = 0.0825
Const CA_TAX_AMOUNT As Double = 0.0775
Const CA_SERVICE_CHARGE As Double = 12.95
Constants are set at compile time and cannot be modified once your app has started. They guarantee that a value will not change.- Marked As Answer byRobert Bodling Sunday, November 01, 2009 1:05 PM
- Glad we can help -- and welcome to this forum! As you can see there are plenty of people willing to jump in and help with a question, so feel free ask more questions when they arise.
Good Luck!- Marked As Answer byRobert Bodling Thursday, November 05, 2009 1:29 AM
- There's not that much more to say about constants - they are defined in the code, cannot be changed at run time and are available to use in code as required.
To see more about constants, look here:
Const
http://msdn.microsoft.com/en-us/library/cyxe49xw(VS.71).aspx
There are also constants predefined for the Visual Basic language. See here:
Constants and Enumerations
http://msdn.microsoft.com/en-us/library/dy7yth1w(VS.71).aspx
The function examples you refer to were coded for that particular application. They are used, for example:
Dim SubT As Double = calculateSubTotal(10, 15)
which will put the result of the calculation (10 * 15 * 0.5) into the variable SubT.
For more about user functions see:
Function
http://msdn.microsoft.com/en-us/library/sect4ck6(VS.71).aspx- Marked As Answer byRobert Bodling Thursday, November 05, 2009 4:12 AM
All Replies
- Hi Robert. First off, please form your question a little more coherently. I don't even know what you mean by constraints. Provide some background to your question, and if there is a specific question regarding the code you have posted, indicate where in the code that would be. No one here is going to just load in your form without knowing what the question is.
Also, please do not post the entire code of your form. If your quesiton is about the logic of calculations then just post the code blocks relevant to the question.
Last, and just a suggestion, but consider removing your email address because people troll these forums looking for valid email addresses to spam. But really, no one is going to email you regarding this question - all answers will be within the thread itself.
If by some chance you are asking about where the constants are in this code then they are designated by the Const keyword, so these are your constants:
Const US_TAX_AMOUNT As Double = 0.065
Const GB_TAX_AMOUNT As Double = 0.0825
Const CA_TAX_AMOUNT As Double = 0.0775
Const CA_SERVICE_CHARGE As Double = 12.95
Constants are set at compile time and cannot be modified once your app has started. They guarantee that a value will not change.- Marked As Answer byRobert Bodling Sunday, November 01, 2009 1:05 PM
- Hmmm. The only technical use of "constraints" I know of in VB.NET has to do with generics. I don't see any use of generics in this code (but I only skimmed it).
Generics would look something like this: List(Of String) or Class Person(Of T as New)
Here is a link about generics and constraints:
http://msdn.microsoft.com/en-us/library/ms379608(VS.80).aspx#vb2005_generics_topic4
I don't see anything like this in your code.
Or did the person requesting this information (an instructor) mean it from more of a design perspective and was really asking for the requirements or limitations?
You may have to ask what was meant by "constraints" in the context of your code.
Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! - In case you did mean Constraints, see this link
http://www.dreamincode.net/forums/showtopic31252.htm
you can also Google VB.NET Constraints and get some more links :) - Robert,
You made a nice puzzle for us in the context from what does he mean.
Constants or Contstraints or maybe even something else
Beside the given replies I know constrains mainly from database developing
In those you can set different kinds of constraints, as those are not fullfiled in your VB application, than you have a hard time to decide what to do.
But I see no database actions in your sample, so there are not that kind of constraints in it.
(It is better not to display your mail addres in a forum, now you be probably a victim of endless spam)
Success
Cor - Thank you Cor Ligthert and Dig-Boy on the advice of removing my email address, I am used to posting in newsgroups and have been getting responses sent to my email address. It has been removed from the tag line. Dig-Boy did an excellent shot at answering my question, I sent the question out late after studying late on this and misspelled it. I am trying to grasp this stuff the best I can and do want to thank those who've already answered my question...
- Glad we can help -- and welcome to this forum! As you can see there are plenty of people willing to jump in and help with a question, so feel free ask more questions when they arise.
Good Luck!- Marked As Answer byRobert Bodling Thursday, November 05, 2009 1:29 AM
- Your response to my inquiry, can you elaborate on your response:
>
If by some chance you are asking about where the constants are in this code then they are designated by the Const keyword, so these are your constants:
Const US_TAX_AMOUNT As Double = 0.065
Const GB_TAX_AMOUNT As Double = 0.0825
Const CA_TAX_AMOUNT As Double = 0.0775
Const CA_SERVICE_CHARGE As Double = 12.95
Constants are set at compile time and cannot be modified once your app has started. They guarantee that a value will not change.
Also, where can I find information on such topics as where do I know how to utilize...
>
Function calculateSubTotal(ByVal weight As Double, ByVal distance As Double) As Double
Return weight * distance * 0.5
End Function
Function calculateTax(ByVal taxPercentage As Double, ByVal taxAmount As Double) As Double
Return taxPercentage * taxAmount
End Function
Thanks for your help so far...
- Edited byRobert Bodling Thursday, November 05, 2009 3:49 AM
- There's not that much more to say about constants - they are defined in the code, cannot be changed at run time and are available to use in code as required.
To see more about constants, look here:
Const
http://msdn.microsoft.com/en-us/library/cyxe49xw(VS.71).aspx
There are also constants predefined for the Visual Basic language. See here:
Constants and Enumerations
http://msdn.microsoft.com/en-us/library/dy7yth1w(VS.71).aspx
The function examples you refer to were coded for that particular application. They are used, for example:
Dim SubT As Double = calculateSubTotal(10, 15)
which will put the result of the calculation (10 * 15 * 0.5) into the variable SubT.
For more about user functions see:
Function
http://msdn.microsoft.com/en-us/library/sect4ck6(VS.71).aspx- Marked As Answer byRobert Bodling Thursday, November 05, 2009 4:12 AM
- Thanks Acamar, that is the information I need... this is how I can learn this stuff...
- One simple question here, is it off topic to inquire issues about hardware issues in this forum? Ie. hard drive problems... window xp driver issues?
Thank you,
Robert Bodling - Both those queries would be off-topic.
You might be best off for those type questions using a newsreader such as Outlook Express and checking out the newsgroups offered by your ISP, or on the msnews.microsoft.com news server.
http://michaelstevenstech.com/outlookexpressnewreader.htm


