我試着做一個程序,當我把一個值小於0時,在標籤像「 負數不能使用我有這個視覺基本小於0
Public Class Form1 'Sebastian roman. Perimeter, 10/1/2014
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Try
Dim intSide1 As Integer = txtSide1.Text
Dim intSide2 As Integer = txtSide2.Text
Dim intSide3 As Integer = txtSide3.Text
Dim intSide4 As Integer = txtSide4.Text
Dim intTotal As Integer = intSide1 + intSide2 + intSide3 + intSide4
lblMessage.Text = intTotal.ToString("#,###.##")
Catch ex As Exception
MessageBox.Show("Incorrect Input. Enter a numeric value.")
End Try
End Sub
End Class
是的,我有使用嘗試捕捉方法,我需要幫助這個
這將防止它甚至點擊按鈕前:http://stackoverflow.com/a/17036254/752527 – 2014-10-02 15:07:38
我不知道vb.net。但你可以像這樣('Dim intSide1 As Integer = txtSide1.Text')給'Integer'分配一個'String'?我想你會需要一個'Parse'或'TryParse'。 – crashmstr 2014-10-02 15:10:17
@crashmstr:使用'Option Strict Off',它會爲您執行隱式轉換。 – 2014-10-02 15:16:39