Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:00 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 : Error problem

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 05:30am 27 Mar 2019
Copy link to clipboard 
Print this post

I have some code that has been running OK and I decided to add GPS time, so I connected the receiver and copy/pasted Geoff's code which runs OK in another project.
I get the error
  Quote  > run
[134] GetMins = GetMins + (md(mth) * (24 * 60))
Error: MD already declared
>


I did a search and there are only three instances of "MD" in the code the first two here
Dim md(12), arg$(20)
Data 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
For i = 1 To 12: Read md(i): Next i

and the next one in this function.
Function GetMins(yr, mth, day, hr, min)
GetMins = (yr - 14) * (365 * 24 * 60) + ((yr - 13) \ 4) * (24 * 60)
GetMins = GetMins + (md(mth) * (24 * 60))
GetMins = GetMins + ((day - 1) * (24 * 60))
GetMins = GetMins + (hr * 60)
GetMins = GetMins + min
If (yr - 16) Mod 4 = 0 And mth > 2 Then GetMins = GetMins + (24 * 60)
End Function



What does this error mean?
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 06:36am 27 Mar 2019
Copy link to clipboard 
Print this post

Deleted - sorry mis=read the code.Edited by Turbo46 2019-03-28
Keep safe. Live long and prosper.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5089
Posted: 04:09pm 27 Mar 2019
Copy link to clipboard 
Print this post

hi Pascal,

Looks like md() is not locally found in function GetMins(xxxx)
Then the function wants to create it (like any variable that is not known previous) and sees that it already exists.

Is there any way to decare md() globally, or pass it to the function also?

Volhout

PicomiteVGA PETSCII ROBOTS
 
goc30

Guru

Joined: 12/04/2017
Location: France
Posts: 435
Posted: 06:49pm 27 Mar 2019
Copy link to clipboard 
Print this post

hi paslcal

I have same pb
I have change 2 vars md and arg$ to vmd and varg$
and it work correctly

after, i have bug with "getdate' function, but it is because function is wrong
(pb with computing "day"

I search!!
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 08:55pm 27 Mar 2019
Copy link to clipboard 
Print this post

@goc30
I did the same thing with the same result.
@Volhout
OK now I understand what is happening but md(12) is declared as a global at the start of the code.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
disco4now

Guru

Joined: 18/12/2014
Location: Australia
Posts: 1003
Posted: 09:47pm 27 Mar 2019
Copy link to clipboard 
Print this post

Do you have/need OPTION EXPLICIT
Latest F4 Latest H7 FotS
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 09:59pm 27 Mar 2019
Copy link to clipboard 
Print this post

From Geoff's "SuperClock":

Dim Integer md(12) = (0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334)


and

' calculate the seconds since midnight 1st Jan 2014
Function GetSec(yr As Integer, mth As Integer, day As Integer, hr As Integer, min As Integer, sec As Integer) As Integer
GetSec = (yr - 14) * (365 * 24 * 60)
GetSec = GetSec + ((yr - 13) \ 4) * (24 * 60)
GetSec = GetSec + (md(mth) * (24 * 60))
GetSec = GetSec + ((day - 1) * (24 * 60))
GetSec = GetSec + (hr * 60)
GetSec = ((GetSec + min) * 60) + sec
If (yr - 16) Mod 4 = 0 And mth > 2 Then GetSec = GetSec + (24 * 3600)
End Function


These are the only places that md() appears and, OK, the code is a bit different but I don't see why one works and the other doesn't. Unless it's a different version of MMBasic and there is a bug.

You don't say which version of MMBasic you are using or what device. I'm not familiar with any of Peter M's versions.

Bill


Keep safe. Live long and prosper.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 03:19am 28 Mar 2019
Copy link to clipboard 
Print this post

MX170 and V5.0409
I don't know what to do? I changed this
Dim md(12), arg$(20)
Data 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334
For i = 1 To 12: Read md(i): Next i

to this
Dim Integer md(12) = (0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334)

and that seemed to fix that part but then got the same error with 'TIMEZONE'
so I substituted 'TIMEZONE' with 10 and got past that, then got the same problem with the Daylight Saving so commented that out then got the problem with the next variable.
I am going to have to go back to the working code I had before trying to add the GPS TIME and start again.
I can't help thinking it has got something to do with the copy/paste of the code.

Edit.... I tried using OPTION EXPLICIT, I declared all the vars but the error still surfaced. I'll START AGAIN.
Edited by palcal 2019-03-29
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
Turbo46

Guru

Joined: 24/12/2017
Location: Australia
Posts: 1642
Posted: 05:53am 28 Mar 2019
Copy link to clipboard 
Print this post

Have you considered re-flashing the chip? I think it was Grogster who said recently "When weird stuff happens try re-flashing the chip" or words to that effect. It has worked for others. I'd give it a go.

Bill
Keep safe. Live long and prosper.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 09:07am 28 Mar 2019
Copy link to clipboard 
Print this post

Good idea, I will try that.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 02:20am 29 Mar 2019
Copy link to clipboard 
Print this post

I re flashed the chip, problem still there BUT since reinstalling MMedit to fix another problem I was having with SEARCH everything seems to be OK. My MMedit must have got corrupted somehow and caused a lot of weird problems.
"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
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