אופיס 365 פונקציה להמרת תאריך לועזי לעברי ולהיפך באקסס

FullTime

משתמש מקצוען
יש למישהו כזה קוד?

יש 2 פקדים אחד עברי ואחד לועזי ואני רוצה שאחד יעדכן את השני אחרי העדכון.


כמובן שמדובר בטופס מאוגד.
 

Rרחמים

משתמש סופר מקצוען
עיצוב גרפי
איור וציור מקצועי
מוזיקה ונגינה
עריכה תורנית
D I G I T A L
עימוד ספרים
הנה קוד מכאן:

קוד:
Option Explicit



 ' This code demonstrates how to convert a Hebrew date into a
 ' Gregorian date. The code is written in VB6/VBA, but I purposely
 ' used very generic features so it would be easy to translate
 ' this into other languages. Also, I avoided using many
 ' optimization in order to make the logic clearer.

 ' These functions assume that all the current rules of the
 ' Hebrew calendar were always in existence (which is not true
 ' since the Hebrew calendar was not always fixed) and all the
 ' current rules of the Gregorian calendar were always in existence
 ' (which is not true).

 ' Here is a very brief description of the Hebrew calendar.
 '
 ' The Hebrew calendar is a lunisolar calendar.  This means that
 ' the months are in sync with the moon and the years stay in sync
 ' with the sun.  A solar year is approximately 365.25 days.  A
 ' lunar month is approximately 29.5 days.  Twelve lunar months is
 ' approximately 354 days (12 * 29.5=354).  Thus, a lunar year of
 ' twelve months is 11.25 days shorter than the solar year. To make
 ' up for this shortfall, the Hebrew calendar adds a thirteenth
 ' month to seven years over a nineteen year period. Therefore, over
 ' a nineteen year period, the Hebrew calendar is approximately the
 ' same length as a nineteen year solar calendar.
 '
 ' In order to understand this code, you must know the following
 ' terms:
 '   Molad - new moon. Hebrew months start around the day of the
 '           new moon
 '   Chalakim - 1 / 1080 of an hour or 3 1/3 seconds
 '   Tishrei - the first month of the Hebrew year (at least for
 '             these calculations)
 '   Rosh Hashanah - The Jewish new year which starts on Tishrei 1.
 '
 ' The Hebrew calendar assumes the period of time between one new
 ' moon to the next is 29 days, 12 hours and 793 chalakim. The first
 ' molad after creation occurred on Monday, September, 7th -3760 at 5
 ' hours and 204 chalakim.  Technically, the Gregorian date would be
 ' in the year 3761 BCE because there was no year 0 in the Gregorian
 ' calendar, but we will use the year of -3760.

 ' Sample Usage:
 '    ' Converts AdarB/7/5765 to 4/6/2005
 '    MsgBox(HebToGreg(5765, 7, 26))
 '

 ' This function returns how many months there has been from the
 ' first Molad until the beginning of the year nYearH
Public Function MonSinceFirstMolad(ByVal nYearH As Long) As Long
    Dim nMonSinceFirstMolad As Long

  ' A shortcut to this function can simply be the following formula
  '   Return Int(((235 * nYearH) - 234) / 19)
  ' This formula is found in Remy Landau's website and he
  ' attributes it to Wolfgang Alexander Shochen. I will use a less
  ' optimized function which I believe shows the underlying logic
  ' better.

  ' count how many months there has been in all years up to last
  ' year. The months of this year hasn't happened yet.
  nYearH = nYearH - 1

 
  ' In the 19 year cycle, there will always be 235 months. That
  ' would be 19 years times 12 months plus 7 extra month for the
  ' leap years. (19 * 12) + 7 = 235.

  ' Get how many 19 year cycles there has been and multiply it by
  ' 235

  nMonSinceFirstMolad = Int(nYearH / 19) * 235

  ' Get the remaining years after the last complete 19 year cycle

  nYearH = nYearH Mod 19

  ' Add 12 months for each of those years

  nMonSinceFirstMolad = nMonSinceFirstMolad + (12 * nYearH)

  ' Add the extra months to account for the leap years

  If nYearH >= 17 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 6
  ElseIf nYearH >= 14 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 5
  ElseIf nYearH >= 11 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 4
  ElseIf nYearH >= 8 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 3
  ElseIf nYearH >= 6 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 2
  ElseIf nYearH >= 3 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 1
  End If
 MonSinceFirstMolad = nMonSinceFirstMolad
End Function


 ' This function returns if a given year is a leap year.

Public Function IsLeapYear(ByVal nYearH As Long) As Boolean
  Dim nYearInCycle As Long


  ' Find out which year we are within the cycle.  The 19th year of
  ' the cycle will return 0

  nYearInCycle = nYearH Mod 19
  IsLeapYear = nYearInCycle = 3 Or _
               nYearInCycle = 6 Or _
               nYearInCycle = 8 Or _
               nYearInCycle = 11 Or _
               nYearInCycle = 14 Or _
               nYearInCycle = 17 Or _
               nYearInCycle = 0
End Function


 ' This function figures out the Gregorian Date that corresponds to
 ' the first day of Tishrei, the first month of the Hebrew
 ' calendar, for a given Hebrew year.

Public Function Tishrei1(ByVal nYearH As Long) As Date
  Dim nMonthsSinceFirstMolad As Long
  Dim nChalakim As Long
  Dim nHours As Long
  Dim nDays As Long
  Dim nDayOfWeek As Long
  Dim dTishrei1 As Date


  ' We want to calculate how many days, hours and chalakim it has
  ' been from the time of 0 days, 0 hours and 0 chalakim to the
  ' molad at the beginning of year nYearH.
  '
  ' The period between one new moon to the next is 29 days, 12
  ' hours and 793 chalakim. We must multiply that by the amount
  ' of months that transpired since the first molad. Then we add
  ' the time of the first molad (Monday, 5 hours and 204 chalakim)

  nMonthsSinceFirstMolad = MonSinceFirstMolad(nYearH)
 nChalakim = 793 * nMonthsSinceFirstMolad
  nChalakim = nChalakim + 204

  ' carry the excess Chalakim over to the hours

  nHours = Int(nChalakim / 1080)
  nChalakim = nChalakim Mod 1080

  nHours = nHours + (nMonthsSinceFirstMolad * 12)
  nHours = nHours + 5

  ' carry the excess hours over to the days

  nDays = Int(nHours / 24)
  nHours = nHours Mod 24

  nDays = nDays + (29 * nMonthsSinceFirstMolad)
  nDays = nDays + 2


  ' figure out which day of the week the molad occurs.
  ' Sunday = 1, Moday = 2 ..., Shabbos = 0

  nDayOfWeek = nDays Mod 7


  ' In a perfect world, Rosh Hashanah would be on the day of the
  ' molad. The Hebrew calendar makes four exceptions where we
  ' push off Rosh Hashanah one or two days. This is done to
  ' prevent three situation. Without explaining why, the three
  ' situations are:
  '   1) We don't want Rosh Hashanah to come out on Sunday,
  '      Wednesday or Friday
  '   2) We don't want Rosh Hashanah to be on the day of the
  '      molad if the molad occurs after the beginning of 18th
  '      hour.
  '   3) We want to limit years to specific lengths.  For non-leap
  '      years, we limit it to either 353, 354 or 355 days.  For
  '      leap years, we limit it to either 383, 384 or 385 days.
  '      If setting Rosh Hashanah to the day of the molad will
  '      cause this year, or the previous year to fall outside
  '      these lengths, we push off Rosh Hashanah to get the year
  '      back to a valid length.
  ' This code handles these exceptions.


  If Not IsLeapYear(nYearH) And _
     nDayOfWeek = 3 And _
     (nHours * 1080) + nChalakim >= _
     (9 * 1080) + 204 Then

    ' This prevents the year from being 356 days. We have to push
    ' Rosh Hashanah off two days because if we pushed it off only
    ' one day, Rosh Hashanah would comes out on a Wednesday. Check
    ' the Hebrew year 5745 for an example.

    nDayOfWeek = 5
    nDays = nDays + 2
  ElseIf IsLeapYear(nYearH - 1) And _
         nDayOfWeek = 2 And _
         (nHours * 1080) + nChalakim >= _
         (15 * 1080) + 589 Then

    ' This prevents the previous year from being 382 days. Check
    ' the Hebrew Year 5766 for an example. If Rosh Hashanah was not
    ' pushed off a day then 5765 would be 382 days

    nDayOfWeek = 3
    nDays = nDays + 1
  Else

    ' see rule 2 above. Check the Hebrew year 5765 for an example

    If nHours >= 18 Then
      nDayOfWeek = nDayOfWeek + 1
      nDayOfWeek = nDayOfWeek Mod 7
      nDays = nDays + 1
    End If

    ' see rule 1 above. Check the Hebrew year 5765 for an example

    If nDayOfWeek = 1 Or _
       nDayOfWeek = 4 Or _
       nDayOfWeek = 6 Then
      nDayOfWeek = nDayOfWeek + 1
      nDayOfWeek = nDayOfWeek Mod 7
      nDays = nDays + 1
    End If
  End If


  ' Here we want to add nDays to creation
  '    dTishrie1 = creation + nDays
  ' Unfortunately, VB doesn't handle negative years very well.
  ' I therefore picked a Random date (1/1/1900) and figured out how
  ' many days it is after the creation (2067025). Then I subtracted
  ' 2067025 from nDays.

  nDays = nDays - 2067025
  dTishrei1 = #1/1/1900#
 ' 2067025 days after creation
 dTishrei1 = dTishrei1 + nDays
 Tishrei1 = dTishrei1
End Function


 ' This function gets the length of a Hebrew year.

Public Function LengthOfYear(ByVal nYearH As Long) As Long
  Dim dThisTishrei1 As Date
  Dim dNextTishrei1 As Date
  Dim diff As Long


  ' subtract the date of this year from the date of next year

  dThisTishrei1 = Tishrei1(nYearH)
  dNextTishrei1 = Tishrei1(nYearH + 1)
 diff = dNextTishrei1 - dThisTishrei1
 LengthOfYear = diff
End Function


 ' This function converts a Hebrew date into the Gregorian date
 ' nYearH - is the Hebrew year
 ' nMonth - Tishrei=1
 '          Cheshvon=2
 '          Kislev=3
 '          Teyvet=4
 '          Shevat=5
 '          Adar A=6 (only valid on leap years)
 '          Adar=7   (Adar B for leap years)
 '          Nison=8
 '          Iyar=9
 '          Sivan=10
 '          Tamuz=11
 '          Av=12
 '          Elul=13

Public Function HebToGreg(ByVal nYearH As Long, _
                          ByVal nMonthH As Long, _
                          ByVal nDateH As Long) As Date
                          
  Dim nLengthOfYear As Long
  Dim bLeap As Boolean
  Dim dGreg As Date
  Dim nMonth As Long
  Dim nMonthLen As Long
  Dim bHaser As Boolean
  Dim bShalem As Boolean

  bLeap = IsLeapYear(nYearH)
  nLengthOfYear = LengthOfYear(nYearH)


  ' The regular length of a non-leap year is 354 days.
  ' The regular length of a leap year is 384 days.
  ' On regular years, the length of the months are as follows
  '   Tishrei (1)   30
  '   Cheshvon(2)   29
  '   Kislev  (3)   30
  '   Teyvet  (4)   29
  '   Shevat  (5)   30
  '   Adar A  (6)   30     (only valid on leap years)
  '   Adar    (7)   29     (Adar B for leap years)
  '   Nison   (8)   30
  '   Iyar    (9)   29
  '   Sivan   (10)  30
  '   Tamuz   (11)  29
  '   Av      (12)  30
  '   Elul    (13)  29
  ' If the year is shorter by one less day, it is called a haser
  ' year. Kislev on a haser year has 29 days. If the year is longer
  ' by one day, it is called a shalem year. Cheshvon on a shalem
  ' year is 30 days.

  bHaser = nLengthOfYear = 353 Or nLengthOfYear = 383
  bShalem = nLengthOfYear = 355 Or nLengthOfYear = 385

  ' get the date for Tishrei 1

  dGreg = Tishrei1(nYearH)
  ' Now count up days within the year

  For nMonth = 1 To nMonthH - 1
    Select Case nMonth
      Case 1, 5, 8, 10, 12 ' 30 day months
        nMonthLen = 30
      Case 4, 7, 9, 11, 13 ' 29 day months
        nMonthLen = 29
      Case 6 ' There is only an Adar A on a leap years
        nMonthLen = IIf(bLeap, 30, 0)
      Case 2 ' Cheshvon, see note above
        nMonthLen = IIf(bShalem, 30, 29)
      Case 3 ' Kislev, see note above
        nMonthLen = IIf(bHaser, 29, 30)
    End Select
 dGreg = dGreg + nMonthLen
  Next
  dGreg = dGreg + (nDateH - 1)
 HebToGreg = dGreg
End Function


 ' This function converts a Gregorian date into the Hebrew date.  The
 ' function returns the hebrew month as a string in the format MM/DD/YYYY.
 ' Also, the parameters nYearH, nMonthH and hDateH, which are sent by
 ' reference, will get set the Hebrew year, month and date. See function
 ' HebToGreg() for the definition of the month numbers.

Public Function GregToHeb(ByVal dGreg As Date, _
                          ByRef nYearH As Long, _
                          ByRef nMonthH As Long, _
                          ByRef nDateH As Long) As String
                          
  Dim nOneMolad As Double
  Dim nAvrgYear As Double
  Dim nDays As Long
  Dim dTishrei1 As Date
  Dim nLengthOfYear As Long
  Dim bLeap As Boolean
  Dim bHaser As Boolean
  Dim bShalem As Boolean
  Dim nMonthLen As Long
  Dim bWhile As Boolean


  ' The basic algorythm to get Hebrew date for the Gregorian date dGreg.
  ' 1) Find out how many days dGreg is after creation.
  ' 2) Based on those days, estimate the Hebrew year
  ' 3) Now that we a good estimate of the Hebrew year, use brute force to
  '    find the Gregorian date for Tishrei 1 prior to or equal to dGreg
  ' 4) Add to Tishrei 1 the amount of days dGreg is after Tishrei 1

  ' Figure out how many days are in a month.
  ' 29 days + 12 hours + 793 chalakim

  nOneMolad = 29 + (12 / 24) + (793 / (1080 * 24))

  ' Figure out the average length of a year. The hebrew year has exactly
  ' 235 months over 19 years.

  nAvrgYear = nOneMolad * (235 / 19)

  ' Get how many days dGreg is after creation. See note as to why I
  ' use 1/1/1900 and add 2067025

  nDays = dGreg - #1/1/1900#
 nDays = nDays + 2067025  ' 2067025 days after creation
  ' Guess the Hebrew year. This should be a pretty accurate guess.

  nYearH = Int(CDbl(nDays) / nAvrgYear) + 1

  ' Use brute force to find the exact year nYearH. It is the Tishrei 1 in
  ' the year <= dGreg.

  dTishrei1 = Tishrei1(nYearH)
  If dTishrei1 = dGreg Then

    ' If we got lucky and landed on the exact date, we can stop here

    nMonthH = 1
    nDateH = 1
  Else

    ' Here is the brute force.  Either count up or count down nYearH
    ' until Tishrei 1 is <= dGreg.

    If dTishrei1 < dGreg Then

      ' If Tishrei 1, nYearH is less than dGreg, count nYearH up.

      Do While Tishrei1(nYearH + 1) <= dGreg
        nYearH = nYearH + 1
      Loop
    Else

      ' If Tishrei 1, nYearH is greater than dGreg, count nYearH down.

      nYearH = nYearH - 1
      Do While Tishrei1(nYearH) > dGreg
        nYearH = nYearH - 1
      Loop
    End If


    ' Subtract Tishrei 1, nYearH from dGreg. That should leave us with
    ' how many days we have to add to Tishrei 1

    nDays = dGreg - Tishrei1(nYearH)


    ' Find out what type of year it is so that we know the length of the
    ' months

    nLengthOfYear = LengthOfYear(nYearH)
    bHaser = nLengthOfYear = 353 Or nLengthOfYear = 383
    bShalem = nLengthOfYear = 355 Or nLengthOfYear = 385
    bLeap = IsLeapYear(nYearH)


    ' Add nDays to Tishrei 1.

    nMonthH = 1
    Do
      Select Case nMonthH
        Case 1, 5, 8, 10, 12 ' 30 day months
          nMonthLen = 30
        Case 4, 7, 9, 11, 13 ' 29 day months
          nMonthLen = 29
        Case 6 ' Adar A (6) will be skipped on non-leap years
          nMonthLen = 30
        Case 2 ' Cheshvon, see note above
          nMonthLen = IIf(bShalem, 30, 29)
        Case 3 ' Kislev, see note above
          nMonthLen = IIf(bHaser, 29, 30)
      End Select
      If nDays >= nMonthLen Then
 bWhile = True
        If bLeap Or nMonthH <> 5 Then
          nMonthH = nMonthH + 1
        Else

          ' We can skip Adar A (6) if its not a leap year

          nMonthH = nMonthH + 2
        End If
 nDays = nDays - nMonthLen
      Else
 bWhile = False
      End If
    Loop While bWhile

    ' Add the remaining days to Date

    nDateH = nDays + 1
  End If
  GregToHeb = CStr(nMonthH) & "/" & CStr(nDateH) & "/" & CStr(nYearH)
End Function

Public Function FormatDateH(nYearH, nMonthH, nDateH)
  Dim sMonth As String
  Select Case nMonthH
    Case 1
      sMonth = "תשרי"
    Case 2
      sMonth = "חשוון"
    Case 3
      sMonth = "כסלו"
    Case 4
      sMonth = "טבת"
    Case 5
      sMonth = "שבט"
    Case 6
      sMonth = "אדר א'"
    Case 7
      sMonth = IIf(IsLeapYear(nYearH), "אדר ב'", "אדר")
    Case 8
      sMonth = "ניסן"
    Case 9
      sMonth = "אייר"
    Case 10
      sMonth = "סיוון"
    Case 11
      sMonth = "תמוז"
    Case 12
      sMonth = "אב"
    Case 13
      sMonth = "אלול"
  End Select
  FormatDateH = CStr(HebrewNum(nDateH)) _
  & " " & sMonth & " " & CStr(HebrewNum(nYearH))
End Function

Public Function TodayHeb()
  Dim nYearH As Long
  Dim nMonthH As Long
  Dim nDateH As Long
  Dim dToday As Date
 
  dToday = Int(Now())
  GregToHeb dToday, nYearH, nMonthH, nDateH
  TodayHeb = FormatDateH(nYearH, nMonthH, nDateH)
End Function

Public Function DateToHeb(dDate)
  Dim nYearH As Long
  Dim nMonthH As Long
  Dim nDateH As Long
 
  dDate = CDate(dDate)
  GregToHeb dDate, nYearH, nMonthH, nDateH
  DateToHeb = FormatDateH(nYearH, nMonthH, nDateH)
End Function



Function HebrewNum(ByVal n As Integer)
  Dim nX As Integer
  Dim sHundred As String
  Dim sTen As String
  Dim sOne As String
 
  n = n Mod 1000
  nX = n - (n Mod 100)
  Select Case nX
    Case 900
      sHundred = Tuf_() & Tuf_() & Raish_()
    Case 800
      sHundred = Tuf_() & Tuf_() & Kuf_()
    Case 700
      sHundred = Tuf_() & Shin_()
    Case 600
      sHundred = Tuf_() & Raish_()
    Case 500
      sHundred = Tuf_() & Kuf_()
    Case 400
      sHundred = Tuf_()
    Case 300
      sHundred = Shin_()
    Case 200
      sHundred = Raish_()
    Case 100
      sHundred = Kuf_()
  End Select
 n = n - nX
  If n = 15 Then
    sTen = Tes_()
    sOne = Vav_()
  ElseIf n = 16 Then
    sTen = Tes_()
    sOne = Ziyon_()
  Else
    nX = n - (n Mod 10)
    Select Case nX
      Case 90
        sTen = Tzodi_()
      Case 80
        sTen = Pai_()
      Case 70
        sTen = Iyin_()
      Case 60
        sTen = Samech_()
      Case 50
        sTen = Nun_()
      Case 40
        sTen = Mem_()
      Case 30
        sTen = Lamed_()
      Case 20
        sTen = Chaf_()
      Case 10
        sTen = Yud_()
    End Select
 nX = n - nX
    Select Case nX
      Case 9
        sOne = Tes_()
      Case 8
        sOne = Ches_()
      Case 7
        sOne = Ziyon_()
      Case 6
        sOne = Vav_()
      Case 5
        sOne = Hai_()
      Case 4
        sOne = Daled_()
      Case 3
        sOne = Gimmel_()
      Case 2
        sOne = Bais_()
      Case 1
        sOne = Alef_()
    End Select
  End If
 
 HebrewNum = sHundred & sTen & sOne
End Function

Public Function FormatDateHInHeb(nYearH, nMonthH, nDateH)
  Dim sMonth As String
  Select Case nMonthH
    Case 1
      sMonth = Tuf_() & Shin_() & Raish_() & Yud_()
    Case 2
      sMonth = Ches_() & Shin_() & Vav_() & Nun_End_()
    Case 3
      sMonth = Chaf_() & Samech_() & Lamed_() & Yud_() & Vav_()
    Case 4
      sMonth = Tes_() & Bais_() & Tuf_()
    Case 5
      sMonth = Shin_() & Bais_() & Tes_()
    Case 6
      sMonth = Alef_() & Daled_() & Raish_() & ChrW(32) & Alef_()
    Case 7
      sMonth = IIf(IsLeapYear(nYearH), _
                     Alef_() & Daled_() & Raish_() & ChrW(32) & Bais_(), _
                     Alef_() & Daled_() & Raish_())
    Case 8
      sMonth = Nun_() & Yud_() & Samech_() & Nun_End_()
    Case 9
      sMonth = Alef_() & Yud_() & Yud_() & Raish_()
    Case 10
      sMonth = Samech_() & Yud_() & Vav_() & Nun_End_()
    Case 11
      sMonth = Tuf_() & Mem_() & Vav_() & Ziyon_()
    Case 12
      sMonth = Alef_() & Bais_()
    Case 13
      sMonth = Alef_() & Lamed_() & Vav_() & Lamed_()
  End Select
  FormatDateHInHeb = sMonth & " " & HebrewNum(nDateH) & " " & CStr(nYearH)
 
  ' FormatDateHInHeb = sMonth & " " & HebrewNum(nDateH) & " " & HebrewNum(nYearH)
 
 
End Function


Public Function HebDateInHeb(dDate)
  Dim nYearH As Long
  Dim nMonthH As Long
  Dim nDateH As Long
 
  dDate = CDate(dDate)
  GregToHeb dDate, nYearH, nMonthH, nDateH
  HebDateInHeb = FormatDateHInHeb(nYearH, nMonthH, nDateH)
End Function

Function Alef_()
  Alef_ = ChrW(1488)
End Function

Function Bais_()
  Bais_ = ChrW(1489)
End Function

Function Gimmel_()
  Gimmel_ = ChrW(1490)
End Function

Function Daled_()
  Daled_ = ChrW(1491)
End Function

Function Hai_()
  Hai_ = ChrW(1492)
End Function

Function Vav_()
  Vav_ = ChrW(1493)
End Function

Function Ziyon_()
  Ziyon_ = ChrW(1494)
End Function

Function Ches_()
  Ches_ = ChrW(1495)
End Function

Function Tes_()
  Tes_ = ChrW(1496)
End Function

Function Yud_()
  Yud_ = ChrW(1497)
End Function

Function Chaf_End_()
  Chaf_End_ = ChrW(1498)
End Function

Function Chaf_()
  Chaf_ = ChrW(1499)
End Function

Function Lamed_()
  Lamed_ = ChrW(1500)
End Function

Function Mem_End_()
  Mem_End_ = ChrW(1501)
End Function

Function Mem_()
Mem_ = ChrW(1502)
End Function

Function Nun_End_()
   Nun_End_ = ChrW(1503)
End Function

Function Nun_()
  Nun_ = ChrW(1504)
End Function

Function Samech_()
  Samech_ = ChrW(1505)
End Function

Function Iyin_()
  Iyin_ = ChrW(1506)
End Function

Function Pai_End_()
  Pai_End_ = ChrW(1507)
End Function

Function Pai_()
  Pai_ = ChrW(1508)
End Function

Function Tzodi_End_()
  Tzodi_End_ = ChrW(1509)
End Function

Function Tzodi_()
  Tzodi_ = ChrW(1510)
End Function

Function Kuf_()
  Kuf_ = ChrW(1511)
End Function

Function Raish_()
  Raish_ = ChrW(1512)
End Function

Function Shin_()
  Shin_ = ChrW(1513)
End Function

Function Tuf_()
  Tuf_ = ChrW(1514)
End Function

Function UnicodeChar(n As Integer)
  UnicodeChar = ChrW(n)
End Function


 ' Some handy code to help generate code

Public Sub MakeHebrewLet()
  Dim nRow As Integer
 Sheets.Add
  ActiveSheet.Name = "HebrewLet"
  For nRow = 1 To 27
    Cells(nRow, 1) = nRow + 1487
    Cells(nRow, 2) = ChrW(nRow + 1487)
    Select Case nRow
      Case 1
        Cells(nRow, 3) = "Alef"
      Case 2
        Cells(nRow, 3) = "Bais"
      Case 3
        Cells(nRow, 3) = "Gimmel"
      Case 4
        Cells(nRow, 3) = "Daled"
      Case 5
        Cells(nRow, 3) = "Hai"
      Case 6
        Cells(nRow, 3) = "Vav"
      Case 7
        Cells(nRow, 3) = "Ziyon"
      Case 8
        Cells(nRow, 3) = "Ches"
      Case 9
        Cells(nRow, 3) = "Tes"
      Case 10
        Cells(nRow, 3) = "Yud"
      Case 11
        Cells(nRow, 3) = "Chaf_End"
      Case 12
        Cells(nRow, 3) = "Chaf"
      Case 13
        Cells(nRow, 3) = "Lamed"
      Case 14
        Cells(nRow, 3) = "Mem_End"
      Case 15
        Cells(nRow, 3) = "Mem"
      Case 16
        Cells(nRow, 3) = "Nun_End"
      Case 17
        Cells(nRow, 3) = "Nun"
      Case 18
        Cells(nRow, 3) = "Samech"
      Case 19
        Cells(nRow, 3) = "Iyin"
      Case 20
        Cells(nRow, 3) = "Pai_End"
      Case 21
        Cells(nRow, 3) = "Pai"
      Case 22
        Cells(nRow, 3) = "Tzodi_End"
      Case 23
        Cells(nRow, 3) = "Tzodi"
      Case 24
        Cells(nRow, 3) = "Kuf"
      Case 25
        Cells(nRow, 3) = "Raish"
      Case 26
        Cells(nRow, 3) = "Shin"
      Case 27
        Cells(nRow, 3) = "Tuf"
    End Select
  Next
End Sub

Public Function HebSt(S As String)
  Dim n As Integer
 

  For n = 1 To Len(S)
    If n <> 1 Then
      HebSt = HebSt + " & "
    End If
    HebSt = HebSt + HebLetToFunc(Mid(S, n, 1))
  Next
End Function

Function HebLetToFunc(sHebLet As String) As String
  Dim nRow As Integer
  HebLetToFunc = "ChrW(" + CStr(AscW(sHebLet)) & ")"
  nRow = 1
  Do While Sheets("HebrewLet").Cells(nRow, 2) <> ""
    If Sheets("HebrewLet").Cells(nRow, 2) = sHebLet Then
      HebLetToFunc = Sheets("HebrewLet").Cells(nRow, 3) & "_()"
      Exit Do
    End If
    nRow = nRow + 1
  Loop
End Function
 

FullTime

משתמש מקצוען
נכתב ע"י Rרחמים;1045330:

תודה, הרעיון עבד לי.
עשיתי שתי פקדים ובאחד עשיתי מקור פקד =DateToHeb([תאריךלועזי])
וזה עבד.

עכשיו;
מה אני עושה כשאני רוצה שהוא יעדכן את התאריך לאחר עדכון התאריך הלועזי.
אני צריך לרשום קוד 'לאחר עדכון'? מה אני רושם שם?

כמו"כ להיפך מתאריך עברי שהוא ימיר ללועזי, לא מצאתי שם משהו. באם יש מה זה? וכנ"ל מה אני רושם לאחר עדכון?

תודה רבה רבה
 

Rרחמים

משתמש סופר מקצוען
עיצוב גרפי
איור וציור מקצועי
מוזיקה ונגינה
עריכה תורנית
D I G I T A L
עימוד ספרים
HebToGreg ממיר מעברי ללועזי
 

FullTime

משתמש מקצוען
נכתב ע"י Rרחמים;1045380:
HebToGreg ממיר מעברי ללועזי

הוא דורש 3 ארגמנטים.
פקד ליום - חודש - שנה. לא? ניסיתי את כל האפשרויות ולא הסתדר לי .

כמו"כ איך אני עושה שלאחר העדכון הוא יעדכן את זה, עם משתנה?
באם כן מה אני רושם?
ובאם לא, אז איך?

מדובר בטופס מאוגד, כך שמקור הפקד שייך לטבלה/שאילתה, ואני צריך שהוא יתעדכן
 

ayg

משתמש צעיר
עימוד ספרים
הוא דורש 3 ארגמנטים.
פקד ליום - חודש - שנה. לא? ניסיתי את כל האפשרויות ולא הסתדר לי .

ראה בקובץ אקסל המצורף הכל מפרוש בו
[הצרכתי להוסיף כמה פקודות להפוך תאריך עברי למספור - וכן פקודה שיבחין באלפים]
 

קבצים מצורפים

  • תאריך לתאריך.zip
    KB 48.6 · צפיות: 105

FullTime

משתמש מקצוען
נכתב ע"י ayg;1046112:
ראה בקובץ אקסל המצורף הכל מפרוש בו
[הצרכתי להוסיף כמה פקודות להפוך תאריך עברי למספור - וכן פקודה שיבחין באלפים]

הוא עובד רק לפני עדכון.
ברגע שאני מחליף תאריך עברי הוא מפסיק לעדכן.

כמו"כ אני צריך את זה לאקסס לא לאקסל
 

moishy

משתמש סופר מקצוען
מנוי פרימיום
בבקשה, ראה את המצורף.

ההמרה מתבצעת או לאחר עדכון אחד מתיבות הטקסט או ע"י לחיצה על הכפתור.
יש בו שני שיטות המרה, אחד מבוסס על הקוד שרחמים שיתף (בתוספת כמה פונקציות), והשני הוא הקוד שפורסם כבר באשכול אחר בזמן האחרון, וד"ל.
 

קבצים מצורפים

  • המרת תאריכים.rar
    KB 70.8 · צפיות: 121

FullTime

משתמש מקצוען
סתם נקודה למחשבה שראיתי עכשיו.
אני כבר לא רוצה שמוישי ישרוף לזה זמן.
הוא לא מטפל בשגיאות הקלדה, לדוגמא אם אני רושם מ' תמוז תשע"ג
הוא מחזיר את התאריך של י'א אב (בלועזי, את העברי הוא משאיר כך...... )
וכו'
רק למחשבה, מוישי, אל תטפל בזה בשבילי.........
 

Rרחמים

משתמש סופר מקצוען
עיצוב גרפי
איור וציור מקצועי
מוזיקה ונגינה
עריכה תורנית
D I G I T A L
עימוד ספרים
נכתב ע"י a26955;1047180:
תודה ענקית, עובד מצויין.

חן חן לך.

גם אני מצטרף!
מוישי תזכה למצוות!
 

HUBHCBH

משתמש מקצוען
אוטומציה עסקית
נכתב ע"י moishy;1047102:
בבקשה, ראה את המצורף.

ההמרה מתבצעת או לאחר עדכון אחד מתיבות הטקסט או ע"י לחיצה על הכפתור.
יש בו שני שיטות המרה, אחד מבוסס על הקוד שרחמים שיתף (בתוספת כמה פונקציות), והשני הוא הקוד שפורסם כבר באשכול אחר בזמן האחרון, וד"ל.

עובד מצוין!!
 

vn453

משתמש חדש
מצ"ב תכנה חינמית בעלת ממשק משתמש יפה, ממירה תאריך עברי ללועזי וגם תאריך לועזי לעברי.
התכנה גם מאפשרת להדפיס את התאריכים שהומרו.
התכנה נוצרה לחלונות 95/98/Me. מתאימה גם ל-xp.
אבל אם הנכם משתמשים ב-win7 - כדי להפעיל את התכנה יש תחילה ללחוץ על סמליל התכנה בלחצן ימני, לבחור "מאפיינים"-->"תאימות"-->לסמן תיבה סימון "הפעל תוכנית זו במצב תאימות עבור: Win98/Me".
ראו גם קישור זה: http://www.dr-vb.co.il/showcat.php?id=5&page=2
 

קבצים מצורפים

  • HebrewCalendar.zip
    1.1 MB · צפיות: 62

ayg

משתמש צעיר
עימוד ספרים
הקוד בVB

נכתב ע"י moishy;1047102:
בבקשה, ראה את המצורף.

ההמרה מתבצעת או לאחר עדכון אחד מתיבות הטקסט או ע"י לחיצה על הכפתור.
יש בו שני שיטות המרה, אחד מבוסס על הקוד שרחמים שיתף (בתוספת כמה פונקציות), והשני הוא הקוד שפורסם כבר באשכול אחר בזמן האחרון, וד"ל.

נפלא!!!
האם שייך שתעלה הקוד גם בשפת VB?
[הגדרת המשתנים בVB והשימוש בהם שונה מVBA, ואי אפשר להשתמש שם בקוד זה]
תודה מראש
 

bmkol

משתמש מקצוען
הנה קוד מכאן:

קוד:
Option Explicit



 ' This code demonstrates how to convert a Hebrew date into a
 ' Gregorian date. The code is written in VB6/VBA, but I purposely
 ' used very generic features so it would be easy to translate
 ' this into other languages. Also, I avoided using many
 ' optimization in order to make the logic clearer.

 ' These functions assume that all the current rules of the
 ' Hebrew calendar were always in existence (which is not true
 ' since the Hebrew calendar was not always fixed) and all the
 ' current rules of the Gregorian calendar were always in existence
 ' (which is not true).

 ' Here is a very brief description of the Hebrew calendar.
 '
 ' The Hebrew calendar is a lunisolar calendar.  This means that
 ' the months are in sync with the moon and the years stay in sync
 ' with the sun.  A solar year is approximately 365.25 days.  A
 ' lunar month is approximately 29.5 days.  Twelve lunar months is
 ' approximately 354 days (12 * 29.5=354).  Thus, a lunar year of
 ' twelve months is 11.25 days shorter than the solar year. To make
 ' up for this shortfall, the Hebrew calendar adds a thirteenth
 ' month to seven years over a nineteen year period. Therefore, over
 ' a nineteen year period, the Hebrew calendar is approximately the
 ' same length as a nineteen year solar calendar.
 '
 ' In order to understand this code, you must know the following
 ' terms:
 '   Molad - new moon. Hebrew months start around the day of the
 '           new moon
 '   Chalakim - 1 / 1080 of an hour or 3 1/3 seconds
 '   Tishrei - the first month of the Hebrew year (at least for
 '             these calculations)
 '   Rosh Hashanah - The Jewish new year which starts on Tishrei 1.
 '
 ' The Hebrew calendar assumes the period of time between one new
 ' moon to the next is 29 days, 12 hours and 793 chalakim. The first
 ' molad after creation occurred on Monday, September, 7th -3760 at 5
 ' hours and 204 chalakim.  Technically, the Gregorian date would be
 ' in the year 3761 BCE because there was no year 0 in the Gregorian
 ' calendar, but we will use the year of -3760.

 ' Sample Usage:
 '    ' Converts AdarB/7/5765 to 4/6/2005
 '    MsgBox(HebToGreg(5765, 7, 26))
 '

 ' This function returns how many months there has been from the
 ' first Molad until the beginning of the year nYearH
Public Function MonSinceFirstMolad(ByVal nYearH As Long) As Long
    Dim nMonSinceFirstMolad As Long

  ' A shortcut to this function can simply be the following formula
  '   Return Int(((235 * nYearH) - 234) / 19)
  ' This formula is found in Remy Landau's website and he
  ' attributes it to Wolfgang Alexander Shochen. I will use a less
  ' optimized function which I believe shows the underlying logic
  ' better.

  ' count how many months there has been in all years up to last
  ' year. The months of this year hasn't happened yet.
  nYearH = nYearH - 1

 
  ' In the 19 year cycle, there will always be 235 months. That
  ' would be 19 years times 12 months plus 7 extra month for the
  ' leap years. (19 * 12) + 7 = 235.

  ' Get how many 19 year cycles there has been and multiply it by
  ' 235

  nMonSinceFirstMolad = Int(nYearH / 19) * 235

  ' Get the remaining years after the last complete 19 year cycle

  nYearH = nYearH Mod 19

  ' Add 12 months for each of those years

  nMonSinceFirstMolad = nMonSinceFirstMolad + (12 * nYearH)

  ' Add the extra months to account for the leap years

  If nYearH >= 17 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 6
  ElseIf nYearH >= 14 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 5
  ElseIf nYearH >= 11 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 4
  ElseIf nYearH >= 8 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 3
  ElseIf nYearH >= 6 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 2
  ElseIf nYearH >= 3 Then
    nMonSinceFirstMolad = nMonSinceFirstMolad + 1
  End If
 MonSinceFirstMolad = nMonSinceFirstMolad
End Function


 ' This function returns if a given year is a leap year.

Public Function IsLeapYear(ByVal nYearH As Long) As Boolean
  Dim nYearInCycle As Long


  ' Find out which year we are within the cycle.  The 19th year of
  ' the cycle will return 0

  nYearInCycle = nYearH Mod 19
  IsLeapYear = nYearInCycle = 3 Or _
               nYearInCycle = 6 Or _
               nYearInCycle = 8 Or _
               nYearInCycle = 11 Or _
               nYearInCycle = 14 Or _
               nYearInCycle = 17 Or _
               nYearInCycle = 0
End Function


 ' This function figures out the Gregorian Date that corresponds to
 ' the first day of Tishrei, the first month of the Hebrew
 ' calendar, for a given Hebrew year.

Public Function Tishrei1(ByVal nYearH As Long) As Date
  Dim nMonthsSinceFirstMolad As Long
  Dim nChalakim As Long
  Dim nHours As Long
  Dim nDays As Long
  Dim nDayOfWeek As Long
  Dim dTishrei1 As Date


  ' We want to calculate how many days, hours and chalakim it has
  ' been from the time of 0 days, 0 hours and 0 chalakim to the
  ' molad at the beginning of year nYearH.
  '
  ' The period between one new moon to the next is 29 days, 12
  ' hours and 793 chalakim. We must multiply that by the amount
  ' of months that transpired since the first molad. Then we add
  ' the time of the first molad (Monday, 5 hours and 204 chalakim)

  nMonthsSinceFirstMolad = MonSinceFirstMolad(nYearH)
 nChalakim = 793 * nMonthsSinceFirstMolad
  nChalakim = nChalakim + 204

  ' carry the excess Chalakim over to the hours

  nHours = Int(nChalakim / 1080)
  nChalakim = nChalakim Mod 1080

  nHours = nHours + (nMonthsSinceFirstMolad * 12)
  nHours = nHours + 5

  ' carry the excess hours over to the days

  nDays = Int(nHours / 24)
  nHours = nHours Mod 24

  nDays = nDays + (29 * nMonthsSinceFirstMolad)
  nDays = nDays + 2


  ' figure out which day of the week the molad occurs.
  ' Sunday = 1, Moday = 2 ..., Shabbos = 0

  nDayOfWeek = nDays Mod 7


  ' In a perfect world, Rosh Hashanah would be on the day of the
  ' molad. The Hebrew calendar makes four exceptions where we
  ' push off Rosh Hashanah one or two days. This is done to
  ' prevent three situation. Without explaining why, the three
  ' situations are:
  '   1) We don't want Rosh Hashanah to come out on Sunday,
  '      Wednesday or Friday
  '   2) We don't want Rosh Hashanah to be on the day of the
  '      molad if the molad occurs after the beginning of 18th
  '      hour.
  '   3) We want to limit years to specific lengths.  For non-leap
  '      years, we limit it to either 353, 354 or 355 days.  For
  '      leap years, we limit it to either 383, 384 or 385 days.
  '      If setting Rosh Hashanah to the day of the molad will
  '      cause this year, or the previous year to fall outside
  '      these lengths, we push off Rosh Hashanah to get the year
  '      back to a valid length.
  ' This code handles these exceptions.


  If Not IsLeapYear(nYearH) And _
     nDayOfWeek = 3 And _
     (nHours * 1080) + nChalakim >= _
     (9 * 1080) + 204 Then

    ' This prevents the year from being 356 days. We have to push
    ' Rosh Hashanah off two days because if we pushed it off only
    ' one day, Rosh Hashanah would comes out on a Wednesday. Check
    ' the Hebrew year 5745 for an example.

    nDayOfWeek = 5
    nDays = nDays + 2
  ElseIf IsLeapYear(nYearH - 1) And _
         nDayOfWeek = 2 And _
         (nHours * 1080) + nChalakim >= _
         (15 * 1080) + 589 Then

    ' This prevents the previous year from being 382 days. Check
    ' the Hebrew Year 5766 for an example. If Rosh Hashanah was not
    ' pushed off a day then 5765 would be 382 days

    nDayOfWeek = 3
    nDays = nDays + 1
  Else

    ' see rule 2 above. Check the Hebrew year 5765 for an example

    If nHours >= 18 Then
      nDayOfWeek = nDayOfWeek + 1
      nDayOfWeek = nDayOfWeek Mod 7
      nDays = nDays + 1
    End If

    ' see rule 1 above. Check the Hebrew year 5765 for an example

    If nDayOfWeek = 1 Or _
       nDayOfWeek = 4 Or _
       nDayOfWeek = 6 Then
      nDayOfWeek = nDayOfWeek + 1
      nDayOfWeek = nDayOfWeek Mod 7
      nDays = nDays + 1
    End If
  End If


  ' Here we want to add nDays to creation
  '    dTishrie1 = creation + nDays
  ' Unfortunately, VB doesn't handle negative years very well.
  ' I therefore picked a Random date (1/1/1900) and figured out how
  ' many days it is after the creation (2067025). Then I subtracted
  ' 2067025 from nDays.

  nDays = nDays - 2067025
  dTishrei1 = #1/1/1900#
 ' 2067025 days after creation
 dTishrei1 = dTishrei1 + nDays
 Tishrei1 = dTishrei1
End Function


 ' This function gets the length of a Hebrew year.

Public Function LengthOfYear(ByVal nYearH As Long) As Long
  Dim dThisTishrei1 As Date
  Dim dNextTishrei1 As Date
  Dim diff As Long


  ' subtract the date of this year from the date of next year

  dThisTishrei1 = Tishrei1(nYearH)
  dNextTishrei1 = Tishrei1(nYearH + 1)
 diff = dNextTishrei1 - dThisTishrei1
 LengthOfYear = diff
End Function


 ' This function converts a Hebrew date into the Gregorian date
 ' nYearH - is the Hebrew year
 ' nMonth - Tishrei=1
 '          Cheshvon=2
 '          Kislev=3
 '          Teyvet=4
 '          Shevat=5
 '          Adar A=6 (only valid on leap years)
 '          Adar=7   (Adar B for leap years)
 '          Nison=8
 '          Iyar=9
 '          Sivan=10
 '          Tamuz=11
 '          Av=12
 '          Elul=13

Public Function HebToGreg(ByVal nYearH As Long, _
                          ByVal nMonthH As Long, _
                          ByVal nDateH As Long) As Date
                         
  Dim nLengthOfYear As Long
  Dim bLeap As Boolean
  Dim dGreg As Date
  Dim nMonth As Long
  Dim nMonthLen As Long
  Dim bHaser As Boolean
  Dim bShalem As Boolean

  bLeap = IsLeapYear(nYearH)
  nLengthOfYear = LengthOfYear(nYearH)


  ' The regular length of a non-leap year is 354 days.
  ' The regular length of a leap year is 384 days.
  ' On regular years, the length of the months are as follows
  '   Tishrei (1)   30
  '   Cheshvon(2)   29
  '   Kislev  (3)   30
  '   Teyvet  (4)   29
  '   Shevat  (5)   30
  '   Adar A  (6)   30     (only valid on leap years)
  '   Adar    (7)   29     (Adar B for leap years)
  '   Nison   (8)   30
  '   Iyar    (9)   29
  '   Sivan   (10)  30
  '   Tamuz   (11)  29
  '   Av      (12)  30
  '   Elul    (13)  29
  ' If the year is shorter by one less day, it is called a haser
  ' year. Kislev on a haser year has 29 days. If the year is longer
  ' by one day, it is called a shalem year. Cheshvon on a shalem
  ' year is 30 days.

  bHaser = nLengthOfYear = 353 Or nLengthOfYear = 383
  bShalem = nLengthOfYear = 355 Or nLengthOfYear = 385

  ' get the date for Tishrei 1

  dGreg = Tishrei1(nYearH)
  ' Now count up days within the year

  For nMonth = 1 To nMonthH - 1
    Select Case nMonth
      Case 1, 5, 8, 10, 12 ' 30 day months
        nMonthLen = 30
      Case 4, 7, 9, 11, 13 ' 29 day months
        nMonthLen = 29
      Case 6 ' There is only an Adar A on a leap years
        nMonthLen = IIf(bLeap, 30, 0)
      Case 2 ' Cheshvon, see note above
        nMonthLen = IIf(bShalem, 30, 29)
      Case 3 ' Kislev, see note above
        nMonthLen = IIf(bHaser, 29, 30)
    End Select
 dGreg = dGreg + nMonthLen
  Next
  dGreg = dGreg + (nDateH - 1)
 HebToGreg = dGreg
End Function


 ' This function converts a Gregorian date into the Hebrew date.  The
 ' function returns the hebrew month as a string in the format MM/DD/YYYY.
 ' Also, the parameters nYearH, nMonthH and hDateH, which are sent by
 ' reference, will get set the Hebrew year, month and date. See function
 ' HebToGreg() for the definition of the month numbers.

Public Function GregToHeb(ByVal dGreg As Date, _
                          ByRef nYearH As Long, _
                          ByRef nMonthH As Long, _
                          ByRef nDateH As Long) As String
                         
  Dim nOneMolad As Double
  Dim nAvrgYear As Double
  Dim nDays As Long
  Dim dTishrei1 As Date
  Dim nLengthOfYear As Long
  Dim bLeap As Boolean
  Dim bHaser As Boolean
  Dim bShalem As Boolean
  Dim nMonthLen As Long
  Dim bWhile As Boolean


  ' The basic algorythm to get Hebrew date for the Gregorian date dGreg.
  ' 1) Find out how many days dGreg is after creation.
  ' 2) Based on those days, estimate the Hebrew year
  ' 3) Now that we a good estimate of the Hebrew year, use brute force to
  '    find the Gregorian date for Tishrei 1 prior to or equal to dGreg
  ' 4) Add to Tishrei 1 the amount of days dGreg is after Tishrei 1

  ' Figure out how many days are in a month.
  ' 29 days + 12 hours + 793 chalakim

  nOneMolad = 29 + (12 / 24) + (793 / (1080 * 24))

  ' Figure out the average length of a year. The hebrew year has exactly
  ' 235 months over 19 years.

  nAvrgYear = nOneMolad * (235 / 19)

  ' Get how many days dGreg is after creation. See note as to why I
  ' use 1/1/1900 and add 2067025

  nDays = dGreg - #1/1/1900#
 nDays = nDays + 2067025  ' 2067025 days after creation
  ' Guess the Hebrew year. This should be a pretty accurate guess.

  nYearH = Int(CDbl(nDays) / nAvrgYear) + 1

  ' Use brute force to find the exact year nYearH. It is the Tishrei 1 in
  ' the year <= dGreg.

  dTishrei1 = Tishrei1(nYearH)
  If dTishrei1 = dGreg Then

    ' If we got lucky and landed on the exact date, we can stop here

    nMonthH = 1
    nDateH = 1
  Else

    ' Here is the brute force.  Either count up or count down nYearH
    ' until Tishrei 1 is <= dGreg.

    If dTishrei1 < dGreg Then

      ' If Tishrei 1, nYearH is less than dGreg, count nYearH up.

      Do While Tishrei1(nYearH + 1) <= dGreg
        nYearH = nYearH + 1
      Loop
    Else

      ' If Tishrei 1, nYearH is greater than dGreg, count nYearH down.

      nYearH = nYearH - 1
      Do While Tishrei1(nYearH) > dGreg
        nYearH = nYearH - 1
      Loop
    End If


    ' Subtract Tishrei 1, nYearH from dGreg. That should leave us with
    ' how many days we have to add to Tishrei 1

    nDays = dGreg - Tishrei1(nYearH)


    ' Find out what type of year it is so that we know the length of the
    ' months

    nLengthOfYear = LengthOfYear(nYearH)
    bHaser = nLengthOfYear = 353 Or nLengthOfYear = 383
    bShalem = nLengthOfYear = 355 Or nLengthOfYear = 385
    bLeap = IsLeapYear(nYearH)


    ' Add nDays to Tishrei 1.

    nMonthH = 1
    Do
      Select Case nMonthH
        Case 1, 5, 8, 10, 12 ' 30 day months
          nMonthLen = 30
        Case 4, 7, 9, 11, 13 ' 29 day months
          nMonthLen = 29
        Case 6 ' Adar A (6) will be skipped on non-leap years
          nMonthLen = 30
        Case 2 ' Cheshvon, see note above
          nMonthLen = IIf(bShalem, 30, 29)
        Case 3 ' Kislev, see note above
          nMonthLen = IIf(bHaser, 29, 30)
      End Select
      If nDays >= nMonthLen Then
 bWhile = True
        If bLeap Or nMonthH <> 5 Then
          nMonthH = nMonthH + 1
        Else

          ' We can skip Adar A (6) if its not a leap year

          nMonthH = nMonthH + 2
        End If
 nDays = nDays - nMonthLen
      Else
 bWhile = False
      End If
    Loop While bWhile

    ' Add the remaining days to Date

    nDateH = nDays + 1
  End If
  GregToHeb = CStr(nMonthH) & "/" & CStr(nDateH) & "/" & CStr(nYearH)
End Function

Public Function FormatDateH(nYearH, nMonthH, nDateH)
  Dim sMonth As String
  Select Case nMonthH
    Case 1
      sMonth = "תשרי"
    Case 2
      sMonth = "חשוון"
    Case 3
      sMonth = "כסלו"
    Case 4
      sMonth = "טבת"
    Case 5
      sMonth = "שבט"
    Case 6
      sMonth = "אדר א'"
    Case 7
      sMonth = IIf(IsLeapYear(nYearH), "אדר ב'", "אדר")
    Case 8
      sMonth = "ניסן"
    Case 9
      sMonth = "אייר"
    Case 10
      sMonth = "סיוון"
    Case 11
      sMonth = "תמוז"
    Case 12
      sMonth = "אב"
    Case 13
      sMonth = "אלול"
  End Select
  FormatDateH = CStr(HebrewNum(nDateH)) _
  & " " & sMonth & " " & CStr(HebrewNum(nYearH))
End Function

Public Function TodayHeb()
  Dim nYearH As Long
  Dim nMonthH As Long
  Dim nDateH As Long
  Dim dToday As Date
 
  dToday = Int(Now())
  GregToHeb dToday, nYearH, nMonthH, nDateH
  TodayHeb = FormatDateH(nYearH, nMonthH, nDateH)
End Function

Public Function DateToHeb(dDate)
  Dim nYearH As Long
  Dim nMonthH As Long
  Dim nDateH As Long
 
  dDate = CDate(dDate)
  GregToHeb dDate, nYearH, nMonthH, nDateH
  DateToHeb = FormatDateH(nYearH, nMonthH, nDateH)
End Function



Function HebrewNum(ByVal n As Integer)
  Dim nX As Integer
  Dim sHundred As String
  Dim sTen As String
  Dim sOne As String
 
  n = n Mod 1000
  nX = n - (n Mod 100)
  Select Case nX
    Case 900
      sHundred = Tuf_() & Tuf_() & Raish_()
    Case 800
      sHundred = Tuf_() & Tuf_() & Kuf_()
    Case 700
      sHundred = Tuf_() & Shin_()
    Case 600
      sHundred = Tuf_() & Raish_()
    Case 500
      sHundred = Tuf_() & Kuf_()
    Case 400
      sHundred = Tuf_()
    Case 300
      sHundred = Shin_()
    Case 200
      sHundred = Raish_()
    Case 100
      sHundred = Kuf_()
  End Select
 n = n - nX
  If n = 15 Then
    sTen = Tes_()
    sOne = Vav_()
  ElseIf n = 16 Then
    sTen = Tes_()
    sOne = Ziyon_()
  Else
    nX = n - (n Mod 10)
    Select Case nX
      Case 90
        sTen = Tzodi_()
      Case 80
        sTen = Pai_()
      Case 70
        sTen = Iyin_()
      Case 60
        sTen = Samech_()
      Case 50
        sTen = Nun_()
      Case 40
        sTen = Mem_()
      Case 30
        sTen = Lamed_()
      Case 20
        sTen = Chaf_()
      Case 10
        sTen = Yud_()
    End Select
 nX = n - nX
    Select Case nX
      Case 9
        sOne = Tes_()
      Case 8
        sOne = Ches_()
      Case 7
        sOne = Ziyon_()
      Case 6
        sOne = Vav_()
      Case 5
        sOne = Hai_()
      Case 4
        sOne = Daled_()
      Case 3
        sOne = Gimmel_()
      Case 2
        sOne = Bais_()
      Case 1
        sOne = Alef_()
    End Select
  End If
 
 HebrewNum = sHundred & sTen & sOne
End Function

Public Function FormatDateHInHeb(nYearH, nMonthH, nDateH)
  Dim sMonth As String
  Select Case nMonthH
    Case 1
      sMonth = Tuf_() & Shin_() & Raish_() & Yud_()
    Case 2
      sMonth = Ches_() & Shin_() & Vav_() & Nun_End_()
    Case 3
      sMonth = Chaf_() & Samech_() & Lamed_() & Yud_() & Vav_()
    Case 4
      sMonth = Tes_() & Bais_() & Tuf_()
    Case 5
      sMonth = Shin_() & Bais_() & Tes_()
    Case 6
      sMonth = Alef_() & Daled_() & Raish_() & ChrW(32) & Alef_()
    Case 7
      sMonth = IIf(IsLeapYear(nYearH), _
                     Alef_() & Daled_() & Raish_() & ChrW(32) & Bais_(), _
                     Alef_() & Daled_() & Raish_())
    Case 8
      sMonth = Nun_() & Yud_() & Samech_() & Nun_End_()
    Case 9
      sMonth = Alef_() & Yud_() & Yud_() & Raish_()
    Case 10
      sMonth = Samech_() & Yud_() & Vav_() & Nun_End_()
    Case 11
      sMonth = Tuf_() & Mem_() & Vav_() & Ziyon_()
    Case 12
      sMonth = Alef_() & Bais_()
    Case 13
      sMonth = Alef_() & Lamed_() & Vav_() & Lamed_()
  End Select
  FormatDateHInHeb = sMonth & " " & HebrewNum(nDateH) & " " & CStr(nYearH)
 
  ' FormatDateHInHeb = sMonth & " " & HebrewNum(nDateH) & " " & HebrewNum(nYearH)
 
 
End Function


Public Function HebDateInHeb(dDate)
  Dim nYearH As Long
  Dim nMonthH As Long
  Dim nDateH As Long
 
  dDate = CDate(dDate)
  GregToHeb dDate, nYearH, nMonthH, nDateH
  HebDateInHeb = FormatDateHInHeb(nYearH, nMonthH, nDateH)
End Function

Function Alef_()
  Alef_ = ChrW(1488)
End Function

Function Bais_()
  Bais_ = ChrW(1489)
End Function

Function Gimmel_()
  Gimmel_ = ChrW(1490)
End Function

Function Daled_()
  Daled_ = ChrW(1491)
End Function

Function Hai_()
  Hai_ = ChrW(1492)
End Function

Function Vav_()
  Vav_ = ChrW(1493)
End Function

Function Ziyon_()
  Ziyon_ = ChrW(1494)
End Function

Function Ches_()
  Ches_ = ChrW(1495)
End Function

Function Tes_()
  Tes_ = ChrW(1496)
End Function

Function Yud_()
  Yud_ = ChrW(1497)
End Function

Function Chaf_End_()
  Chaf_End_ = ChrW(1498)
End Function

Function Chaf_()
  Chaf_ = ChrW(1499)
End Function

Function Lamed_()
  Lamed_ = ChrW(1500)
End Function

Function Mem_End_()
  Mem_End_ = ChrW(1501)
End Function

Function Mem_()
Mem_ = ChrW(1502)
End Function

Function Nun_End_()
   Nun_End_ = ChrW(1503)
End Function

Function Nun_()
  Nun_ = ChrW(1504)
End Function

Function Samech_()
  Samech_ = ChrW(1505)
End Function

Function Iyin_()
  Iyin_ = ChrW(1506)
End Function

Function Pai_End_()
  Pai_End_ = ChrW(1507)
End Function

Function Pai_()
  Pai_ = ChrW(1508)
End Function

Function Tzodi_End_()
  Tzodi_End_ = ChrW(1509)
End Function

Function Tzodi_()
  Tzodi_ = ChrW(1510)
End Function

Function Kuf_()
  Kuf_ = ChrW(1511)
End Function

Function Raish_()
  Raish_ = ChrW(1512)
End Function

Function Shin_()
  Shin_ = ChrW(1513)
End Function

Function Tuf_()
  Tuf_ = ChrW(1514)
End Function

Function UnicodeChar(n As Integer)
  UnicodeChar = ChrW(n)
End Function


 ' Some handy code to help generate code

Public Sub MakeHebrewLet()
  Dim nRow As Integer
 Sheets.Add
  ActiveSheet.Name = "HebrewLet"
  For nRow = 1 To 27
    Cells(nRow, 1) = nRow + 1487
    Cells(nRow, 2) = ChrW(nRow + 1487)
    Select Case nRow
      Case 1
        Cells(nRow, 3) = "Alef"
      Case 2
        Cells(nRow, 3) = "Bais"
      Case 3
        Cells(nRow, 3) = "Gimmel"
      Case 4
        Cells(nRow, 3) = "Daled"
      Case 5
        Cells(nRow, 3) = "Hai"
      Case 6
        Cells(nRow, 3) = "Vav"
      Case 7
        Cells(nRow, 3) = "Ziyon"
      Case 8
        Cells(nRow, 3) = "Ches"
      Case 9
        Cells(nRow, 3) = "Tes"
      Case 10
        Cells(nRow, 3) = "Yud"
      Case 11
        Cells(nRow, 3) = "Chaf_End"
      Case 12
        Cells(nRow, 3) = "Chaf"
      Case 13
        Cells(nRow, 3) = "Lamed"
      Case 14
        Cells(nRow, 3) = "Mem_End"
      Case 15
        Cells(nRow, 3) = "Mem"
      Case 16
        Cells(nRow, 3) = "Nun_End"
      Case 17
        Cells(nRow, 3) = "Nun"
      Case 18
        Cells(nRow, 3) = "Samech"
      Case 19
        Cells(nRow, 3) = "Iyin"
      Case 20
        Cells(nRow, 3) = "Pai_End"
      Case 21
        Cells(nRow, 3) = "Pai"
      Case 22
        Cells(nRow, 3) = "Tzodi_End"
      Case 23
        Cells(nRow, 3) = "Tzodi"
      Case 24
        Cells(nRow, 3) = "Kuf"
      Case 25
        Cells(nRow, 3) = "Raish"
      Case 26
        Cells(nRow, 3) = "Shin"
      Case 27
        Cells(nRow, 3) = "Tuf"
    End Select
  Next
End Sub

Public Function HebSt(S As String)
  Dim n As Integer
 

  For n = 1 To Len(S)
    If n <> 1 Then
      HebSt = HebSt + " & "
    End If
    HebSt = HebSt + HebLetToFunc(Mid(S, n, 1))
  Next
End Function

Function HebLetToFunc(sHebLet As String) As String
  Dim nRow As Integer
  HebLetToFunc = "ChrW(" + CStr(AscW(sHebLet)) & ")"
  nRow = 1
  Do While Sheets("HebrewLet").Cells(nRow, 2) <> ""
    If Sheets("HebrewLet").Cells(nRow, 2) = sHebLet Then
      HebLetToFunc = Sheets("HebrewLet").Cells(nRow, 3) & "_()"
      Exit Do
    End If
    nRow = nRow + 1
  Loop
End Function

אולי מישהו יכו לעזור? ... למה את החודש אני מקבל בסימני שאלה ... מצורף צילום מסך ==>

1640004638482.png
 

אפר

סתם מתעניין...
מנוי פרימיום
אולי מישהו יכו לעזור? ... למה את החודש אני מקבל בסימני שאלה ... מצורף צילום מסך ==>

צפה בקובץ המצורף 1027101
כנראה אותה בעיה של קידוד
שים לב שהשנה והתאריך בסדר כי השתמשו בקידוד ע"י פונקציות ולא בטקסט
אולי תייצר פונקציה שתטפל בזה בכל טקסט שאתה מעוניין
 

bmkol

משתמש מקצוען
אני צריך מישהו לנסות את התוכנה מעשרות שלי רק כדי לקבל חוות דעת לפני שאני משחרר אותה חינם לאויר ... מישהו רוצה אולי?
 

bmkol

משתמש מקצוען
פונקציה קטנה ופשוטה שיכולה לעזור להמרת השנה לתאריך עברי .. אפשר עוד להרחיב את זה למי שרוצה

Public Function ShanaIvrit(ByVal intNum As Integer)

Dim strNum As String = CStr(intNum)
Dim strTemp As String = ""
Dim strTemp1 As String = ""
Dim strTemp2 As String = ""
Dim strTemp3 As String = ""

'לוקח את המאות למשל 5782 נותן את תש
strTemp1 = Mid(strNum, 2, 1)
Select Case strTemp1
Case 7
strTemp1 = "תש"
Case 8
strTemp1 = "תת"
End Select
strTemp = strTemp1

'לוקח את העשרות למשל 5782 נותן את פ
strTemp2 = Mid(strNum, 3, 1)
Select Case strTemp2
Case 1
strTemp2 = "י"
Case 2
strTemp2 = "כ"
Case 3
strTemp2 = "ל"
Case 4
strTemp2 = "מ"
Case 5
strTemp2 = "נ"
Case 6
strTemp2 = "ס"
Case 7
strTemp2 = "ע"
Case 8
strTemp2 = "פ"
Case 9
strTemp2 = "צ"
End Select
strTemp = strTemp1 & strTemp2

'לוקח את האחדות למשל 5782 נותן את ג
strTemp3 = Mid(strNum, 4, 1)
Select Case strTemp3
Case 1
strTemp3 = "א"
Case 2
strTemp3 = "ב"
Case 3
strTemp3 = "ג"
Case 4
strTemp3 = "ד"
Case 5
strTemp3 = "ה"
Case 6
strTemp3 = "ו"
Case 7
strTemp3 = "ז"
Case 8
strTemp3 = "ח"
Case 9
strTemp3 = "ט"
End Select
strTemp = strTemp1 & strTemp2 & ChrW(34) & strTemp3

ShanaIvrit = strTemp

End Function
 

יכג

משתמש חדש
אני מחפש עzרה מי שיכול לכתוב לי לפי הקוד שם רחמיםR (שרשור 2) איך אני כותב את הפונקציה בכדי להפוך תאריך עברי ללועזי
השאלה כוללת 2 דברים:
1. באיזה תבנית אני צריך לרשום את התאריך העברי עם גרשיים / ללא וכדו'
2. מה אני כותב בכדי שהפונקציה ימיר את התאריך ללועזי.
מצורף דוגמא:
()Private Sub DateHebrew_AfterUpdate​
Me.DateEnglish = ????????????? (Me.DateHebrew)​
Me.DateEnglish.Requery
End Sub​
בתודה מראש
 

אולי מעניין אותך גם...

הפרק היומי

הפרק היומי! כל ערב פרק תהילים חדש. הצטרפו אלינו לקריאת תהילים משותפת!


תהילים פרק צח

א מִזְמוֹר שִׁירוּ לַיי שִׁיר חָדָשׁ כִּי נִפְלָאוֹת עָשָׂה הוֹשִׁיעָה לּוֹ יְמִינוֹ וּזְרוֹעַ קָדְשׁוֹ:ב הוֹדִיעַ יי יְשׁוּעָתוֹ לְעֵינֵי הַגּוֹיִם גִּלָּה צִדְקָתוֹ:ג זָכַר חַסְדּוֹ וֶאֱמוּנָתוֹ לְבֵית יִשְׂרָאֵל רָאוּ כָל אַפְסֵי אָרֶץ אֵת יְשׁוּעַת אֱלֹהֵינוּ:ד הָרִיעוּ לַיי כָּל הָאָרֶץ פִּצְחוּ וְרַנְּנוּ וְזַמֵּרוּ:ה זַמְּרוּ לַיי בְּכִנּוֹר בְּכִנּוֹר וְקוֹל זִמְרָה:ו בַּחֲצֹצְרוֹת וְקוֹל שׁוֹפָר הָרִיעוּ לִפְנֵי הַמֶּלֶךְ יי:ז יִרְעַם הַיָּם וּמְלֹאוֹ תֵּבֵל וְיֹשְׁבֵי בָהּ:ח נְהָרוֹת יִמְחֲאוּ כָף יַחַד הָרִים יְרַנֵּנוּ:ט לִפְנֵי יי כִּי בָא לִשְׁפֹּט הָאָרֶץ יִשְׁפֹּט תֵּבֵל בְּצֶדֶק וְעַמִּים בְּמֵישָׁרִים:
נקרא  9  פעמים

אתגר AI

באבוד רשעים בינה • אתגר 112

לוח מודעות

למעלה