Reputation: 11
I'm new to coding on Visual Basic and was wondering if anyone knew why the end total cost isn't working. Currently I keep getting C as the end value
Here is the variables bit so you can see the data types I have set
Dim Height As Decimal
Dim HeightValidation As Boolean
Dim Width As Decimal
Dim WidthValidation As Boolean
Dim TotalArea As Decimal
Dim Paint As String
Dim PaintValidation As Boolean
Dim Cost As Decimal
Dim FinalCost As Decimal
Dim UndercoatValidation As Boolean
Dim Undercoat As String
And here is the last bit of the code
Do Until UndercoatValidation = True
UnderCoat = InputBox("Would you like to add an Undercoat to your purchase?")
If Undercoat = "Yes" Then
FinalCost = Cost + (TotalArea * 0.5)
UndercoatValidation = True
ElseIf Undercoat = "No" Then
FinalCost = Cost
Else
UndercoatValidation = False
End If
Loop
MsgBox("Thank you for using the Paint Calculator")
MsgBox("Your total cost is"(FormatCurrency(FinalCost)))
Thanks in advance. By the way before I added the currency bit it worked.
So the values of cost will change depending on whether or not the user wishes to have an undercoat, what type of paint they use and the area of the room.
Do Until HeightValidation = True
Height = InputBox("Enter the height of the room you are working in: ") 'Gains users value
If (2 <= Height) AndAlso (Height <= 6) Then 'Only allows number between 2 and 6
HeightValidation = True 'breaks the loop if the requirements are met
Else
HeightValidation = False 'continues the loop if the requirements are not met
End If
Loop
Do Until WidthValidation = True
Width = InputBox("Enter the width of the room you are working in: ") 'Gains users value
If (1 <= Width) AndAlso (Width <= 25) Then 'Only allows number between 1 and 25
WidthValidation = True 'breaks the loop if the requirements are met
Else
WidthValidation = False 'continues the loop if the requirements are not met
End If
Loop
TotalArea = Height * Width
Do Until PaintValidation = True
MsgBox("There are 3 different types of paint you could you, which are: Luxury which costs £1.75 per square metre; standard which costs £1 per square metre and economy which costs £0.45 per square metre")
Paint = InputBox("Which type of paint will you be using to paint the walls?")
If Paint = "standard" Then
Cost = TotalArea * 1
PaintValidation = True
ElseIf Paint = "economy" Then
Cost = TotalArea * 0.45
PaintValidation = True
ElseIf Paint = "luxury" Then
Cost = TotalArea * 1.75
PaintValidation = True
Else
PaintValidation = False
End If
Loop
That's the rest of the code that works out the costs, sorry for all the code not being annotated.
Upvotes: 0
Views: 47
Reputation: 78155
MsgBox("Your total cost is"(FormatCurrency(FinalCost)))
That means "show the character at position FormatCurrency(FinalCost)
from the string "Your total cost is"
.
Apparently the result of FormatCurrency(FinalCost)
is implicitly convertible to 11
, so it shows the "c"
.
Apparently you meant
MsgBox("Your total cost is " & FormatCurrency(FinalCost))
Please use Option Strict On
to not have this kind of problems in the future.
Upvotes: 1