| | |
How to add strings that contain amounts
Please support our VB.NET advertiser: Intel Parallel Studio Home
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: 320
Reputation:
Solved Threads: 44
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
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net 30minutes 2005 2008 access account application arithmetic array arrays basic binary bing button buttons c# center check checkbox code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dropdownlist excel file-dialog folder ftp generatetags google gridview hardcopy image images inline insert intel internet listview mobile monitor ms net networking output passingparameters peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save searchbox searchvb.net select serial server soap sorting table tcp text textbox timer toolbox trim update updown user vb vb.net vb.netcode vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf






