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
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
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
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
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