What the matter? The program is always repair the file. HELP

Just starting out? Need help? Post your questions and find answers here.
zer0c0de
New User
New User
Posts: 6
Joined: Sun Oct 04, 2015 8:51 am

What the matter? The program is always repair the file. HELP

Post by zer0c0de »

Code: Select all

Procedure.s CalculateTime(Time$)
  If Mid(Time$,1,2) = "00"
  Time$ = ReplaceString(Time$,"00","01")
  ProcedureReturn Time$
EndIf

  If Mid(Time$,1,2) = "01"
  Time$ = ReplaceString(Time$,"01","02")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "02"
  Time$ = ReplaceString(Time$,"02","03")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "03"
  Time$ = ReplaceString(Time$,"03","04")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "04"
  Time$ = ReplaceString(Time$,"04","05")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "05"
  Time$ = ReplaceString(Time$,"05","06")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "06"
  Time$ = ReplaceString(Time$,"06","07")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "07"
  Time$ = ReplaceString(Time$,"07","08")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "08"
  Time$ = ReplaceString(Time$,"08","09")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "09"
  Time$ = ReplaceString(Time$,"09","10")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "10"
  Time$ = ReplaceString(Time$,"10","11")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "11"
  Time$ = ReplaceString(Time$,"11","12")
  ProcedureReturn Time$
EndIf
  If Mid(Time$,1,2) = "12"
  Time$ = ReplaceString(Time$,"12","13")
  ProcedureReturn Time$
EndIf
  
  If Mid(Time$,1,2) = "13"
  Time$ = ReplaceString(Time$,"13","14")
  ProcedureReturn Time$
EndIf
  
  If Mid(Time$,1,2) = "14"
  Time$ = ReplaceString(Time$,"14","15")
  ProcedureReturn Time$
  EndIf

  If Mid(Time$,1,2) = "15"
  Time$ = ReplaceString(Time$,"15","16")
  ProcedureReturn Time$
EndIf

  If Mid(Time$,1,2) = "16"
  Time$ = ReplaceString(Time$,"16","17")
  ProcedureReturn Time$
EndIf

If Mid(Time$,1,2) = "17"
  Time$ = ReplaceString(Time$,"17","18")
  ProcedureReturn Time$
EndIf

If Mid(Time$,1,2) = "18"
  Time$ = ReplaceString(Time$,"18","19")
  ProcedureReturn Time$
EndIf

If Mid(Time$,1,2) = "19"
  Time$ = ReplaceString(Time$,"19","20")
  ProcedureReturn Time$
EndIf

If Mid(Time$,1,2) = "20"
  Time$ = ReplaceString(Time$,"17","18")
  ProcedureReturn Time$
EndIf

If Mid(Time$,1,2) = "21"
  Time$ = ReplaceString(Time$,"21","22")
  ProcedureReturn Time$
EndIf

If Mid(Time$,1,2) = "22"
  Time$ = ReplaceString(Time$,"22","23")
  ProcedureReturn Time$
EndIf

If Mid(Time$,1,2) = "23"
  Time$ = ReplaceString(Time$,"23","00")
  ProcedureReturn Time$
EndIf

EndProcedure


Procedure Logging(file$)
  If CheckFile(file$) = -1
     OpenFile(0,file$)
     WriteString(0,FormatDate("%yyyy-%mm-%dd",Date())+" "+FormatDate("%hh:%ii:%ss",Date()))
     WriteString(0," - "+FormatDate("%yyyy-%mm-%dd",Date())+" ")
     WriteString(0,CalculateTime(FormatDate("%hh:%ii:%ss",Date())))
   ElseIf CheckFile(file$) = 1
     OpenFile(0,file$)
     date$ = StringField(r$,4," ")
     time$ = StringField(r$,5," ")
     If date$ < FormatDate("%yyyy-%mm-%dd",Date())
       Debug "Repair"
       CloseFile(0)
       DeleteFile(file$)
       OpenFile(0,file$)
       WriteString(0,FormatDate("%yyyy-%mm-%dd",Date())+" "+FormatDate("%hh:%ii:%ss",Date()))
       WriteString(0," - "+FormatDate("%yyyy-%mm-%dd",Date())+" ")
       WriteString(0,CalculateTime(FormatDate("%hh:%ii:%ss",Date())))
     EndIf 
     Debug "repaired"
   EndIf
   
EndProcedure

Logging(GetHomeDirectory()+"mydate.csv")

; The date is of the file 2016-02-09 how i can repair, that? If the date is greater like the current date just then repair the date of the  file?
__________________________________________________
Code tags added
09.02.2016
RSBasic
User avatar
spikey
Enthusiast
Enthusiast
Posts: 771
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: What the matter? The program is always repair the file.

Post by spikey »

That isn't going to work, your code will cause a cascade failure somewhere along the line every time.
What are you trying to do? If you tell us more about what you are trying to achieve we might be able to suggest something better.
zer0c0de
New User
New User
Posts: 6
Joined: Sun Oct 04, 2015 8:51 am

Re: What the matter? The program is always repair the file.

Post by zer0c0de »

This is a date checker program, but i would like to check the date, and if the date on the file is greater like the current date, just then repair the date of the file. Some reason the program is repair the date on the file but the date is the current date.
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: What the matter? The program is always repair the file.

Post by infratec »

Hi,

I didn't look closer, because I don't know from which file you are talking and which date,
but you compare strings and no date values

You should compare

Code: Select all

If ParseDate() < Date()
And if this is not the case your file stays open, because you have no close.
Also in the first case you only open the file.

Bernd
infratec
Always Here
Always Here
Posts: 7622
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: What the matter? The program is always repair the file.

Post by infratec »

A closer look:

I can not test something, since CheckFile() is not available.

But...
Your CalculateTime() will fail often, because ReplaceString() replaces every occurence
and not only the one you want.
And I think it's a bit complicated. What should it do?

Bernd
Post Reply