0
我是新来Visual编码基础知识,并想知道如果有人知道为什么最终总成本不起作用。目前,我不断收到C作为终值Visual Basic货币错误一直给我C的价值
这里是变量位,所以你可以看到我已经设置
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
而且这里的数据类型是代码
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)))
的最后一位
提前致谢。顺便说一句,我添加了它工作的货币位。
因此,成本的价值将根据用户是否希望拥有底漆,他们使用何种类型的涂料以及房间面积而改变。
Do Until HeightValidation = True
Height = InputBox("Enter the height of the room you are workin 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 workin 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: Luxary which costs £1.75 per square metre; standard which costs £1 per square metre and economy wich 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 = "luxary" Then
Cost = TotalArea * 1.75
PaintValidation = True
Else
PaintValidation = False
End If
Loop
这就是代码的其余部分,可以计算出所有代码的遗漏,对所有代码都没有注释。
“Cost”和“TotalArea”的值是多少?另外,我建议不要使用带有InputBox的Do/Loop。没有必要让用户键入Yes或No ...如果他们键入小写字母,则逻辑失败。只需使用带有Yes和No按钮的MessageBox,并根据返回值执行逻辑。 –
成本和总面积的值将根据用户输入的内容而变化。如果需要,我可以上传这段代码。而随着逻辑的事情,我会改进我的代码,就像你说的。对不起,vb – IcarusFlight