| | |
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: 289
Reputation:
Solved Threads: 38
1
#2 25 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 25 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 24 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 24 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.
-7
#10 24 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; 24 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 2008 access account advanced application array basic beginner browser button buttons center click code combo cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic excel exists fade filter forms generatetags gridview html images input insert intel internet listview map mobile module monitor msaccess net number objects open panel passingparameters pdf picturebox picturebox2 port position print printing problem regex remove right-to-left save search searchvb.net select serial settings shutdown socket sqldatbase sqlserver survey temperature textbox timer timespan transparency txttoxmlconverter update user usercontol vb vb.net vb.netformclosing()eventpictureboxmessagebox vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode xml year






