19. december 2003 - 10:34Der er
3 kommentarer og 1 løsning
IsTime funktion i ASP
Hej
Er der nogle der har et forslag til hvordan man kontrollere om et tidspunkt er indtastet rigtigt og kan indsættes i en Aceess database. Faktisk en istime funktion.
Pos=InStr(Valor,":") Aux=(len(valor)<=8 and len(valor)>=3) And ((Pos=2 or Pos=3)) 'Verifica-se se o tamanho e o separador (:) estao bem h=Mid(Valor,1,Pos-1) If IsNumeric(h) Then 'Captura-se a Hora h=Cint(h) Aux=(h>=0 And h<=23) 'Verifica-se se esta no intervalo correcto End if
Valor=Mid(Valor,Pos+1,Len(Valor)-Pos+1) 'Fica-se com os minutos e segundos
Pos=InStr(Valor,":") Aux=(len(valor)<=5 and len(valor)>=1) 'Verifica-se se o tamanho e o separador (:) estao bem If Pos=0 Then m=Mid(Valor,1,Len(Valor)) Else m=Mid(Valor,1,Pos-1) End if
If IsNumeric(m) Then 'Captura-se os minutos m=Cint(m) Aux=(m>=0 And m<=59) 'Verifica-se se esta no intervalo correcto Else Aux=False End if
Pos=InStr(Valor,":") Valor=Mid(Valor,Pos+1,Len(Valor)-Pos+1) 'Fica-se com os segundos If Pos>0 Then 'Entao, ainda ha os segundos para verificar.... Pos=InStr(Valor,":") Aux=(len(valor)<=2) 'Verifica-se se o tamanho e o separador (:) estao bem If Pos=0 Then s=Mid(Valor,1,Len(Valor)) Else s=Mid(Valor,1,Pos-1) End if
If IsNumeric(s) Then 'Captura-se os minutos s=Cint(s) Aux=(s>=0 And s<=59) 'Verifica-se se esta no intervalo correcto Else Aux=False End if Else s=0 End if
IsTime=Aux
'Esta linha e' opcional e apenas serve para reconverter o valor para o formato desejado. GetCTime devera ser Global If aux Then GetCTime=h & ":" & m & ":" & s
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.