Page 2 of 2

Posted: Tue Jan 24, 2006 3:47 pm
by SFSxOI
Then if a procedure returns a string, you can't make it a constant?

Posted: Wed Mar 25, 2009 3:46 pm
by Kwai chang caine
@PB
Thanks a lot my good PB for your great tips
I go to surprising you :shock:

KCC have write a little procedure, who use your splendid tips, to create the RES, and put it a the right place
Yes yes .....i know....you don't believe your two eyes....(I suppose you have two eyes :roll:)
KCC have created it alone, with his ten podgy fingers :D
And furthermore.....KCC have write it in two language.

KCC post the english language here....so the half english language like say my MASTER SROD :lol:

Code: Select all

; ResidentCreator created by KCC thanks to the great tips of PB
; http://www.purebasic.fr/english/viewtopic.php?p=120641#120641

Procedure CreationFichierResident(FilePath.s)
  
 NameFile.s = ReplaceString(GetFilePart(FilePath), ".pb", "")
  
 If FileSize(#PB_Compiler_Home + "Residents\" + NameFile + ".res") <> - 1 
    
  AnswerOverWrite = MessageRequester("ResidentCreator", "The file ''" + NameFile + ".res'' already exist, do you want to overwrite it ?", #PB_MessageRequester_YesNo ) 
     
  If AnswerOverWrite <> 6
   ProcedureReturn 0
  EndIf
  
  DeleteFile(#PB_Compiler_Home + "Residents\" + NameFile + ".res")   
 
 EndIf
  
 If RunProgram(#PB_Compiler_Home + "Compilers\pbcompiler.exe", FilePath + " /resident " + NameFile + ".res /IGNORERESIDENT", #PB_Compiler_Home + "Compilers\", #PB_Program_Wait|#PB_Program_Hide)

 While FileSize(#PB_Compiler_Home + "Compilers\" + NameFile + ".res") = - 1
   Delay(10)
  Wend

  CopyFile(#PB_Compiler_Home + "Compilers\" + NameFile + ".res", #PB_Compiler_Home + "Residents\" + NameFile + ".res") 
  DeleteFile(#PB_Compiler_Home + "Compilers\" + NameFile + ".res")
  MessageRequester("ResidentCreator", "The new file résident ''" + NameFile + ".res'', is created in the folder of résidents of PureBasic" + Chr(13) + "For use it, restart the PureBasic IDE.")
 EndIf 
 
EndProcedure

FileChoose$ = OpenFileRequester("Please, choose the Pbfile countain your constants", "c:\", "Resident PB|*.pb", 0)

If Trim(FileChoose$) <> ""
 CreationFichierResident(FileChoose$)
EndIf
Again thanks PB for sharing 8)

Posted: Wed Mar 25, 2009 5:58 pm
by Kwai chang caine
I have create this little code who make a PB file under C:\
This file control if all the constant you have created with the code above is good

1/ Create your RES with the above code
2/ Restart PB IDE
3/ Reload the same file who you have use for create RES in this code
4/ Load the "c:\TestResidents.pb" who just is created by this code
5/ Run TestResidents.pb and it list all your CONSTANT and his value you have created with the above code, for control she is all here and good

Code: Select all

Procedure ControleListeResident(SourceResident.s)
  
 ReadFile(1, SourceResident)    
 
 If FileSize("c:\TestResidents.pb") <> - 1
  DeleteFile("c:\TestResidents.pb")
 EndIf
  
 CreateFile(2 , "c:\TestResidents.pb")
 
 Repeat
  
  Donnee$ = ReadString(1)
  
  If Left(Trim(Donnee$), 1) = "#"
   
   NomConstante$ = StringField(Donnee$, 1, "=")
   
   If FindString(Donnee$, Chr(34), 1)
    WriteStringN(2, "Debug " + Chr(34) + NomConstante$ + " = " + Chr(34) + " + " + NomConstante$)
   Else
    WriteStringN(2, "Debug " + Chr(34) + NomConstante$ + " = " + Chr(34) + " + Str(" + NomConstante$ + ")")
   EndIf
    
  EndIf
  
 Until Eof(1) <> 0
 
 CloseFile(1)
 CloseFile(2)
 MessageRequester("ResidentControlor", "The file ''c:\TestResidents'' is created, load and run it in the IDE, for control all the CONSTANTS and his value.")
 
EndProcedure

FichierChoisi$ = OpenFileRequester("Please, choose the Pbfile countain your constants", "c:\", "Resident PB|*.pb", 0)

If Trim(FichierChoisi$) <> ""
 ControleListeResident(FichierChoisi$)
EndIf