The "fast" PB code.
Not sure I am allowed to show that, but I am interested by any comment, to improve me...
First, the .ini file:
Code: Select all
DIR01 = C:\Test\Serie1
DIR02 = C:\Test\Serie2
DIR03 = C:\Test\Serie3
of_nb_maxi = 2
Second, the PB code:
Code: Select all
EnableExplicit
; Scans some directories in which there are fabrication orders nnnnnn_bbb.suf, where
; nnnnnn is the fabrication order
; bbb is the benchmark number
; suf is the suffix of the file (.txt, .xls, etc.).
; when these files are found, there are displayed alltogether,
; finding the right application To open them.
; If found in one directory, it's sure they are not in another directory.
; There is a limited number of benchmark number. It's sure there will not have other one outside a List (001 002 003 at the beginning).
Global GTitre$, GTitre_commercial$
Gtitre$ = GetFilePart(ProgramFilename())
Gtitre$ = Left(GTitre$,Len(GTitre$) - 4) ; enlever le .exe
GTitre_commercial$ = "erp_fo_display"
; ----------------------------------------------------- mutex
IncludePath "..\Common"
XIncludeFile "Mutex_inc.pb"
Procedure mes(Plib$)
MessageRequester(GTitre$,Plib$)
EndProcedure
If mutex_create(GTitre_commercial$) = 0
mes(GTitre_commercial$ + " déjà en exécution")
End
EndIf
; ----------------------------------------------------- Global variables main
Global Gfini$ = GetCurrentDirectory () + GTitre_commercial$ + ".ini"
Global Gfo_nb_to_be_found$
; ----------------------------------------------------- Global variables ini file
#ini_dir$ = "DIR" ; followed by nn from 01 to 99. No discontinuity.
#ini_fo_nb_maxi$ = "of_nb_maxi"
Global NewList GL_dir$()
Global Gfo_nb_maxi.i
; -----------------------------------------------------
Procedure lect_ini ()
Define wcpt.i, wcpt$, wdir$
If FileSize(Gfini$) < 0
mes(Gfini$ + " absent.")
EndIf
OpenPreferences(Gfini$)
wcpt = 1
Repeat
wcpt$ = Str(wcpt)
If Len(wcpt$) = 1
wcpt$ = "0" + wcpt$
EndIf
wdir$ = ReadPreferenceString(#ini_dir$ + wcpt$,"")
If wdir$ <> ""
AddElement(GL_dir$())
GL_dir$() = wdir$
Else
Break
EndIf
wcpt + 1
ForEver
If ListSize(GL_dir$()) = 0
mes("Manque paramètre DIRnn= dans " + Gfini$ + ", nn allant de 0 à 99 sans trou.")
End
EndIf
Gfo_nb_maxi = ReadPreferenceInteger(#ini_fo_nb_maxi$,0)
If Gfo_nb_maxi = 0
mes("Manque paramètre " + #ini_fo_nb_maxi$ + "= dans " + Gfini$)
End
EndIf
ClosePreferences()
EndProcedure
Procedure accept_parameter ()
If CountProgramParameters() = 0
mes("Manque numéro d'ordre de fabrication comme paramètre.")
End
EndIf
Gfo_nb_to_be_found$ = ProgramParameter()
EndProcedure
Procedure display_file(Pdir$,Pfile$)
RunProgram(pdir$ + "\" + Pfile$)
EndProcedure
Procedure.i fo_nb_found_in_one_directory (Pdir$)
Define wno_dir.i, wnb_file_found.i
If FileSize(Pdir$) <> -2
ProcedureReturn 0
EndIf
wno_dir = ExamineDirectory(#PB_Any,Pdir$,Gfo_nb_to_be_found$ + "*.*")
If wno_dir = 0
ProcedureReturn 0
EndIf
wnb_file_found = 0
While NextDirectoryEntry(wno_dir)
If DirectoryEntryType(wno_dir) = #PB_DirectoryEntry_File
display_file(Pdir$,DirectoryEntryName(wno_dir))
wnb_file_found + 1
EndIf
Wend
FinishDirectory(wno_dir)
ProcedureReturn wnb_file_found
EndProcedure
Procedure.i scan_directories ()
Define wscan_dir.i
ResetList(GL_dir$())
While NextElement(GL_dir$())
wscan_dir = fo_nb_found_in_one_directory (GL_dir$())
If wscan_dir <> 0
Break
EndIf
Wend
ProcedureReturn wscan_dir
EndProcedure
;- BEGIN
lect_ini ()
accept_parameter ()
If scan_directories() = 0
mes("Aucun ordre de fabrication trouvé.")
EndIf
End
Mutex_inc.pb code in include (not important) :
Code: Select all
Procedure.i Mutex_create(Pmutex_name$)
Define wmutex.i
wmutex = CreateMutex_(0,1,Pmutex_name$)
If GetLastError_()=#ERROR_ALREADY_EXISTS
wmutex = 0
EndIf
ProcedureReturn wmutex
EndProcedure
Procedure Mutex_release(Pmutex.i)
ReleaseMutex_(Pmutex)
EndProcedure
It's run by the following .bat when the user clicks on a button in the ERP:
where 4567 is the beginning of the fabrication order to be found.
PureBasic 6.20 beta 2 (x64) | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled.
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).