1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
| Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Code généré par le Concepteur Windows Form "
Public Sub New()
MyBase.New()
'Cet appel est requis par le Concepteur Windows Form.
InitializeComponent()
'Ajoutez une initialisation quelconque après l'appel InitializeComponent()
End Sub
'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Requis par le Concepteur Windows Form
Private components As System.ComponentModel.IContainer
'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
'Elle peut être modifiée en utilisant le Concepteur Windows Form.
'Ne la modifiez pas en utilisant l'éditeur de code.
Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
Friend WithEvents TextBox2 As System.Windows.Forms.TextBox
Friend WithEvents TextBox3 As System.Windows.Forms.TextBox
Friend WithEvents TextBox4 As System.Windows.Forms.TextBox
Friend WithEvents TextBox5 As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
Friend WithEvents Label5 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.TextBox1 = New System.Windows.Forms.TextBox
Me.TextBox2 = New System.Windows.Forms.TextBox
Me.TextBox3 = New System.Windows.Forms.TextBox
Me.TextBox4 = New System.Windows.Forms.TextBox
Me.TextBox5 = New System.Windows.Forms.TextBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.Label3 = New System.Windows.Forms.Label
Me.Label4 = New System.Windows.Forms.Label
Me.Label5 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'TextBox1
'
Me.TextBox1.Location = New System.Drawing.Point(152, 48)
Me.TextBox1.Name = "TextBox1"
Me.TextBox1.TabIndex = 0
Me.TextBox1.Text = ""
'
'TextBox2
'
Me.TextBox2.Location = New System.Drawing.Point(152, 80)
Me.TextBox2.Name = "TextBox2"
Me.TextBox2.TabIndex = 1
Me.TextBox2.Text = ""
'
'TextBox3
'
Me.TextBox3.Location = New System.Drawing.Point(152, 112)
Me.TextBox3.Name = "TextBox3"
Me.TextBox3.TabIndex = 2
Me.TextBox3.Text = ""
'
'TextBox4
'
Me.TextBox4.Location = New System.Drawing.Point(152, 144)
Me.TextBox4.Name = "TextBox4"
Me.TextBox4.TabIndex = 3
Me.TextBox4.Text = ""
'
'TextBox5
'
Me.TextBox5.Location = New System.Drawing.Point(152, 176)
Me.TextBox5.Name = "TextBox5"
Me.TextBox5.TabIndex = 4
Me.TextBox5.Text = ""
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(0, 48)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(64, 23)
Me.Label1.TabIndex = 5
Me.Label1.Text = "Entier"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(0, 80)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(64, 23)
Me.Label2.TabIndex = 6
Me.Label2.Text = "Decimal"
'
'Label3
'
Me.Label3.Location = New System.Drawing.Point(0, 112)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(72, 23)
Me.Label3.TabIndex = 7
Me.Label3.Text = "Entier negatif"
'
'Label4
'
Me.Label4.Location = New System.Drawing.Point(0, 144)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(72, 23)
Me.Label4.TabIndex = 8
Me.Label4.Text = "Demi"
'
'Label5
'
Me.Label5.Location = New System.Drawing.Point(0, 176)
Me.Label5.Name = "Label5"
Me.Label5.Size = New System.Drawing.Size(160, 16)
Me.Label5.TabIndex = 9
Me.Label5.Text = "Texte (seulement 'azertyuiop')"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Controls.Add(Me.TextBox5)
Me.Controls.Add(Me.Label5)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.TextBox4)
Me.Controls.Add(Me.TextBox3)
Me.Controls.Add(Me.TextBox2)
Me.Controls.Add(Me.TextBox1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Enum FormatTexte
Décimal
Entier
Demi
Texte
Décimal_Négatif
Entier_Négatif
End Enum
Friend Sub FormatText(ByRef MonTexte As String, ByVal TypeTexte As FormatTexte, Optional ByVal Etendue As String = "", Optional ByVal TexteBox As TextBox = Nothing)
'definition format
Dim Numerique, Entier, Pointure, Negatif As Boolean
Select Case TypeTexte
Case FormatTexte.Décimal
Numerique = True
Entier = False
Negatif = False
Pointure = False
Case FormatTexte.Décimal_Négatif
Numerique = True
Entier = False
Negatif = True
Pointure = False
Case FormatTexte.Entier
Numerique = True
Entier = True
Negatif = False
Pointure = False
Case FormatTexte.Entier_Négatif
Numerique = True
Entier = True
Negatif = True
Pointure = False
Case FormatTexte.Demi
Numerique = True
Entier = False
Negatif = False
Pointure = True
Case FormatTexte.Texte
Numerique = False
Entier = False
Negatif = False
Pointure = False
End Select
'Definition du séparateur décimal défini dans le panneau de configuration
'************************************************************************
Dim SeparateurDecimal As String
If Pointure = False Then
Dim Nombre As Single
Nombre = Val("1.1")
SeparateurDecimal = Mid(CStr(Nombre), 2, 1)
Else
SeparateurDecimal = "½"
End If
' Si le champs est numérique
'***************************
If Numerique Then
If Not Entier Then
'si decimal
MonTexte = MonTexte.Replace(",", SeparateurDecimal)
MonTexte = MonTexte.Replace(".", SeparateurDecimal)
If MonTexte.Compare(MonTexte, SeparateurDecimal) <> 0 Then
If MonTexte.IndexOf(SeparateurDecimal) <> MonTexte.LastIndexOf(SeparateurDecimal) Then
MonTexte = Mid(MonTexte, 1, MonTexte.LastIndexOf(SeparateurDecimal)) 'garde qu'un seul SeparateurDecimal
End If
End If
RefreshNum:
If Negatif = False Then
For x As Int16 = 1 To MonTexte.Length
If Not IsNumeric(Mid(MonTexte, x, 1)) And Mid(MonTexte, x, 1) <> SeparateurDecimal Then
MonTexte = MonTexte.Remove(x - 1, 1)
GoTo RefreshNum
End If
Next
Else
For x As Int16 = 1 To MonTexte.Length
If Not IsNumeric(Mid(MonTexte, x, 1)) And Mid(MonTexte, x, 1) <> SeparateurDecimal And Mid(MonTexte, x, 1) <> "-" Then
MonTexte = MonTexte.Remove(x - 1, 1)
GoTo RefreshNum
End If
Next
End If
Else
'si entier
MonTexte = MonTexte.Replace(",", "")
MonTexte = MonTexte.Replace(".", "")
RefreshNumInt:
If Negatif = False Then
For x As Int16 = 1 To MonTexte.Length
If Not IsNumeric(Mid(MonTexte, x, 1)) Then
MonTexte = MonTexte.Remove(x - 1, 1)
GoTo RefreshNumInt
End If
Next
Else
For x As Int16 = 1 To MonTexte.Length
If Not IsNumeric(Mid(MonTexte, x, 1)) And Mid(MonTexte, x, 1) <> "-" Then
MonTexte = MonTexte.Remove(x - 1, 1)
GoTo RefreshNumInt
End If
Next
End If
End If
Else
'sinon si alpha
RefreshAlpha:
If MonTexte.Compare(MonTexte, Etendue) <> 0 Then
For x As Int16 = 1 To MonTexte.Length
If InStr(Etendue, Mid(MonTexte, x, 1)) < 1 Then
MonTexte = MonTexte.Remove(x - 1, 1)
GoTo RefreshAlpha
End If
Next
End If
End If
On Error Resume Next
TexteBox.Text = MonTexte
TexteBox.Select(Len(TexteBox.Text), 0)
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Me.FormatText(Me.TextBox1.Text, FormatTexte.Entier, , Me.TextBox1)
End Sub
Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
Me.FormatText(Me.TextBox2.Text, FormatTexte.Décimal, , Me.TextBox2)
End Sub
Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
Me.FormatText(Me.TextBox3.Text, FormatTexte.Entier_Négatif, , Me.TextBox3)
End Sub
Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
Me.FormatText(Me.TextBox4.Text, FormatTexte.Demi, , Me.TextBox4)
End Sub
Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
Me.FormatText(Me.TextBox5.Text, FormatTexte.Texte, "azertyuiop", Me.TextBox5)
End Sub
End Class |