Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / could not understand command at line ...

Author
Message
compile
8
Years of Service
User Offline
Joined: 11th Jan 2016
Location:
Posted: 11th Jan 2016 17:02
Hello,

at compile time I receive this error message : could not understand command at line ... for #CONSTANT xyz 1

My DBpro version is 1.0761

Help will be welcome
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 12th Jan 2016 01:58 Edited at: 12th Jan 2016 02:14
Hi and welcome

When you have the word "for" before #constant xyz 1, is that because it is in your code or did you write that in explanation to us that the error message is for that particular code?

If it is because it is in your code then it is because "for" is actually the start of a loop and would be used with"next" similar to this:

First of all if you don't understand what a variable is please consult the help files and look at the principles section from the help files home page followed by the first option available which should read data types and variables.

Basically the program executes any commands trapped between the "for" and "next" lines. "x" is the variable needed for the loop which you can use to keep track of the number of times the loop is run before it stops trapping the commands between "for" and "next" and continues to execute commands after the "next" command(which also needs the "x" in order to compile). The command itself uses the variable "x" in conjunction with a step value if provided(detailed in the help files). The variable "x" is being used by the loop very much like you would use a variable. So in the above case the first time the loop is completed the variable "x" holds the value of 1, then the "print x" line simply outputs the value of "x" to screen. When the program reaches "next x" it jumps back to the "for x=1 to 10" line and continues in the same manner for a second time. This time the "x" value will be 2 when we reach the "print x" line. This is because of the "1 to 10" part which instructs the loop how many times to cycle through the loop, so on the third cycle the value of "x" will be 3 and so on until the loop has been completed 10 times. After the tenth cycle the program no longer jumps back to the "for x=1 to 10" line, instead it continues past the "next x" line and executes the "wait key" command. If you place your cursor on the word "for" then press F1 key the commands help file will open and you can see more information on the command.

The "#constant" command in your line is a sort of variable that is fixed(called a token), if you where to attempt to change that variable using the "=" sign ie "xyz=20" at some point anywhere in the program the compiler should fail and tell you "unknown type found line ..." as the error message. However you can force it to change by slipping it into the for...next loop(or any of the looping commands) and switching the actual value from "1" to "x". You can also declare the constant token once per source file(any project can use multiple source files)

If however the word "for" was not part of your code and was intended to tell us what line the error was for, then the compiler sometimes gets the wrong line number and/or gives the wrong error message, in which case we will need to see more of the code - the compiler usually does not get the line number wrong unless there are multiple source files used in a project, if this is the case there should be a temp folder in your Dark Basic Pro folder with a dump file that combines all the source files into one file. If you compile this temp dump file the compiler should then give you the correct line number of the error.
compile
8
Years of Service
User Offline
Joined: 11th Jan 2016
Location:
Posted: 12th Jan 2016 10:32
Thank you very much for your long and interresting answer.

Sorry for my syntax !

The word "for" was meaning "for the following command", as you supposed.

The error was almost at the bottom of the code and had nothing to do with #CONSTANT.

I learned something new today.
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 12th Jan 2016 14:48
Your welcome, glad to have helped, have fun

Login to post a reply

Server time is: 2024-04-25 16:02:10
Your offset time is: 2024-04-25 16:02:10