| | |
Need help with calculation
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
I'm trying to learn asp.net in vb.net. I have a form to order hats online because I'm learning only one hat at a time may be ordered. I have two listboxes one displays the size and the other the color, I have a checkbox which if checked adds a logo, a button which the user clicks to submit an order, and a label which confirms the order By displaying the message " The cost of your hat is (the total). Here is the rate scale:
White Blue White & Blue
Small $5.99 $6.99 $7.99
Medium $6.99 $7.99 $8.99
Large $7.99 $8.99 $9.99
Hats with a logo cost 3.00 regarless of size or color.
If someone could point me in the right direction I put this in the VB.net forum because (if I understand correctly) this calculation can be done vb.net, even though it's a web form. I'm not to good at expressing calculations. So this may take more than one post.
Thanks
Augie0216
"Help you give now may be help you get in the future"
White Blue White & Blue
Small $5.99 $6.99 $7.99
Medium $6.99 $7.99 $8.99
Large $7.99 $8.99 $9.99
Hats with a logo cost 3.00 regarless of size or color.
If someone could point me in the right direction I put this in the VB.net forum because (if I understand correctly) this calculation can be done vb.net, even though it's a web form. I'm not to good at expressing calculations. So this may take more than one post.
Thanks
Augie0216
"Help you give now may be help you get in the future"
Well you could do this many ways, but since you have not indicated that you are using a Database to store you information lets assume you don't and use an array.
You could use several one-dimensional arrays or one multidimensional array. Store the information, then based on the choise by the user it grabs that value from the array(s) and uses it in calculation.
Example: (pseudo-code)
....
Dim arSMALLCosts(3) as Float
Dim arMEDCosts(3) as Float
Dim arLARGECosts(3) as Float
Dim Cost as Float
Dim LogoFee as Float
Dim qty as Integer
Dim Total as Float
.... ' Fill your arrays with costs
....
' Use some sort of logic to determine if small, medium or large is selected
Dim nValue as Integer
nValue = ' Color of the size selected
....
Cost = arSMALLCosts(nValue) ' Assuming Size selected was small
if chkLogo = True Then
LogoFee = 3.00
else
LogoFee = 0
end if
Total = qty * Cost
lblTotal.Text = Total
...
Hope this helps

You could use several one-dimensional arrays or one multidimensional array. Store the information, then based on the choise by the user it grabs that value from the array(s) and uses it in calculation.
Example: (pseudo-code)
....
Dim arSMALLCosts(3) as Float
Dim arMEDCosts(3) as Float
Dim arLARGECosts(3) as Float
Dim Cost as Float
Dim LogoFee as Float
Dim qty as Integer
Dim Total as Float
.... ' Fill your arrays with costs
....
' Use some sort of logic to determine if small, medium or large is selected
Dim nValue as Integer
nValue = ' Color of the size selected
....
Cost = arSMALLCosts(nValue) ' Assuming Size selected was small
if chkLogo = True Then
LogoFee = 3.00
else
LogoFee = 0
end if
Total = qty * Cost
lblTotal.Text = Total
...
Hope this helps

•
•
•
•
Originally Posted by augie0216
I'm trying to learn asp.net in vb.net. I have a form to order hats online because I'm learning only one hat at a time may be ordered. I have two listboxes one displays the size and the other the color, I have a checkbox which if checked adds a logo, a button which the user clicks to submit an order, and a label which confirms the order By displaying the message " The cost of your hat is (the total). Here is the rate scale:
White Blue White & Blue
Small $5.99 $6.99 $7.99
Medium $6.99 $7.99 $8.99
Large $7.99 $8.99 $9.99
Hats with a logo cost 3.00 regarless of size or color.
If someone could point me in the right direction I put this in the VB.net forum because (if I understand correctly) this calculation can be done vb.net, even though it's a web form. I'm not to good at expressing calculations. So this may take more than one post.
Thanks
Augie0216
"Help you give now may be help you get in the future"
•
•
Join Date: May 2005
Posts: 55
Reputation:
Solved Threads: 1
Suppose the size listbox has Small, Medium, and Large
Suppose the color listbox has White, Blue, White & Blue
Then write:
dim total as Double
//check if its small and white
If lstBoxSize.SelectedIndex = 0 And lstBoxColor.SelectedIndex = 0 then
total = total + 5.99
End if
//check if its small and blue
If lstBoxSize.SelectedIndex = 0 And lstBoxColor.SelectedIndex = 1 then
total = total + 6.99
End if
//check if its small and white&blue
If lstBoxSize.SelectedIndex = 0 And lstBoxColor.SelectedIndex = 2 then
total = total + 7.99
End if
//check if its medium and white
If lstBoxSize.SelectedIndex = 1 And lstBoxColor.SelectedIndex = 0 then
total = total + 6.99
End if
//and so on...
//check if logo is selected and set total to 3 if it is selected
For more programming help, visit www.NeedProgrammingHelp.com or email me at NeedProgrammingHelp@hotmail.com
Alex.
Suppose the color listbox has White, Blue, White & Blue
Then write:
dim total as Double
//check if its small and white
If lstBoxSize.SelectedIndex = 0 And lstBoxColor.SelectedIndex = 0 then
total = total + 5.99
End if
//check if its small and blue
If lstBoxSize.SelectedIndex = 0 And lstBoxColor.SelectedIndex = 1 then
total = total + 6.99
End if
//check if its small and white&blue
If lstBoxSize.SelectedIndex = 0 And lstBoxColor.SelectedIndex = 2 then
total = total + 7.99
End if
//check if its medium and white
If lstBoxSize.SelectedIndex = 1 And lstBoxColor.SelectedIndex = 0 then
total = total + 6.99
End if
//and so on...
//check if logo is selected and set total to 3 if it is selected
For more programming help, visit www.NeedProgrammingHelp.com or email me at NeedProgrammingHelp@hotmail.com
Alex.
![]() |
Similar Threads
- Help with calculation (VB.NET)
- 2d address calculation (C++)
- leap year calculation (ASP)
- Auto Calculation (Visual Basic 4 / 5 / 6)
- Help with Calculation (C++)
- Mortgage Calculation (Java)
Other Threads in the VB.NET Forum
- Previous Thread: pass OleDbDataReader to table
- Next Thread: connecting to access via vb.net-HELP!!!
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array basic beginner bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel fade file-dialog filter forms ftp generatetags google hardcopy html images input insert intel internet mobile monitor net networking objects open output panel passingparameters pdf picturebox picturebox1 port position print printing problem project save searchbox searchvb.net select serial settings shutdown soap sqlserver survey table tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year





