codice:
'Il nostro numero dalla conversione della TextBox
Private myNumber As Double
Private Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim myStringNum As String() = TextBox1.Text.Split(New Char() {"."c, ","c})
Try
If myStringNum.Length = 0 Then
myNumber = 0
ElseIf myStringNum.Length = 1 OrElse myStringNum(1).Length = 0 Then
myNumber = CInt(myStringNum(0))
Else
myNumber = CInt(myStringNum(0))
myNumber += CInt(myStringNum(1)) / (10 ^ myStringNum(1).Length)
End If
Catch ex As InvalidCastException
'Se siamo quì vuol dire che nella text o ci sono caratteri non numerici oppure è vuota
myNumber = 0
End Try
End Sub
Ecco quà, funziona sia che usi la virgola od il punto come separatore,L'ho fatto in 5 min, dunque nn sperare che non abbia bug
Il catch particolare serve per intercettare quando CInt non riesce ad effettuare la conversione(es CInt("text") o anche CInt(""))
Ciao