我正在尝试执行一个计算游乐园员工每周工资的项目。付款计算程序中的“从字符串转换为Double类型无效”
当我运行它并将数字放在文本框中时,出现一条错误消息,提示“字符串转换为Double类型无效”。
有人可以善意解释我出错的地方吗?
Dim ticketCollection As Double
Dim foodService As Double
Dim cleaningService As Double
Dim ridingAssistance As Double
Dim totalAmount As Double
Dim totalCollectionPay As Double
Dim totalFoodPay As Double
Dim totalCleaningPay As Double
Dim totalRidingPay As Double
ticketCollection = txtCollection.Text
foodService = txtFood.Text
cleaningService = txtCleaning.Text
ridingAssistance = txtRide.Text
totalCollectionPay = ticketCollection * 5
totalFoodPay = foodService * 10
totalCleaningPay = cleaningService * 6
totalRidingPay = ridingAssistance * 5
totalAmount = totalCollectionPay + totalFoodPay + totalCleaningPay + totalRidingPay
lblTotalDue.Text = totalAmount
它发生在哪一行?这可能会更好(更简单)在Excel中构建。基本上你的文本字段中有一个非数字字符(可能是空白)。你可以试试这个方法来确保只输入数字:http://stackoverflow.com/questions/463299/how-do-i-make-a-textbox-that-only-accepts-numbers –
@ Nick.McDermaid错误显示在foodservice = txtFood.Text –
@RomarioAlleyne - 您应该在代码的顶部放置'Option Strict On',看看编译器告诉你什么。在提出关于VB.NET的任何问题之前,你应该这样做。 – Enigmativity