Variables: Need clarification
Oldbitcollector (Jeff)
Posts: 8,091
I have to admit that I'm getting very lost in variables.
Would someone mind giving me some examples in .spin based on these basic examples?
A$="This is not a number"
A=1
A=A+1
A=A-1
LET B = A
If there is some clarification elsewhere in print, (the prop manual isn't helping)
please point in that direction. Thanks!
Jeff
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
Would someone mind giving me some examples in .spin based on these basic examples?
A$="This is not a number"
A=1
A=A+1
A=A-1
LET B = A
If there is some clarification elsewhere in print, (the prop manual isn't helping)
please point in that direction. Thanks!
Jeff
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
Comments
2) A := 1
3) A := A + 1 or A += 1 or A++
4) A := A - 1 or A -= 1 or A--
5) B : = A
is nearly exactly the same as:
Edit: STRING is very versatile: You can also write things like :
Of course you must not use 0...
Post Edited (deSilva) : 7/31/2007 5:18:30 PM GMT
Strings in Spin use a zero byte ($00) as a terminator character, like in C and some other programming languages.
VAR byte a[noparse][[/noparse] 20 ]
[noparse][[/noparse]set the length of a?]
PUB strcopy( dst, src) [noparse][[/noparse]a function with destination and source?]
bytemove(dst, src, strsize(src)+1) [noparse][[/noparse]move destination to source +1??]
{ now you can do: strcopy(a,string("This is not a number")) }
so a now equals "This is not a number" ?
Lost...
Oldbitcollector
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
The comments and code above are proof that a million monkeys with a million propeller chips *could* write Shakespeare!
strsize scans the string looking for a zero byte and returns the number of non-zero bytes found before the zero byte which is the length of the string. strsize+1 includes the zero byte in the length.
The declaration "VAR byte a[noparse][[/noparse] 20 ]" simply allocates a 20 byte block of storage.
I did make a mistake in the example in the comment. It should be: strcopy(@a,string("This is not a number"))
The difference is that the "@" operator produces an address (of a) which is what strcopy expects. The "string" function already returns an address.