Restored from previous forum. Originally posted by CONVERT.
SortArray(tfich.s(),2) does not sort anything in the table (274 records of about 20 to 40 characteres).
If I put Delay(45) before OR after SortArray(tfich.s(),2), it works fine.
45 was determined by dichotomy in several tests.
(Windows 98 SE, AMD Duron 800 Mhz, 256 MB memory).
Is it normal?
Is it better writting Delay(45) before or after SortArray?
Thanks,
Jean.
Sortarray needs delay?
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by PB.
Could you post some code that shows this problem? Because needing a
delay is not right, and I feel it may just be a bug in your code.
Or, does it work if you use this: SortArray(tfich.s(),2,0,274)
You may just need to declare the range (0-274) at the end...
Could you post some code that shows this problem? Because needing a
delay is not right, and I feel it may just be a bug in your code.
Or, does it work if you use this: SortArray(tfich.s(),2,0,274)
You may just need to declare the range (0-274) at the end...
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by CONVERT.
I extract the procedure creating the sorted file, from the bigger program where it is. This procedure reads a text file into a table, sorts the table, and rewrites the table into the same file.
This isolated procedure works outside the bigger program.
The same code in the bigger program does not sort.
But, in the bigger program, if I rewrite in a different output file, it works, without delay(45).
May be the trouble comes from system buffer or cache...
Win 98 SE. The scan disk does not find any error on the disk. Diskeeper says the disks is OK (no fragmentation). 41 % free (12.7 GB free).
Here is the code :
; ----------------------- formating a number on long.l characters.
; called by the following procedure.
Procedure.s formatn(nombre.l,long.b)
w.s = Str(nombre.l)
If Len(w.s) > long.b
ProcedureReturn Right(w.s,long.b)
Else
nbzero.b=long.b - Len(w.s)
For i.b = 1 To nbzero.b
w.s = "0" + w.s
Next i
ProcedureReturn w.s
EndIf
EndProcedure
Procedure.s gener_aleat ()
; -------------------------------------- loading in table
Liberr$ = ""
Dim tfich.s (maxi.l)
nb_lect.l=0
If ReadFile(0, Fliste$) ; some times, there is an error. I run again
; without modification, and It's OK.
While Eof(0) = 0
enr.s = Trim(ReadString())
If enr.s ""
nombre.s = formatn(Random(maxi.l),6)
tfich.s(nb_lect.l) = nombre.s + enr.s
nb_lect.l = nb_lect.l + 1
EndIf
Wend
CloseFile(0)
Else
liberr$ ="Erreur : " + Fliste$ + " illisible." + Finerreur$
ProcedureReturn Liberr$
EndIf
; ------------------------- sort according to hasardous number
; Delay(45)
SortArray(tfich.s(),2,0,maxi.l)
; Delay(45)
; --------------- writing into the same file
If CreateFile(0, Fliste$)
For nb_lect.l = 0 To (maxi.l)
texte.s = tfich.s(nb_lect.l)
texte.s = Trim(Mid(texte.s,7,Len(texte.s) - 6))
If texte.s ""
WriteStringN(texte.s)
EndIf
Next nb_lect
CloseFile(0)
Else
Liberr$ ="ERREUR : Ecriture impossible de " + Fliste$
ProcedureReturn Liberr$
EndIf
ProcedureReturn Liberr$
EndProcedure
Thanks for your help.
Jean.
Same trouble with SortArray(tfich.s(),2,0,274)Originally posted by PB
Could you post some code that shows this problem? Because needing a
delay is not right, and I feel it may just be a bug in your code.
Or, does it work if you use this: SortArray(tfich.s(),2,0,274)
You may just need to declare the range (0-274) at the end...
I extract the procedure creating the sorted file, from the bigger program where it is. This procedure reads a text file into a table, sorts the table, and rewrites the table into the same file.
This isolated procedure works outside the bigger program.
The same code in the bigger program does not sort.
But, in the bigger program, if I rewrite in a different output file, it works, without delay(45).
May be the trouble comes from system buffer or cache...
Win 98 SE. The scan disk does not find any error on the disk. Diskeeper says the disks is OK (no fragmentation). 41 % free (12.7 GB free).
Here is the code :
; ----------------------- formating a number on long.l characters.
; called by the following procedure.
Procedure.s formatn(nombre.l,long.b)
w.s = Str(nombre.l)
If Len(w.s) > long.b
ProcedureReturn Right(w.s,long.b)
Else
nbzero.b=long.b - Len(w.s)
For i.b = 1 To nbzero.b
w.s = "0" + w.s
Next i
ProcedureReturn w.s
EndIf
EndProcedure
Procedure.s gener_aleat ()
; -------------------------------------- loading in table
Liberr$ = ""
Dim tfich.s (maxi.l)
nb_lect.l=0
If ReadFile(0, Fliste$) ; some times, there is an error. I run again
; without modification, and It's OK.
While Eof(0) = 0
enr.s = Trim(ReadString())
If enr.s ""
nombre.s = formatn(Random(maxi.l),6)
tfich.s(nb_lect.l) = nombre.s + enr.s
nb_lect.l = nb_lect.l + 1
EndIf
Wend
CloseFile(0)
Else
liberr$ ="Erreur : " + Fliste$ + " illisible." + Finerreur$
ProcedureReturn Liberr$
EndIf
; ------------------------- sort according to hasardous number
; Delay(45)
SortArray(tfich.s(),2,0,maxi.l)
; Delay(45)
; --------------- writing into the same file
If CreateFile(0, Fliste$)
For nb_lect.l = 0 To (maxi.l)
texte.s = tfich.s(nb_lect.l)
texte.s = Trim(Mid(texte.s,7,Len(texte.s) - 6))
If texte.s ""
WriteStringN(texte.s)
EndIf
Next nb_lect
CloseFile(0)
Else
Liberr$ ="ERREUR : Ecriture impossible de " + Fliste$
ProcedureReturn Liberr$
EndIf
ProcedureReturn Liberr$
EndProcedure
Thanks for your help.
Jean.
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm