Guide Contents
|
DigitalDan Home Page
|
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(8) Then Exit Sub ' 1
If Not "0123456789".Contains(e.KeyChar) Then
e.Handled = True ' 2
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim oldText As String = TextBox1.Text
Dim regex As New System.Text.RegularExpressions.Regex("[^0-9]")
Dim newText As String = regex.Replace(oldText, "") ' 3
If oldText <> newtext Then ' 4
TextBox1.Text = newText
End If
End Sub
Private Function Read_TextBox1() As Integer
Dim ret As Integer
If Not Integer.TryParse(TextBox1.Text, ret) Then Return 0 ' 5
Return ret
End Function
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(8) Then Exit Sub
If Not "0123456789.".Contains(e.KeyChar) Then
e.Handled = True
End If
If e.KeyChar = "."c AndAlso TextBox1.Text.Contains("."c) Then
e.Handled = True
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim oldText As String = TextBox1.Text
Dim regex As New System.Text.RegularExpressions.Regex("[^0-9.]")
' this version does not alloiw exponential numbers
Dim newText As String = regex.Replace(oldText, "")
' ensure maximum of one decimal point
Dim parts() As String = newText.Split("."c)
If parts.Length > 2 Then
newText = parts(0) & "."c & parts(1)
End If
If oldText <> newText Then
TextBox1.Text = newText
MsgBox("changed")
End If
End Sub
Private Function Read_TextBox1() As Double
Dim ret As Double
If Not Double.TryParse(TextBox1.Text, ret) Then Return 0
Return ret
End Function
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(8) Then Exit Sub
If Not "0123456789+-".Contains(e.KeyChar) Then
e.Handled = True
End If
If e.KeyChar = "+"c Then
Button1.Text = "+"
e.Handled = True
End If
If e.KeyChar = "-"c Then
Button1.Text = "-"
e.Handled = True
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim oldText As String = TextBox1.Text
Dim regex As New System.Text.RegularExpressions.Regex("[^0-9+-]")
' this version does not allow exponential numbers
Dim newText As String = regex.Replace(oldText, String.Empty)
For Each c As Char In newText
If c = "+"c Then Button1.Text = "+"
If c = "-"c Then Button1.Text = "-"
Next
newText = newText.Replace("+"c, String.Empty).Replace("-"c, String.Empty)
If oldText <> newText Then
TextBox1.Text = newText
MsgBox("changed")
End If
End Sub
Private Function Read_TextBox1() As Integer
Dim ret As Integer
Dim num As String = TextBox1.Text.Replace("+"c, String.Empty)
num = num.Replace("-", String.Empty)
If Button1.Text = "-" Then num = "-" & num
If Not Integer.TryParse(num, ret) Then Return 0
Return ret
End Function
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(8) Then Exit Sub
If Not "0123456789+-.".Contains(e.KeyChar) Then
e.Handled = True
End If
If e.KeyChar = "."c AndAlso TextBox1.Text.Contains("."c) Then
e.Handled = True
End If
If e.KeyChar = "+"c Then
Button1.Text = "+"
e.Handled = True
End If
If e.KeyChar = "-"c Then
Button1.Text = "-"
e.Handled = True
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim oldText As String = TextBox1.Text
Dim regex As New System.Text.RegularExpressions.Regex("[^0-9+.-]")
' this version does not allow exponential numbers
Dim newText As String = regex.Replace(oldText, String.Empty)
For Each c As Char In newText
If c = "+"c Then Button1.Text = "+"
If c = "-"c Then Button1.Text = "-"
Next
newText = newText.Replace("+"c, String.Empty).Replace("-"c, String.Empty)
Dim parts() As String = newText.Split("."c)
If parts.Length > 2 Then
newText = parts(0) & "." & parts(1)
End If
If oldText <> newText Then
TextBox1.Text = newText
MsgBox("changed")
End If
End Sub
Private Function Read_TextBox1() As Integer
Dim ret As Integer
Dim num As String = TextBox1.Text.Replace("+"c, String.Empty)
num = num.Replace("-", String.Empty)
If Button1.Text = "-" Then num = "-" & num
If Not Integer.TryParse(num, ret) Then Return 0
Return ret
End Function
DigitalDan.co.uk ... Hits = 108