| | |
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: 283
Reputation:
Solved Threads: 36
1
#2 20 Days Ago
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 20 Days Ago
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 19 Days Ago
•
•
•
•
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 19 Days Ago
•
•
•
•
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.
-2
#10 19 Days Ago
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; 19 Days Ago 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 |
.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 ms net networking objects open output panel passingparameters pdf picturebox picturebox1 port position printing problem project save searchbox searchvb.net select serial settings shutdown soap sqlserver survey tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet view visual visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year






