| 

.NET C# Java Javascript Exception

1
Wer kann mal hier weiterhelfen komme da nicht weiter....!

Textbox automatisch die Komma und Punkt setzen

0,25 oder 2,53 oder 253,00 oder 2.537,00 oder 25.372,00 usw.

Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
'
If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) Then
e.Handled = True
End If
End Sub


Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Select Case Val(Replace(TextBox1.Text, ",", "."))
Case 0 : TextBox1.Text = ""
Case ""
TextBox1.Text = Format(Val(Replace(TextBox1.Text, ",", "")) / 100, "0.00")
TextBox1.SelectionStart = Len(TextBox1.Text)
Case Else
TextBox1.Text = Format(Val(Replace(TextBox1.Text, ".", "")) / 1000, "0.000")
TextBox1.SelectionStart = Len(TextBox1.Text)
End Select
End Sub


Gruss TM
02.01.2021
tsmeier 81 1 3
5 Antworten
0
So könnte man es machen!!! Funktioniert aber noch nicht mit DE Layout!

Wer kann Helfen!

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

If Not String.IsNullOrEmpty(TextBox1.Text) Then
Dim culture As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("de-DE")
Dim valueBefore As Integer = Int32.Parse(TextBox1.Text, System.Globalization.NumberStyles.AllowThousands)
TextBox1.Text = String.Format(culture, "{0:n}", valueBefore) ' {0:n} {0:N0}
TextBox1.[Select](TextBox1.Text.Length, 0)
End If

End Sub


Gruss TM
06.01.2021
tsmeier 81 1 3
0
Mit Euro Zeichen

Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

If Not String.IsNullOrEmpty(TextBox1.Text) Then
Dim culture As System.Globalization.CultureInfo = New System.Globalization.CultureInfo("de-DE")
Dim valueBefore As Integer = Int32.Parse(TextBox1.Text, System.Globalization.NumberStyles.AllowThousands)
TextBox1.Text = String.Format(culture, "{0:C}", valueBefore) ' {0:n} {0:N0}
TextBox1.[Select](TextBox1.Text.Length, 0)
End If

End Sub
06.01.2021
tsmeier 81 1 3
0
Culturinfo festlegen... geht aber auch nicht 111.111.111 sollte so aussehen 1.245,00!

Private Sub TextBox2_TextChanged(sender As Object, e As EventArgs) Handles TextBox2.TextChanged
Dim ci As CultureInfo
ci = New CultureInfo("de-DE")

If Not String.IsNullOrWhiteSpace(TextBox2.Text) Then ' IsNullOrWhitespace IsNullOrEmpty
Dim culture As System.Globalization.CultureInfo = ci 'New System.Globalization.CultureInfo("de-DE") ' "de-DE" "en-US"
Dim valueBefore As Integer = Int32.Parse(TextBox2.Text, System.Globalization.NumberStyles.AllowThousands)
TextBox2.Text = String.Format(culture, "{0:#,#}", valueBefore) ' {0:n} {0:N0} {0:#,#}
'TextBox2.Text = String.Format(ci, "{0:#,#}", valueBefore)
TextBox2.[Select](TextBox1.Text.Length, 0)

End If

End Sub
06.01.2021
tsmeier 81 1 3
0
So eine verkürzter Code für die Textbox:
Wäre noch gut wenn man die Zahl so eingibt das der Cursor rechts bleibt!!! so wie man den Wert eingibt 125,35 nur er wandert nach links ab...

Dim number As Decimal

If Decimal.TryParse(TextBox1.Text, number) Then
TextBox1.Text = String.Format("{0:#,##0.00}", number)
Else
'TextBox1.Text = ""
'TextBox1.[Select](TextBox1.Text.Length, 0)
'TextBox1.SelectionStart = Len(TextBox1.Text)
TextBox1.Text = Strings.Left(Replace(TextBox1.Text, ",", ""), Strings.Len(Replace(TextBox1.Text, ",", "")) - 1) & "," & Strings.Right(Replace(TextBox1.Text, ",", ""), 1)
End If




Gruss TM
07.01.2021
tsmeier 81 1 3
0
So noch nicht ganz perfekt....

If TextBox1.Text = "" Or TextBox1.Text = "€" Or TextBox1.Text = "0" Then
TextBox1.Text = String.Format("{0:C}", "0,00 €")
'MsgBox("Please fill in all boxes")
End If

TextBox1.Text = TextBox1.Text.Trim
If Not TextBox1.Text = "0" And Not TextBox1.Text = "0,00" Then 'String.IsNullOrEmpty(TextBox.Text)

Dim aDouble As Double = CType(TextBox1.Text, Double)
TextBox1.Text = Format([aDouble], "c").Replace("$", "")
TextBox1.SelectionStart = Len(TextBox1.Text)
TextBox1.ScrollToCaret()
TextBox1.Focus()
End If


Gruss TM
07.01.2021
tsmeier 81 1 3

Stelle deine --Frage jetzt!