Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.clipper.visual-objects > #6060 > unrolled thread
| Started by | Rob Smith <rasmithhalifax@gmail.com> |
|---|---|
| First post | 2013-10-11 02:56 -0700 |
| Last post | 2013-10-14 04:24 -0700 |
| Articles | 11 — 4 participants |
Back to article view | Back to comp.lang.clipper.visual-objects
Basic to VO Rob Smith <rasmithhalifax@gmail.com> - 2013-10-11 02:56 -0700
Re: Basic to VO Johan Nel <johan.nel@xsinet.co.za> - 2013-10-11 04:16 -0700
Re: Basic to VO Rob Smith <rasmithhalifax@gmail.com> - 2013-10-11 05:53 -0700
Re: Basic to VO Johan Nel <johan.nel@xsinet.co.za> - 2013-10-11 06:06 -0700
Re: Basic to VO Rob Smith <rasmithhalifax@gmail.com> - 2013-10-11 06:46 -0700
Re: Basic to VO Johan Nel <johan.nel@xsinet.co.za> - 2013-10-11 07:03 -0700
Re: Basic to VO Rob Smith <rasmithhalifax@gmail.com> - 2013-10-11 08:00 -0700
Re: Basic to VO JohnMartens <martens@tennishulp.info> - 2013-10-11 17:32 +0200
Re: Basic to VO "Johan Nel" <johan.nel@xsinet.co.za> - 2013-10-12 13:40 +0200
Re: Basic to VO "Johan Nel" <johan.nel@xsinet.co.za> - 2013-10-12 13:41 +0200
Re: Basic to VO Rob Smith <rasmithhalifax@gmail.com> - 2013-10-14 04:24 -0700
| From | Rob Smith <rasmithhalifax@gmail.com> |
|---|---|
| Date | 2013-10-11 02:56 -0700 |
| Subject | Basic to VO |
| Message-ID | <7b6ad427-8874-43d4-9bfc-8e54083d7163@googlegroups.com> |
Hi
I am trying to translate some basic into Vo.
The basic function is specified as follows
Function greg_date(hdat As String) As Date
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
greg_date = Cstart - 1 + ncycles * DCycle + days_thiscycle
End Function
I have run it through the excel debugger and the value of greg_date = Cstart - 1 etc is 23868.
Same value in my VO Code.
But how do I make this a date?
Thanks
Robert
[toc] | [next] | [standalone]
| From | Johan Nel <johan.nel@xsinet.co.za> |
|---|---|
| Date | 2013-10-11 04:16 -0700 |
| Message-ID | <c3448ddc-027d-49a3-8b19-63ea3d31c088@googlegroups.com> |
| In reply to | #6060 |
Hi Robert,
> But how do I make this a date?
Done this in Vulcan, but as close as possible to VO Syntax :)
HTH,
Johan Nel
Durban, South Africa.
FUNCTION Start( ) AS VOID
?Greg_Date("2/24/1906")
RETURN
FUNCTION Greg_Date(hdat AS STRING) AS DATE
LOCAL YearFinder := {354, 708, 1063, 1417, 1772, 2126, 2480, 2835} AS ARRAY
LOCAL MonthFinderL := {30, 59, 89, 118, 148, 177, 207, 236, 266, 296, 325, 355};
AS ARRAY
LOCAL MonthFinder := {29, 59, 88, 118, 147, 177, 206, 236, 265, 295, 324, 354};
AS ARRAY
LOCAL Cstart := SToD("19060224") AS DATE // Corresponds to 1 Muharram 1324
LOCAL Hstart := 1324 AS INT
LOCAL DCycle := 2835 AS INT
// parses to produce hmonth, hday, hyear
LOCAL i := At("/", hdat) AS DWORD
LOCAL hmonth := Val(Left(hdat, i - 1)) AS INT
LOCAL j := RAt("/", hdat) AS DWORD
LOCAL hday := Val(SubStr(hdat, i + 1, j - i - 1)) AS INT
LOCAL hyear := Val(Right(hdat, Len(hdat) - j)) AS INT
LOCAL elapsed_years := hyear - Hstart AS INT
LOCAL ncycles := elapsed_years / 8 // You have \ here, was that a typo?
LOCAL nyear := elapsed_years % 8 AS INT
LOCAL leap AS LOGIC
LOCAL days_thiscycle AS INT
LOCAL days_thisyear AS INT
IF nyear = 0
days_thiscycle := 0
ELSE
days_thiscycle := YearFinder[nyear]
ENDIF
leap := IsLeapYear(nyear) // You should have your own function for this, but I
//include my version
IF hmonth = 1
days_thisyear := hday
ELSE
IF leap
days_thisyear := MonthFinderL[hmonth - 1] + hday
ELSE
days_thisyear := MonthFinder[hmonth - 1] + hday
ENDIF
ENDIF
days_thiscycle := days_thiscycle + days_thisyear
RETURN Cstart - 1 + ncycles * DCycle + days_thiscycle
FUNCTION IsLeapYear(y AS INT) AS LOGIC
LOCAL d AS DATE
d := SToD(Str(y, 4, 0) + "0228")
d := d + 1
RETURN Month(d) == 2
[toc] | [prev] | [next] | [standalone]
| From | Rob Smith <rasmithhalifax@gmail.com> |
|---|---|
| Date | 2013-10-11 05:53 -0700 |
| Message-ID | <c8bf1b43-aa63-4d22-9684-606f6e8aec33@googlegroups.com> |
| In reply to | #6064 |
On Friday, October 11, 2013 12:16:33 PM UTC+1, Johan Nel wrote: Thanks Johan I stll have the problem that RETURN Cstart - 1 + ncycles * DCycle + days_thiscycle gives an error of date and longint so it doesn't recognise it as a date.
[toc] | [prev] | [next] | [standalone]
| From | Johan Nel <johan.nel@xsinet.co.za> |
|---|---|
| Date | 2013-10-11 06:06 -0700 |
| Message-ID | <7dc0e08d-8839-43bf-bed0-86469f995dfe@googlegroups.com> |
| In reply to | #6066 |
Hi Robert, > I stll have the problem that RETURN Cstart - 1 + ncycles * DCycle + days_thiscycle > > gives an error of date and longint so it doesn't recognise it as a date. Can you post your VO code? The example I posted runs fine on my side with date returned. Regards, Johan
[toc] | [prev] | [next] | [standalone]
| From | Rob Smith <rasmithhalifax@gmail.com> |
|---|---|
| Date | 2013-10-11 06:46 -0700 |
| Message-ID | <62cef3e3-b06d-47a3-8eca-9fff740017ae@googlegroups.com> |
| In reply to | #6067 |
Hi John
This is my VO Code :-
FUNCTION GregDate(hdat as STRING) as date
/*
local YearFinder := {354, 708, 1063, 1417, 1772, 2126, 2480, 2835} as ARRAY
local MonthFinderL := {30, 59, 89, 118, 148, 177, 207, 236, 266, 296, 325, 355} as ARRAY
local MonthFinder := {29, 59, 88, 118, 147, 177, 206, 236, 265, 295, 324, 354} as ARRAY
*/
local Cstart := SToD("19060224") as date // Corresponds to 1 Muharram 1324
local Hstart := 1324 as int
local DCycle := 2835 as int
// parses to produce hmonth, hday, hyear
local i := At("/", hdat) as DWORD
local hmonth := Val(Left(hdat, i - 1)) as int
local j := RAt("/", hdat) as DWORD
local hday := Val(SubStr(hdat, i + 1, j - i - 1)) as int
local hyear := Val(Right(hdat, Len(hdat) - j)) as int
local elapsed_years := hyear - Hstart as int
local nCycles := elapsed_years / 8 // You have \ here, was that a typo?
local nyear := elapsed_years % 8 as int
local leap as LOGIC
local days_thiscycle as int
local days_thisyear as int
if nyear=0
days_thiscycle := 0
else
days_thiscycle := azIslamYears[nyear]
endif
leap := IsLeapYear(nyear) // You should have your own function for this, but I
//include my version
if hmonth=1
days_thisyear:=hday
else
if leap
days_thisyear:=azIslamMonths1[hmonth-1]+hday
else
days_thisyear:=azIslamMonths2[hmonth-1]+hday
endif
endif
days_thiscycle:=days_thiscycle+days_thisyear
RETURN Cstart - 1 + nCycles * DCycle + days_thiscycle
I have comments out the arrays as I use globals for them.
My call to the function is dDate:=GregDate("01/05/1385"), dDate being as date
Thanks
Robert
[toc] | [prev] | [next] | [standalone]
| From | Johan Nel <johan.nel@xsinet.co.za> |
|---|---|
| Date | 2013-10-11 07:03 -0700 |
| Message-ID | <d5d7271c-0b1e-4daa-a721-c62910ce3934@googlegroups.com> |
| In reply to | #6072 |
Hi Robert,
There must be something else that is funny, the code running fine on my side...
>
> My call to the function is dDate:=GregDate("01/05/1385"), dDate being as date
>
That produces 1964/04/25 on my side...
Johan.
[toc] | [prev] | [next] | [standalone]
| From | Rob Smith <rasmithhalifax@gmail.com> |
|---|---|
| Date | 2013-10-11 08:00 -0700 |
| Message-ID | <cff7b2a2-d3a9-4ca5-9e0e-129083099bce@googlegroups.com> |
| In reply to | #6074 |
Does my code work for you in VO?
[toc] | [prev] | [next] | [standalone]
| From | JohnMartens <martens@tennishulp.info> |
|---|---|
| Date | 2013-10-11 17:32 +0200 |
| Message-ID | <l395ml$gcu$1@dont-email.me> |
| In reply to | #6077 |
could setdate format be the problem ? this is very relevant to StoD !! Better is to use ConDate() function to be independant to the date formatting value John Rob Smith schreef op 11-10-2013 17:00: > Does my code work for you in VO? >
[toc] | [prev] | [next] | [standalone]
| From | "Johan Nel" <johan.nel@xsinet.co.za> |
|---|---|
| Date | 2013-10-12 13:40 +0200 |
| Message-ID | <l3bcfe$fae$1@dont-email.me> |
| In reply to | #6078 |
Hi John, Yes I also believe it has to do with his date format. SToD is independant of date format it receives a string in YYYYMMDD format, and DToS converts to YYYYMMDD format no matter what the date format is set to. Regards, Johan. "JohnMartens" <martens@tennishulp.info> wrote in message news:l395ml$gcu$1@dont-email.me... > could setdate format be the problem ? > this is very relevant to StoD !! > Better is to use ConDate() function to be independant to the date > formatting value > John > > > > Rob Smith schreef op 11-10-2013 17:00: >> Does my code work for you in VO? >>
[toc] | [prev] | [next] | [standalone]
| From | "Johan Nel" <johan.nel@xsinet.co.za> |
|---|---|
| Date | 2013-10-12 13:41 +0200 |
| Message-ID | <l3bchr$flt$1@dont-email.me> |
| In reply to | #6077 |
Rob, As John Martens indicates, we do not know what other conversions you do outside the function, set date format might actually be the culprit. I assumed your date format is set to MM/DD/YYYY, but no sure. When you do a DtoC(dDate) the set date format is use to convert. So not sure how your Hijri date is stored. Regards, Johan"Rob Smith" <rasmithhalifax@gmail.com> wrote in message news:cff7b2a2-d3a9-4ca5-9e0e-129083099bce@googlegroups.com... > Does my code work for you in VO?
[toc] | [prev] | [next] | [standalone]
| From | Rob Smith <rasmithhalifax@gmail.com> |
|---|---|
| Date | 2013-10-14 04:24 -0700 |
| Message-ID | <87dead31-8c52-48a1-afbf-8a37b1c16c45@googlegroups.com> |
| In reply to | #6060 |
A big thanks for everyones help, finally I can convert dates to hijra dates and vice-versa. Robert
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.clipper.visual-objects
csiph-web