How to get rid of Option Base 1

wolflow

New Member
Joined
Apr 23, 2015
Messages
13
How can I get "Option Base 1" out of Module and into function "Date_Hijri_Greg"
I tried some things with Lbound and Ubound but was unscuccesful
Perferably I'd like the isLeapH(N) into function "Date_Hijri_Greg" as well leaving only one function


Option Base 1

Public Function isLeapH(N) As Boolean
isLeapH = (N = 3 Or N = 5 Or N = 8)
End Function

Public Function Date_Hijri_Greg(hdat As String) As Date

hdat = "10/1/1437"
' Result should be 5 July 2016

YearFinder = Array(354, 708, 1063, 1417, 1772, 2126, 2480, 2835)
MonthFinderL = Array(30, 59, 89, 118, 148, 177, 207, 236, 266, 296, 325, 355)
MonthFinder = Array(29, 59, 88, 118, 147, 177, 206, 236, 265, 295, 324, 354)
Cstart = CLng(#2/24/1906#) 'Corresponds to 1 Muharram 1324
Hstart = 1324
DCycle = 2835

'parse s to produce hmonth, hday, hyear
I = InStr(hdat, "/")
hmonth = CInt(Left(hdat, I - 1))
J = InStr(I + 1, hdat, "/")
hday = CInt(Mid(hdat, I + 1, J - I - 1))
Hyear = CInt(Right(hdat, Len(hdat) - J))
elapsed_years = Hyear - Hstart
ncycles = elapsed_years \ 8
nyear = elapsed_years Mod 8
If nyear = 0 Then
days_thiscycle = 0
Else
days_thiscycle = YearFinder(nyear)
End If
leap = isLeapH(nyear)
If hmonth = 1 Then
days_thisyear = hday
Else
If leap Then
days_thisyear = MonthFinderL(hmonth - 1) + hday
Else
days_thisyear = MonthFinder(hmonth - 1) + hday
End If
End If
days_thiscycle = days_thiscycle + days_thisyear
Date_Hijri_Greg = Cstart - 1 + ncycles * DCycle + days_thiscycle

End Function
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
See if this yields the correct results, without the base 1 option:

Code:
Public Function Date_Hijri_Greg(hdat$) As Date
'hdat = "10/1/1437"
' Result should be 5 July 2016
yearfinder = Array(354, 708, 1063, 1417, 1772, 2126, 2480, 2835)
MonthFinderL = Array(30, 59, 89, 118, 148, 177, 207, 236, 266, 296, 325, 355)
MonthFinder = Array(29, 59, 88, 118, 147, 177, 206, 236, 265, 295, 324, 354)
Cstart = CLng(#2/24/1906#) 'Corresponds to 1 Muharram 1324
Hstart = 1324
DCycle = 2835
'parse s to produce hmonth, hday, hyear
i = InStr(hdat, "/")
hmonth = CInt(Left(hdat, i - 1))
j = InStr(i + 1, hdat, "/")
hday = CInt(Mid(hdat, i + 1, j - i - 1))
Hyear = CInt(Right(hdat, Len(hdat) - j))
elapsed_years = Hyear - Hstart
ncycles = elapsed_years \ 8
nyear = elapsed_years Mod 8
If nyear = 0 Then
    days_thiscycle = 0
Else
    days_thiscycle = yearfinder(nyear - 1)
End If
If nyear = 4 Or nyear = 6 Or nyear = 9 Then leap = True
If hmonth = 1 Then
    days_thisyear = hday
Else
    If leap Then
        days_thisyear = MonthFinderL(hmonth - 2) + hday
    Else
        days_thisyear = MonthFinder(hmonth - 2) + hday
    End If
End If
days_thiscycle = days_thiscycle + days_thisyear
Date_Hijri_Greg = Cstart - 1 + ncycles * DCycle + days_thiscycle
End Function
 
Upvote 0

Forum statistics

Threads
1,215,348
Messages
6,124,425
Members
449,157
Latest member
mytux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top