Two more traps that I have fallen into recently that might help someone else avoid the same pitfalls.:
1.)
No error message is generated by the code below but the array is corrupted. It took a bit of finding. The bad code seemed to work OK under PBDLL 5 but not under PBDLL 6. DIM should of course have been REDIM.
'.....................................
FUNCTION PBMAIN() AS LONG
GLOBAL mystring AS STRING*10
.
call myprocedure(mystring)
.
call myprocedure(mystring)
END FUNCTION
........................................
SUB myprocedure(mystring AS STRING*10)
.
.
DIM mystring(100)
.
END SUB
2. Logic shortcuts we frequently use can become second nature to us so we often do not check through the code carefully enough as I was recently caught out.
To check if a string is not empty we often use the following:
To check if a substring is in a main string we often use:
However, these cannot be safely combined with an AND to test whether both conditions are satisfied eg.
If LEN(mystring) returned 10 and INSTR(mainstring,mystring) returned 1 then:
LEN(mystring) AND INSTR(mainstring,mystring) actually returns 0 even though both our requirements are satisfied because of the way that the AND operator works.
We need to use a structure like that below with both components returning -1:
Regards,
Bern
------------------
Bern
www.insighttrading.com.au
[This message has been edited by Bernard Chapman (edited August 26, 2001).]
1.)
No error message is generated by the code below but the array is corrupted. It took a bit of finding. The bad code seemed to work OK under PBDLL 5 but not under PBDLL 6. DIM should of course have been REDIM.
'.....................................
FUNCTION PBMAIN() AS LONG
GLOBAL mystring AS STRING*10
.
call myprocedure(mystring)
.
call myprocedure(mystring)
END FUNCTION
........................................
SUB myprocedure(mystring AS STRING*10)
.
.
DIM mystring(100)
.
END SUB
2. Logic shortcuts we frequently use can become second nature to us so we often do not check through the code carefully enough as I was recently caught out.
To check if a string is not empty we often use the following:
Code:
IF LEN(mystring) THEN . END IF
Code:
IF INSTR(mainstring,mystring) THEN . END IF
Code:
IF LEN(mystring) AND INSTR(mainstring,mystring) THEN . END IF
LEN(mystring) AND INSTR(mainstring,mystring) actually returns 0 even though both our requirements are satisfied because of the way that the AND operator works.
We need to use a structure like that below with both components returning -1:
Code:
IF LEN(mystring)>0 AND INSTR(mainstring,mystring)>0 THEN . END IF
Bern
------------------
Bern
www.insighttrading.com.au
[This message has been edited by Bernard Chapman (edited August 26, 2001).]
Comment