Re: help clean up some code
Here's what I'd do:
if counter = 1 and value0 <> newdata then
value1 = newdata
counter = counter +1
return
endif
if counter = 2 and Value0 <> newdata and Value1 <> newdata then
value2 = newdata
counter = counter + 1
return
endif" .......
There is probably a clean "select case" application here as well.
Mike
Re: help clean up some code
yes i could do that but i think the actual structure could be improved , the "newdata" and Value0-6 are actully a 3 values tested to see if that table of arrays(49 arrays values) should add to the larger table of arrays with a total of 6 records
in essence it just test value if it new then add it to the table and inc the counter , if its not then dont add to the table
Re: help clean up some code
Main:
select case counter
case is = 0
if value0 <> newdata then
value1 = newdata
counter = counter +1
endif
case is = 1
if value0 <> newdata and value1 <> new data then
value2 = newdata
counter = counter + 1
endif.......
return
Re: help clean up some code
thanks mike , both option work ok , as it turned out i decided to go with "and" option , it just really large array group and as such it has about 30 " and " statements per match group of the records it takes about 10k compile for that section , large arrays do take space , i need to write the sorting index routine for this large array in PBP next , not seen any examples where using large data arrays to sort as yet
cheers
Sheldon
Re: help clean up some code
Hi,
Generally, using nested IF/THENs produces less code than using AND. For example
Code:
IF A = 1 THEN
IF B = 2 THEN
IF C = 3 THEN
IF D = 4 THEN
IF E = 5 THEN
HIGH PortB.0
ENDIF
ENDIF
ENDIF
ENDIF
ENDIF
Compiled for a 16F628 is 30 words and 76 bytes for 18F4520 (all variables are bytes) while using AND, like this
Code:
IF (A = 1) AND (B = 2) AND (C = 3) AND (D = 4) AND (E = 5) THEN
HIGH PortB.0
ENDIF
takes 79 words for the 16F628 and 162 bytes for the 18F4520.
/Henrik.
Re: help clean up some code
how does this look ?
value var byte[6]
chk var byte
chknewval:
chk=0
while chk<6
if value[chk] = 0 then
value[chk]=newvalue
chk=6
else
if value[chk]=newvalue then ;we already have this value
chk=6
else
chk=chk+1
endif
endif
end while
return ?
Re: help clean up some code
I just learned something new about PBP! (Use of [brackets]). Thanks Richard!
Mike
Re: help clean up some code
i always knew the if , then way produces less words but with 30 "and" compares per test , if then way look really bad and hard to follow, there seems to be no really short way to do large compares for arrays
Re: help clean up some code
Hi,
I haven't looked into it in detail but perhaps you could use ARRAYREAD with the WAIT or WAITSTR modifer to do what you want?
Code:
Value VAR BYTE[6] ' Array of 6 bytes for the "new values"
DummyVAR 'Needed for ArrayWrite to do what we want - possibly
ARRAYREAD Value, 6, NoMatch, [WAIT("123456"), DummyVAR] ' Search the Value-array for 123456, jump to NoMatch if not found.
' Continue here if match is found
' ....
' ....
NoMatch:
' Continue here if no match was found
The above tries to match the array to a static string of 123456, if what you want to match is changing then use a second array for the "match condition" and use WAITSTR instead of WAIT. At least that's how I THINK it should work, I haven't actually tried it though.....
/Henrik.
Re: help clean up some code
THANKS HENDRICK , i not looked at that command , will investigate further , i finding it very hard for large arrays and indexing with match , i am working now on arrays using 78 variables per index per group match which 5 variable in the array need to be matched before adding / removing / reindexing , and then needs tobe saved , i have a lot of time before displaying the results on GLCD about 1 sec , i am finding that pbp need to to have more inbuilt functions in this area . iam looking at writing these sort of fuctions in asm , but my asm really need to improve
space is now becoming an issue
i may pm if thats ok
cheers
sheldon