Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:14 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : syntax error?

Author Message
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 07:19pm 20 Nov 2020
Copy link to clipboard 
Print this post

ok so i decided to try some of the programs in the manual. the days program i get a syntax error on line 28 and for the life of me i cannot see what its complaining about unless there is an issue with the code.

' Example program to calculate the number of days between two dayes

OPTION EXPLICIT
OPTION DEFAULT NONE
TRACE ON

dim STRING s
dim FLOAT d1, d2

DO
 print : print "Enter the date as dd mmm yyyy"
 print "first date";
 input s
 d1 = GetDays(s)
 if d1 = 0 then print "invalid date:" : continue do
 print "second date";
 input s
 d2 = GetDays(s)
 IF d2 = 0 then print "invalid date!" : continue do
 print "Difference is" ABS(d2 - d1) " days"
loop

'calculate the number of days since 1/1/1900

function GetDays(d$) as float
 local string Month(11) = ("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec")
 local float Days(11) = (0,31,59,90,120,151,181,212,243,273,304,334)
 local float day, mth, yr, s1, s2,

'find the seperating space character within a date

s1 = INSTR(d$, " ")
if si = 0 then exit function
s2 = INSTR(s1 + 1, d$, " ")
if s2 = 0 then exit function

'get the day month and year as numbers

day = VAL(MID$(d$, 1, s2 - 1)) - 1
if day < 0 or day > 30 then exit function
for mth = 0 to 11
 if LCASE$(MID$(d$, s1 + 1, 3)) = Month(mth) then exit for
next mth
if mth > 11 then exit function
yr = VAL(MID$(d$, s2 + 1)) - 1900
if yr < 1 or yr >= 200 then exit function


' calculate the number of days uncluding adjustment for leap years

GetDays = (yr * 365) + FIX((yr - 1) / 4)
if yr MOD 4 = 0 and mth >= 2 then GetDays = Getdays + 1
GetDays = GetDays + Days(mth) = day
end function

 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 07:33pm 20 Nov 2020
Copy link to clipboard 
Print this post

You have a spurious comma at the end of the line and the interpreter is looking for another variable name. Also check the function EPOCH for this application
Edited 2020-11-21 05:34 by matherp
 
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 08:33pm 20 Nov 2020
Copy link to clipboard 
Print this post

its always the easy ones that allude me. im looking for something complicated and it was a typo :P.
 
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 08:40pm 20 Nov 2020
Copy link to clipboard 
Print this post

ok now its running but its not doing what its suppose to. when i type in the first day i get a bunch of numbers then it says enter first date and keeps repeating.
 
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 08:56pm 20 Nov 2020
Copy link to clipboard 
Print this post

fixed that now im stuck in the first date loop. for some reason it thinks what im typing in is 0 because i keep getting invalid date.
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 09:30pm 20 Nov 2020
Copy link to clipboard 
Print this post

I copied the program from the "Introduction..." PDF.
The only line I changed was to remove the linebreak in line 21
IT runs correctly and tells me I am 25044 days old.
(Time flys when you are having fun)

There will be a few typos in your code.

Jim
VK7JH
MMedit
 
JohnS
Guru

Joined: 18/11/2011
Location: United Kingdom
Posts: 4044
Posted: 09:35pm 20 Nov 2020
Copy link to clipboard 
Print this post

I see a typo si for s1

No doubt others.

John
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6283
Posted: 12:22am 21 Nov 2020
Copy link to clipboard 
Print this post

si instead of s1 on line 33
and
the second = should be a + on line 53
VK7JH
MMedit
 
Geoffg

Guru

Joined: 06/06/2011
Location: Australia
Posts: 3292
Posted: 04:39am 21 Nov 2020
Copy link to clipboard 
Print this post

This is the complete program (with no errors).  
You should be able to copy and paste from this webpage.

' Example program to calculate the number of days between two dates

OPTION EXPLICIT
OPTION DEFAULT NONE

DIM STRING s
DIM FLOAT d1, d2

DO
 PRINT : PRINT "Enter the date as  dd mmm yyyy"
 PRINT " First date";
 INPUT s
 d1 = GetDays(s)
 IF d1 = 0 THEN PRINT "Invalid date!" : CONTINUE DO
 PRINT "Second date";
 INPUT s
 d2 = GetDays(s)
 IF d2 = 0 THEN PRINT "Invalid date!" : CONTINUE DO
 PRINT "Difference is" ABS(d2 - d1) " days"
LOOP

' Calculate the number of days since 1/1/1900
FUNCTION GetDays(d$) AS FLOAT
 LOCAL STRING Month(11) = "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
 LOCAL FLOAT Days(11) = (0,31,59,90,120,151,181,212,243,273,304,334)
 LOCAL FLOAT day, mth, yr, s1, s2

 ' Find the separating space character within a date
 s1 = INSTR(d$, " ")
 IF s1 = 0 THEN EXIT FUNCTION
 s2 = INSTR(s1 + 1, d$, " ")
 IF s2 = 0 THEN EXIT FUNCTION

 ' Get the day, month and year as numbers
 day = VAL(MID$(d$, 1, s2 - 1)) - 1
 IF day < 0 OR day > 30 THEN EXIT FUNCTION
 FOR mth = 0 TO 11
   IF LCASE$(MID$(d$, s1 + 1, 3)) = Month(mth) THEN EXIT FOR
 NEXT mth
 IF mth > 11 THEN EXIT FUNCTION
 yr = VAL(MID$(d$, s2 + 1)) - 1900
 IF yr < 1 OR yr >= 200 THEN EXIT FUNCTION

 ' Calculate the number of days including adjustment for leap years
 GetDays = (yr * 365) + FIX((yr - 1) / 4)
 IF yr MOD 4 = 0 AND mth >= 2 THEN GetDays = GetDays + 1
 GetDays = GetDays + Days(mth) + day
END FUNCTION

Geoff Graham - http://geoffg.net
 
markboston36
Regular Member

Joined: 27/10/2020
Location: United States
Posts: 76
Posted: 07:45pm 21 Nov 2020
Copy link to clipboard 
Print this post

amazing how one typo can cause a big issue. thanks for all your help guys.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025