Problème avec inputbox

stepaustral Messages postés 54 Date d'inscription dimanche 5 janvier 2003 Statut Membre Dernière intervention 29 juillet 2012 - 16 oct. 2003 à 15:27
stepaustral Messages postés 54 Date d'inscription dimanche 5 janvier 2003 Statut Membre Dernière intervention 29 juillet 2012 - 16 oct. 2003 à 19:50
voila j'ai un petit programme avec une listview et un bouton pour l'imprimer quand je clique dessus ca lance une inputbox avec la date a inscrire le truc c que quand j'annule cela me fais une erreur 13 voici le code pour que tous le monde comprenne bien

Private Sub Impr_Click()
Dim DATE1 As Date
MouseOn
Dim DATEx As Date
Dim entree As String
Dim SORTIE As String
Dim TENTREE As String
Dim TSORTIE As String
Dim OBSERV As String
Dim RESTE As String
Dim T
Dim Chaine As String

DATE1 = InputBox("De la date :", "Date", Format("01/01/" & Year(Date), "dd/mm/yyyy"))
SetupPrinter

SetFont 10, False, False, False, False
Printer.Print "COMPTE:" & Text1.Text
PrintLine

TENTREE = "0"
TSORTIE = "0"

NB_oBr = Val(LireKeyIni("OPR", "NB_OPR", Fichier))
RESTE = "0"

Printer.Print ""

For T = 1 To NB_oBr
Chaine = LireKeyIni("OPR", "OPR" & Trim(Str(T)), Fichier)
If Mid(Chaine, 1, 10) <> "Supprimer" Then
DATEx = Mid(Chaine, 1, 10)
If Val(SupprimerC(Mid(Chaine, 12, 7), "_")) < 0 Then
SORTIE = Format(SupprimerC(Mid(Chaine, 12, 7), "_"), "0.000")
entree = "0"
Else
entree = Format(SupprimerC(Mid(Chaine, 12, 7), "_"), "0.000")
SORTIE = "0"
End If
OBSERV = Mid(Chaine, 21, Len(Chaine) - 18)
RESTE = Format(Str(Val(RESTE) + Val(entree) + Val(SORTIE)), "0.000")

If DATEx >= DATE1 Then
TENTREE = Format(Val(TENTREE) + Val(entree), "0.000")
TSORTIE = Format(Val(TSORTIE) + Val(SORTIE), "0.000")
Printer.Print String(5, " ") & DATEx _
& String(2, " ") & String(12 - Len(entree), " ") & entree _
& String(2, " ") & String(12 - Len(SORTIE), " ") & SORTIE _
& String(2, " ") & String(12 - Len(RESTE), " ") & RESTE _
& String(2, " ") & OBSERV
End If
End If
Next T
PrintLine
SetFont 10, True, False, False, False

Printer.Print ""

Printer.Print String(5, " ") & Format(Date, "dd/mm/yyyy") _
& String(2, " ") & String(12 - Len(TENTREE), " ") & TENTREE _
& String(2, " ") & String(12 - Len(TSORTIE), " ") & TSORTIE _
& String(2, " ") & String(12 - Len(RESTE), " ") & RESTE _
& String(2, " ") & "TOTAUX"

Printer.EndDoc
MouseOff

End Sub

2 réponses

stabe Messages postés 144 Date d'inscription lundi 23 décembre 2002 Statut Membre Dernière intervention 17 juin 2006
16 oct. 2003 à 15:56
Quand tu fais annuler dans une inputbox, ça te renvoie une chaine vide donc tu as alors date1 = ""
Mais comme tu as déclaré date1 de type Date, ça fait boom ("" n'est pas un format de date valide)

Une solution (parmi d'autres) :

dim r as string

r = InputBox("De la date :", "Date", Format("01/01/" & Year(Date), "dd/mm/yyyy"))

'format de date invalide ou appuie sur Annuler ?
if not isdate(r) then exit sub

date1 = cdate(r)
...

-- stabe --
0
stepaustral Messages postés 54 Date d'inscription dimanche 5 janvier 2003 Statut Membre Dernière intervention 29 juillet 2012
16 oct. 2003 à 19:50
cool ca fonctionne je te remerci ;) donc je remet le code en entier en faite c juste le debut modifié pour ceux que ca interesserais

Private Sub Impr_Click()
Dim DATE1 As String
Dim DATEx As Date
Dim entree As String
Dim SORTIE As String
Dim TENTREE As String
Dim TSORTIE As String
Dim OBSERV As String
Dim RESTE As String
Dim T
Dim Chaine As String

DATE1 = InputBox("De la date :", "Date", Format("01/01/" & Year(Date), "dd/mm/yyyy"))
If Not IsDate(DATE1) Then Exit Sub
0
Rejoignez-nous