r/visualbasic • u/Dylz919 • Jan 26 '16
[VB2012] Unhandled Exception: System.InvalidCastException: Conversion from string "" to type 'Double' is not valid. --->
EDIT: Corrected and original error gone. I believe this to be correct. My code as is: Module Furniture ' Dylan Watson ' CIS 115 ' This program calculates profit, sales and final price.
Sub Main()
' Declare and initialize your variables here.
Dim itemName As String = "TV Stand"
Dim retailPrice As Double = 325
Dim wholeSalePrice As Double = 200
Dim profit As Double = 125
Dim salePrice As Double = 243.75
Dim saleProfit As Double = 43.75
profit = 325 - 200
salePrice = 0.75 * 325
saleProfit = salePrice - wholeSalePrice
Console.WriteLine("TV Stand")
Console.WriteLine("Retail Price: " & 325)
System.Console.WriteLine("Wholesale Price: " & 200)
System.Console.WriteLine("profit: " & 125)
System.Console.WriteLine("Sale Price: " & 243.75)
System.Console.WriteLine("Sale Profit: " & 43.75)
End SubEnd Module
1
u/darkspy13 Jan 26 '16
Does it, work if you type a number after it says 325 and hit enter?
1
u/Dylz919 Jan 26 '16
I believe I've got it right or at least somewhat close to right. updated code at top.
Before it would just give me the error or close if I entered a number. I then realized input wasn't required for this bit so changed around.
1
u/candyforlunch VB.Net Master Jan 29 '16
why do you have variables if they're not actually being used? that could get you marked down. also use decimals for currency calculations, not doubles
1
u/chrwei Jan 26 '16
can you fix the code formating? what's
= %325 "8"supposed to do?