Private Sub TextBox_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles TextBox1.Leave, _
TextBox2.Leave, _
TextBox3.Leave, _
TextBox4.Leave
Dim result As Decimal
If Not Decimal.TryParse(sender.Text.Trim, result) Then
result = 0.0
End If
sender.Text = result.ToString("##0.00")
End Sub
Showing posts with label Decimal.TryParse. Show all posts
Showing posts with label Decimal.TryParse. Show all posts
Thursday, October 12, 2017
ตัวอย่างการใช้งาน Decimal.TryParse กับ TextBox มากกว่า 1 TextBox
การใช้งาน Decimal.TryParse เพื่อช่วยในการตรวจสอบค่าที่ผู้ใช้ป้อนใน TextBox
Private Sub TextBox1_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) _
Handles TextBox1.Leave
Dim result As Decimal
If Not Decimal.TryParse(TextBox1.Text.Trim, result) Then
result = 0.0
End If
TextBox1.Text = result.ToString("##0.00")
End Sub
ตัวอย่างการใช้ Decimal.TryParse
Dim result as Decimal = 0.0 if Decimal.TryParse(txt1.text, result) then ' valid entry else ' invalid entry end if
Wednesday, October 11, 2017
ตัวอย่างการใช้ Decimal.TryParse, Leave
Private Sub txtEstimateAmount_Leave(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles txtEstimateAmount.Leave
' Take any dollars-and-cents amount and round to the nearest dollar
Dim est As Decimal
est = Decimal.TryParse(txtEstimateAmount.Text.Trim, est)
txtEstimateAmount.Text = If(est <> 0, Math.Round(est).ToString(), String.Empty)
End Sub
ตัวอย่างการใช้ Decimal.TryParse, Validating
Private Sub TextBox1_Validating(ByVal sender As System.Object, _
ByVal e As System.ComponentModel.CancelEventArgs) _
Handles TextBox1.Validating
Dim est As Decimal
If TextBox1.Text.Length = 0 then Exit Sub '' optional
If Not Decimal.TryParse(TextBox1.Text.Trim, est) Then
e.Cancel = True
TextBox1.SelectAll()
Else
TextBox1.Text = est.ToString("N0")
End If
End Sub
ตัวอย่างการใช้งาน Decimal.TryParse
Dim a as string
Dim b as Decimal
If Decimal.TryParse(a, b) Then
a = b.ToString("##,##0.00")
Else
a = "can not parse"
End If
Subscribe to:
Posts (Atom)