Curseur

clovis23 Messages postés 8 Date d'inscription mardi 24 février 2004 Statut Membre Dernière intervention 8 août 2005 - 8 août 2005 à 11:15
wael1_2 Messages postés 5 Date d'inscription vendredi 5 août 2005 Statut Membre Dernière intervention 18 août 2005 - 17 août 2005 à 10:10
Bjr à tous


Voici mon pb: je veux saisir une date de naissance au format jj/mm/aaaa dans 3 textBox (1 pour jj, 1 pour mm et 1 pour aaaa).Comment spécifier que je veux que des chiffres (c.a.d. 01à31 pour jj, 01 à 12 pour mm et pour aaaa tous nombres à 4 chiffres) et une fois le jj saisi le curseur passe au mm puis au aaaa une fois le mm saisi.
Merci.

4 réponses

fcampagne Messages postés 195 Date d'inscription vendredi 3 juin 2005 Statut Membre Dernière intervention 13 juillet 2006 3
8 août 2005 à 11:27
Slt

A chaque saisi dans tes champs tu teste la longueur du texte saisi,

Par exemple si la longueur de ton texte jj est egal a 2 alors tu donen le focus a mm

Pour verifier si c'est bien des chiffres entrés, fait un test >1 and <31 pour jj

Il n'y a pas en VB une fonction Isnumeric???

Voila quelques pistes
0
Gobillot Messages postés 3140 Date d'inscription vendredi 14 mai 2004 Statut Membre Dernière intervention 11 mars 2019 34
8 août 2005 à 11:44
exemple de code pour saisie d'une date avec controle direct.

sinon il y a le MaskedEditBox

ou encore Dtpicker ou Monthview





Option Explicit



Private Sub Form_Load()

'pour effacer ou pour initialiser

Text1.Text = "00/00/0000"

End Sub



Private Sub Text1_KeyDown(Key As Integer, Shift As Integer)

If Key = 39 Then

If Text1.SelStart 1 Then Text1.SelStart 2

If Text1.SelStart 4 Then Text1.SelStart 5

End If

If Key = 37 Then

If Text1.SelStart 3 Then Text1.SelStart 2

If Text1.SelStart 6 Then Text1.SelStart 5

End If

If Key 38 Then Key 0

If Key 40 Then Key 0

If Key 46 Then Key 0

End Sub



Private Sub Text1_KeyPress(Key As Integer)

Dim K As Integer

Dim x As Integer

K Key: Key 0

Select Case K

Case 8:

If Text1.SelStart > 0 Then Text1.SelStart = Text1.SelStart - 1

Case 48 To 57:

x = Text1.SelStart

If x = 0 Then

If (K -
48) * 10 + Asc(Mid$(Text1, 2, 1)) - 48 > 31 Then Beep: Exit Sub

End If

If x = 1 Then

If
(Asc(Mid$(Text1, 1, 1)) - 48) * 10 + K - 48 > 31 Then Beep: Exit Sub

End If

If x = 3 Then

If (K -
48) * 10 + Asc(Mid$(Text1, 5, 1)) - 48 > 12 Then Beep: Exit Sub

End If

If x = 4 Then

If
(Asc(Mid$(Text1, 4, 1)) - 48) * 10 + K - 48 > 12 Then Beep: Exit Sub

End If

If x 2 Then Text1.SelStart 3: Beep: Exit Sub

If x 5 Then Text1.SelStart 6: Beep: Exit Sub

If x = 10 Then Exit Sub

Text1 = Left$(Text1, x) & Chr$(K) & Mid$(Text1, x + 2)

If x 1 Then x 2

If x 4 Then x 5

Text1.SelStart = x + 1

Case 13: 'fin de saisie

If IsDate(Text1) Then

MsgBox "valide"

Else

MsgBox "non valide"

End If

Case Else: Beep

End Select

End Sub


Daniel
0
clovis23 Messages postés 8 Date d'inscription mardi 24 février 2004 Statut Membre Dernière intervention 8 août 2005
8 août 2005 à 12:45
Pouvez vous me donner un exemple de code
0
wael1_2 Messages postés 5 Date d'inscription vendredi 5 août 2005 Statut Membre Dernière intervention 18 août 2005
17 août 2005 à 10:10
Bjr à tous


Voici mon pb: je veux que le curseur soit dans la zone de texte (textbox) a chaque click sur n'importe quelle boutton
Merci.
0
Rejoignez-nous