اذهب الي المحتوي
أوفيسنا
بحث مخصص من جوجل فى أوفيسنا
Custom Search

الردود الموصى بها

قام بنشر (معدل)

تقومان بفحص تقويم الـ vba ونوع المدخل، فهي تساعد المستخدم كثيرا وتجنبه الأخطاء إن شاء الله.
عملت تجاربي عليها، ويمكنكم اجراء المزيد من التجارب.
 

Option Compare Database
Option Explicit

Function Greg2Hijri(GregDate As Variant, _
           Optional dFormat As String = "yyyy/mm/dd") As Variant
    Dim CurCal As VbCalendar
    
    On Error Resume Next
    
    CurCal = Calendar
    Greg2Hijri = Null   '"WrongInput"
    
    If Calendar = vbCalGreg And (VarType(GregDate) = vbDate Or _
                                 VarType(GregDate) = vbLong) Then
        Calendar = vbCalHijri
        Greg2Hijri = Format(GregDate, dFormat)
    ElseIf VarType(GregDate) = vbString Then
        Calendar = vbCalGreg
        If IsDate(GregDate) Then
            Greg2Hijri = CDate(GregDate)
        End If
    End If
    
    Calendar = CurCal
End Function
'-------------------------

Function Hijri2Greg(HijriDate As Variant, _
           Optional dFormat As String = "yyyy/mm/dd") As Variant
    Dim CurCal As VbCalendar
    
    On Error Resume Next
    
    CurCal = Calendar
    Hijri2Greg = Null   '"WrongInput"
    
    If Calendar = vbCalHijri And (VarType(HijriDate) = vbDate Or _
                                  VarType(HijriDate) = vbLong) Then
        Calendar = vbCalGreg
        Hijri2Greg = Format(HijriDate, dFormat)
    ElseIf VarType(HijriDate) = vbString Then
        Calendar = vbCalHijri
        If IsDate(HijriDate) Then
            Hijri2Greg = CDate(HijriDate)
        End If
    End If
    
    Calendar = CurCal
End Function
'--------------------------------------------------------------------

Sub TestingDateConverting()
    Dim CurCal As VbCalendar
    CurCal = Calendar
    
    Debug.Print "Greg2Hijri"
    Calendar = vbCalGreg
    Debug.Print Greg2Hijri(Date, "yyyy-mmmm-dd")
    Debug.Print Greg2Hijri(CLng(Date), "yyyy mm dd")
    Debug.Print Greg2Hijri("06/07/2023")
    Debug.Print "-----------"
    
    Calendar = vbCalHijri
    Debug.Print Greg2Hijri(Date, "yyyy-mmmm-dd")
    Debug.Print Greg2Hijri(CLng(Date), "yyyy mm dd")
    Debug.Print Greg2Hijri("06/07/2023")
    Debug.Print "-------------------------------"

    
    Debug.Print "Hijri2Greg"
    Calendar = vbCalHijri
    Debug.Print Hijri2Greg(Date, "yyyy-mmmm-dd")
    Debug.Print Hijri2Greg(CLng(Date), "yyyy mm dd")
    Debug.Print Hijri2Greg("18/12/1444")
    Debug.Print "-----------"
    
    Calendar = vbCalGreg
    Debug.Print Hijri2Greg(Date, "yyyy-mmmm-dd")
    Debug.Print Hijri2Greg(CLng(Date), "yyyy mm dd")
    Debug.Print Hijri2Greg("18/12/1444")
    Debug.Print "-------------------------------"
    
    Calendar = CurCal
End Sub

 

تم تعديل بواسطه AbuuAhmed
تنقيح الكود
  • Like 3
  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

زائر
اضف رد علي هذا الموضوع....

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • اضف...

Important Information