2013-11-02 142 views
1

我有這個簡單的程序,給我一個錯誤。代碼如下所示從字符串轉換爲整數vb.net

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 

當我嘗試MessageBox的全名,地址和citystatezip它不斷給我一個錯誤說,它不能將地址轉換爲整數。我將所有這三個變量都聲明爲字符串,並在程序中將其運行時,我在這三個文本框中輸入了A B和C。

回答

2

爲MSGBOX的語法(如VS將通過智能感知告訴你)是:

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

當你調用MSGBOX你的第二個參數應該是指明樣式的整數。試試這個:

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

或添加換行符,如果您選擇。