这个消息框有什么问题?

时间:2016-02-10 20:16:05

标签: vba

我很好奇为什么最终的msgBox失败了。我得到语法错误和语句结束错误。

Option Explicit

Private Sub Travel_Expenses_Click()

    Dim firstName As String
    Dim lastName As String
    Dim nMiles As Single
    Dim milesPerGallon As Single
    Dim avgPrice As Currency
    Dim tripCost As Currency

    firstName = InputBox("Enter your first name", "Expenses Calculator", "First")
    lastName = InputBox("Enter your last name", "Expenses Calculator", "Last")
    nMiles = InputBox("How many miles did you drive", "Expenses Calculator",     "99")
    milesPerGallon = InputBox("What was your average miles per gallon", "Expenses   Calculator", "35")
    avgPrice = InputBox("What was the average price per gallon on your trip",     "Expenses Calculator", "1.90")
    tripCost = nMiles / milesPerGallon * avgPrice

    msgBox firstName & lastName & " Traveled " & nMiles & "Miles, got " & _
    milesPerGallon & "Miles per Gallon on average, paid " & _
    avgPrice & "per gallon on average, and paid a total of " & tripCost _
    " for gas"




End Sub

1 个答案:

答案 0 :(得分:5)

您忘记了最后两个组件之间的&运算符:

tripCost _
" for gas"

应该是:

tripCost & _
" for gas"