Checksum Question - Part 2
deepforestgreen
Junior Member
Working with this:
define_function integer getChecksum(char cmd[])
{
stack_var integer bTotal
stack_var integer nLength
stack_var integer nCT
nLength = LENGTH_STRING(cmd - 1)
nCT = 1
for(nCT=1;nCT<=8;nCT++)
{
bTotal = bTotal + cmd[nCT]
}
bTotal = bTotal & $FF
return bTotal
}
Getting this:
'String used as a CHAR value in a math operation' in relation to the line that says 'nLength = LENGTH_STRING(cmd - 1)'
I'm stumped. I'm trying to get rid of these warnings so I can learn more about this part of the programming, but I'm at a loss. I just fixed a handful of similar problems and learned a lot in the process, but this one isn't coming to me.
define_function integer getChecksum(char cmd[])
{
stack_var integer bTotal
stack_var integer nLength
stack_var integer nCT
nLength = LENGTH_STRING(cmd - 1)
nCT = 1
for(nCT=1;nCT<=8;nCT++)
{
bTotal = bTotal + cmd[nCT]
}
bTotal = bTotal & $FF
return bTotal
}
Getting this:
'String used as a CHAR value in a math operation' in relation to the line that says 'nLength = LENGTH_STRING(cmd - 1)'
I'm stumped. I'm trying to get rid of these warnings so I can learn more about this part of the programming, but I'm at a loss. I just fixed a handful of similar problems and learned a lot in the process, but this one isn't coming to me.
Comments
-
nLength = LENGTH_STRING(cmd - 1)
Should be
nLength = LENGTH_STRING(cmd)-1 -
That did it! It seems obvious, now, but I just wasn't thinking about it properly. Thanks!
-
your welcome.
-
I would strongly suggest that you initialize bTotal before your FOR loop. If your cmd[] comes in with 0 length, you won't necessarily know what gets returned, unless a STACK_VAR is always initialized to "0". It's just good practice to initialize the return variable before you make any decisions on it or calculate a new value, in my opinion.
Categories
- All Categories
- 2.5K AMX General Discussion
- 922 AMX Technical Discussion
- 514 AMX Hardware
- 502 AMX Control Products
- 3 AMX Video Distribution Products
- 9 AMX Networked AV (SVSI) Products
- AMX Workspace & Collaboration Products
- 3.4K AMX Software
- 151 AMX Resource Management Suite Software
- 386 AMX Design Tools
- 2.4K NetLinx Studio
- 135 Duet/Cafe Duet
- 248 NetLinx Modules & Duet Modules
- 57 AMX RPM Forum
- 228 MODPEDIA - The Public Repository of Modules for Everyone
- 943 AMX Specialty Forums
- 2.6K AMXForums Archive
- 2.6K AMXForums Archive Threads
- 1.5K AMX Hardware
- 432 AMX Applications and Solutions
- 249 Residential Forum
- 182 Tips and Tricks
- 146 AMX Website/Forums