1

我有这个简单的程序给我一个错误。代码如下

    Private Sub btnProcess_Click(sender As Object, e As EventArgs) Handles btnProcess.Click
    Dim FullName As String = "" 
    Dim Address As String = "" 
    Dim CityStateZip As String = "" 
    Dim Stoves As Integer 
    Dim Refrigerators As Integer 
    Dim Dishwashers As Integer 

    INPUT_DATA(FullName, Address, CityStateZip, Stoves, Refrigerators, Dishwashers)
    MsgBox(FullName, Address, CityStateZip)

End Sub
Sub INPUT_DATA(ByRef Name As String, ByRef Address As String, ByRef CSZ As String, ByRef Stoves As Integer, ByRef Refrigerators As Integer, ByRef Dishwashers As Integer)
    If txtName.Text = "" Then
        Name = InputBox("Please enter a name!")
    Else
        Name = txtName.Text
    End If
    If txtAddress.Text = "" Then
        Address = InputBox("Please enter an address!")
    Else
        Address = txtAddress.Text
    End If
    If txtCSZ.Text = "" Then
        CSZ = InputBox("Please enter City, State, Zip!")
    Else
        CSZ = txtCSZ.Text
    End If
End Sub

当我尝试使用消息框全名、地址和 citystatezip 时,它一直给我一个错误,说它无法将地址转换为整数。我将所有这三个变量都声明为字符串,并在运行程序时在这三个文本框中输入 AB 和 C。

4

1 回答 1

2

MsgBox 的语法(正如 VS 将通过 Intellisense 向您展示的那样)是:

 MsgBox (Prompt, Optional ByVal Buttons As Microsoft.VisualBasic.MsgBoxStyle = _ 
         OkOnly, Optional ByVal Title As Object = Nothing)

当您调用 MsgBox 时,您的第二个参数应该是指示样式的 Integer。尝试这个:

  MsgBox (FullName & " - " & Address & " - " & CityStateZip)

或者如果您选择添加换行符。

于 2013-11-03T00:02:11.677 回答