Stuck on syntax to read value in memory
John Kauffman
Posts: 653
I am trying to use the syntax #3 at the bottom of page 53 of the prop manual v1.1.
Program #1 creates and fills three variables
Program #2 reads them - but it fails
I compile and run Program #2
The line marked ### the code below is where the error occurs.
The standard lines of clock freq, etc. are there and when I comment out the "read variable" lines the code compiles, runs and performs as expected.
I know this is a trivial question, but I don't see how my code is different than the Prop Manual.
Thanks.
File = TestNumGen01.spin
{Creates and fills three variables with numbers}
VAR
byte Number1
byte Number2
byte Number3
PUB Start
{ Fills three variables}
Number1 := 11
Number2 := 12
Number3 := 13
File = TestMatchDisplay01.spin
OBJ
TestNumGen : "TestNumGen01"
VgaText : "VGA_Text"
PUB MyPub
{displays value in variable "Number1" put in the main memory by object "TestNumGen"}
vgatext.start(16)
TestNumGen.start
vgatext.str(string("Here are the numbers: ")) ' this line works fine
' ### problem is here:
all three following lines result in compile error of "expect expression term"
when next three lines are commented out the program runs fine.
vgatext.dec(Number1[0])
vgatext.dec(byte[Number1][0])
vgatext.dec(byte[@Number1][0])
Program #1 creates and fills three variables
Program #2 reads them - but it fails
I compile and run Program #2
The line marked ### the code below is where the error occurs.
The standard lines of clock freq, etc. are there and when I comment out the "read variable" lines the code compiles, runs and performs as expected.
I know this is a trivial question, but I don't see how my code is different than the Prop Manual.
Thanks.
File = TestNumGen01.spin
{Creates and fills three variables with numbers}
VAR
byte Number1
byte Number2
byte Number3
PUB Start
{ Fills three variables}
Number1 := 11
Number2 := 12
Number3 := 13
File = TestMatchDisplay01.spin
OBJ
TestNumGen : "TestNumGen01"
VgaText : "VGA_Text"
PUB MyPub
{displays value in variable "Number1" put in the main memory by object "TestNumGen"}
vgatext.start(16)
TestNumGen.start
vgatext.str(string("Here are the numbers: ")) ' this line works fine
' ### problem is here:
all three following lines result in compile error of "expect expression term"
when next three lines are commented out the program runs fine.
vgatext.dec(Number1[0])
vgatext.dec(byte[Number1][0])
vgatext.dec(byte[@Number1][0])
Comments
Could you please use [noparse] [/noparse] for code fragments?
> I'm not sure how to do that. Do you have an example? Is it like this: ?
[noparse] [/noparse]
I did not know about that convention, will do. Thanks.
That's it Which will then look like this (noparse tags omitted):
Goal:
OuterFile.spin, the top object, will use the value in a variable that has been filled by the .start method of the InnerFile.spin.
Current problem:
The OuterFile does not compile.
Thanks.
What is your goal. It appears like you want to use the .start() method of "inner" to set a variable in that object, but you'd also like to read that variable back. A parent object cannot see the variables in one of it's children. You can deal with this two ways
1) Provide a method to return the variable from the child object -- for example (this would be in "inner"):
2) Provide an address to shared values. This is useful when you have several variables. For example, what if you had an array of five bytes in the "inner" object. By returning the address of that array with a method you could do this:
Now your "outer" object can loop through that array like this:
Perhaps it would be useful to state your end goal.
Note that this uses the address. You have this syntax error in your "inner" object:
This is the most straightforward:
...but you could also do this:
Note the inclusion of the @ (address of) sign.
Inner:
Outer:
VGA shows "11"
Jon: thanks for sticking with me to see this one through.