Strange bug
Posted: Mon Jun 15, 2009 3:02 am
This took a bit of time to see and I still have no idea how the code got mangled. The code below compiled OK but crashed with an Invalid Memory Access at the 5th line with the cause being the 32nd line.Shouldn't the compiler catch errors like this.
This code was stable for several months before it started crashing and I do not recall editing it so am mystified how the m=m= got there.
BTW, this was under XP Pro & PB 4.30 final.
Code: Select all
ListViewGadget(#LIST_HOL_CFG,12,top+14,215,30,#PB_ListView_Clickselect)
y=Year(Date())
If ReadFile(0, "holiday.txt")
While Eof(0)=0
temp=UCase(Trim(StringField(ReadString(0),1,";"))) ;===============INVALID MEMORY ACCESS============
If Len(temp)>0
datecode=StringField(temp,2,"=")
temp=StringField(temp,1,"=")
If FindString(datecode,"/",1)
m=Val(StringField(datecode,1,"/")):d=Val(StringField(datecode,2,"/"))
If Date(y,m,d,0,0,0)<>-1
If StringField(datecode,2,",")="1"
weekday=DayOfWeek(Date(y,m,d,0,0,0))
If weekday=0:d+1:EndIf
If weekday=6
If d>1
d-1
Else
If m>1
m-1:d=32
While Date(y,m,d, 0, 0, 0)=-1:d-1:Wend
EndIf
EndIf
EndIf
EndIf
temp=RSet(Str(DayOfYear(Date(y,m,d, 0, 0, 0))),3,"0")+" "+temp
Else
temp = "INVALID DATECODE "+datecode
EndIf
Else
m=m=Val(StringField(datecode,3,",")) ;==============THIS LINE WAS THE CAUSE=================
d=GetDay(datecode)
If d>-1
temp=RSet(Str(DayOfYear(Date(y,m,d, 0, 0, 0))),3,"0")+" "+temp
Else
temp = "INVALID DATECODE "+datecode
EndIf
EndIf
AddGadgetItem(#LIST_HOL_CFG,-1,temp)
If Len(Trim(holidays))
holidays+","+StringField(temp,1," ")
Else
holidays+StringField(temp,1," ")
EndIf
EndIf
Wend
CloseFile(0)
EndIf
If DayOfWeek(Date(y,12,31,0,0,0))=5
temp=RSet(Str(DayOfYear(Date(y,12,31, 0, 0, 0))),3,"0")+" New Year's Day "+Str(y+1)
AddGadgetItem(#LIST_HOL_CFG,-1,temp)
EndIf
This code was stable for several months before it started crashing and I do not recall editing it so am mystified how the m=m= got there.
BTW, this was under XP Pro & PB 4.30 final.