| | |
How to add strings that contain amounts
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 32
Reputation:
Solved Threads: 0
vb.net Syntax (Toggle Plain Text)
'Radio Choice Selection Console.WriteLine("Please enter the Radio Choice for your vehicle: ") Console.WriteLine("Enter 1 for AM/FM Radio") Console.WriteLine("Enter 2 for AM/FM/CD/DVD") strRadioChoice = Console.ReadLine() Select Case strRadioChoice Case "1" Console.WriteLine("Price : $100") Case "2" Console.WriteLine("Price : $400") Case Else Console.WriteLine("Invalid selection") End Select SellingPrice = BasePrice + strEngineChoice + strInteriorChoice + strRadioChoice + ShippingCharge + DealerCharge Console.WriteLine("The total selling price for your vehicle is $" + SellingPrice) Console.WriteLine() Console.WriteLine("Press Enter to Exit") Console.ReadLine()
•
•
Join Date: Sep 2009
Posts: 321
Reputation:
Solved Threads: 45
1
#2 Nov 3rd, 2009
You need to be storing these individual values into numeric variables to be calculated at the end.
•
•
•
•
vb.net Syntax (Toggle Plain Text)
'Radio Choice Selection Dim decRadioPrice As Decimal Console.WriteLine("Please enter the Radio Choice for your vehicle: ") Console.WriteLine("Enter 1 for AM/FM Radio") Console.WriteLine("Enter 2 for AM/FM/CD/DVD") strRadioChoice = Console.ReadLine() Select Case strRadioChoice Case "1" Console.WriteLine("Price : $100") decRadioPrice = 100.00 Case "2" Console.WriteLine("Price : $400") decRadioPrice = 400.00 Case Else Console.WriteLine("Invalid selection") End Select 'SellingPrice = BasePrice + strEngineChoice + strInteriorChoice '+ strRadioChoice + ShippingCharge + DealerCharge decTotal = decBasePrice + desEnginePrice + decInterior + decRadio etc Console.WriteLine("The total selling price for your vehicle is $" + FormatCurrencty(decTotal)) Console.WriteLine() Console.WriteLine("Press Enter to Exit") Console.ReadLine()
1
#4 Nov 3rd, 2009
You should use
integer.TryParse() or decimal.TryParse() instead of handling the exception. Throwing exceptions is a very expensive process and if you have exceptions being thrown in calculations (where it can occur over and over in loops) it can bring a system to a halt depending on the amount of data. •
•
Join Date: Oct 2009
Posts: 32
Reputation:
Solved Threads: 0
0
#6 Nov 5th, 2009
•
•
•
•
Or you can use Integer.Parse() (or Double.Parse(), etc) at that line where you add all the numbers. Maybe add some exception around it, too, .Parse() is pretty picky and throws exceptions when it doesn't get what it wants.
mikiurban are you saying to do decTotal = decBasePrice + decEnginePrice + decInterior + decRadio + decShippingCharge + decDealerCharge
Console.WriteLine("The total selling price for your vehicle is $" + Integer.Parse(decTotal))
I tried integer.parse() and parse.() neither worked
•
•
Join Date: Oct 2009
Posts: 32
Reputation:
Solved Threads: 0
0
#7 Nov 5th, 2009
•
•
•
•
You should useinteger.TryParse()ordecimal.TryParse()instead of handling the exception. Throwing exceptions is a very expensive process and if you have exceptions being thrown in calculations (where it can occur over and over in loops) it can bring a system to a halt depending on the amount of data.
-7
#10 Nov 5th, 2009
CInt casts a string to an integer. e.g.
Will add two strings (the data in the textboxes) and store the result in an integer variable called answer.
Look at:
http://www.vbdotnetforums.com/vb-net...pose-cint.html
VB.NET Syntax (Toggle Plain Text)
Dim answer As Integer answer = CInt(TextBox1.Text) + CInt(TextBox2.Text)
Will add two strings (the data in the textboxes) and store the result in an integer variable called answer.
Look at:
http://www.vbdotnetforums.com/vb-net...pose-cint.html
Last edited by jbennet; Nov 5th, 2009 at 6:35 am.
If i am helpful, please give me reputation points.
![]() |
Similar Threads
- Help with sorting strings alphabetically (Java)
- Adding strings to a listbox (C++)
- function to add to strings (C++)
- Convertings strings to numbers (C++)
- C++ CString Class Help! (C++)
- operator overloading (C++)
- Actual Date to Day of the Week Application (Java)
- Need to know the difference (C++)
Other Threads in the VB.NET Forum
- Previous Thread: My VB app looks blocky when I move to a different OS
- Next Thread: Help with class
Views: 456 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2008 2008 access advanced application array basic beginner browser button buttons center checkbox class client code combo convert cuesent data database datagrid datagridview date datetimepicker design designer dissertation dissertations dissertationtopic eclipse excel fade filter forms generatetags html images input intel internet lib listview map mobile monitor net number objects open panel pdf picturebox picturebox2 port position print printing problem read remove richtextbox save searchvb.net select serial settings shutdown socket sorting sqlserver studio survey temperature textbox timer timespan transparency txttoxmlconverter user usercontol validation vb vb.net vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web webbrowser winforms winsock wpf wrapingcode year






