Code:
Private Function DatumIzJMBG() As Variant
Dim strYear As String
Dim strMonth As String
Dim strDay As String
strYear = Mid(Text1.Text, 5, 3)
strMonth = Mid(Text1.Text, 3, 2)
strDay = Mid(Text1.Text, 1, 2)
'Inicijalno je null, moze koristiti za proveru da li je JMBG ispravan
'ako se sklone Msgbox obavestenja
DatumIzJMBG = Null
'Provera tipa
If IsNumeric(strYear) And IsNumeric(strMonth) And IsNumeric(strDay) Then
'provera i dopuna zbog veka
If CInt(strYear) > 100 Then
strYear = "1" & strYear
Else
strYear = "2" & strYear
End If
DatumIzJMBG = DateSerial(CInt(strYear), CInt(strMonth), CInt(strDay))
Else
MsgBox "Datum u JMBG je nepotpun ili sadrzi neipravne karaktere!"
End If
'Kontrola samog datuma koji je upisan
If (Year(DatumIzJMBG) <> CInt(strYear)) Or (Month(DatumIzJMBG) <> CInt(strMonth)) Or (Day(DatumIzJMBG) <> CInt(strDay)) Then
MsgBox "Datum u JMBG ima nemogucu vrednost za dan ili mesec ili godinu!"
End If
End Function
Naravno, pretpostavio sam da imas upisan JMBG u neki TextBox pod imenom "Text1". Zadnje poredjenje se oslanja na osobinu DateSerial funkcije da u slucaju nekorektnog datuma ispravi datum na prvi moguci (slobodno interpretirano).
[Ovu poruku je menjao goranvuc dana 29.01.2007. u 17:14 GMT+1]