Import File - ProgressBar

Hi everybody, salut tout le monde (voir la fin du message)

How can I do to know what I read ?
I know the byte’s number of my file :

BackupProgress.maximum=f.Length // nb of byte from file

But when I read my file, how can I know how many byte I read ?
It’s for my Progressbar.
I have see textInput.PositionB for my text, Why we haven’t : textInput.Length ???

Compteur =  Compteur+textInput.PositionB // How many byte I read ??

Here’s my code :

[code] Dim Compteur as integer
Compteur = 0
Dim f As FolderItem
Dim textInput As TextInputStream
Dim rowFromFile, oneCell As String
Dim i As Integer
f = GetOpenFolderItem(“text/plain”) //defined as a FileType
If f <> Nil And f.Exists Then

BackupProgress.Visible =true
BackupProgress.maximum=f.Length // nb of byte from file

Dim tab As String = ChrB(9)
textInput = TextInputStream.Open(f)
While Not textInput.EOF
  
  rowFromFile = textInput.ReadLine
  Compteur =  Compteur+textInput.PositionB // How many byte I read ??
  BackupProgress.Value = Compteur
  
  Dim row As New DatabaseRecord
  // Donnes importes
  'row.Column("ID") = NthField(rowFromFile, tab, 1)
  row.Column("Nom") = NthField(rowFromFile, tab, 3)
  row.Column("Prenom") = NthField(rowFromFile, tab, 4)
  row.Column("Naissance") =NthField(rowFromFile, tab, 5)
  row.Column("Homme") = NthField(rowFromFile, tab, 7)
  row.Column("CA") = NthField(rowFromFile, tab, 8)
  row.Column("Pays") =NthField(rowFromFile, tab, 9)
  
  // Donnes alatoires
  Dim r As New Random
  dim d as double
  d=r.Number * 100
  Dim Aleatoire as Integer
  Dim Maintenant As New Date
  Aleatoire = d * val(NthField(rowFromFile, tab, 8))
  row.Column("Photo") = ""
  row.Column("Document") = ""
  row.Column("Volume") = Str(d) 
  row.Column("Ville") =""
  row.Column("Heure") = Maintenant.LongTime
  row.Column("TimeStamp") = Maintenant.SQLDateTime
  
  mDB.InsertRecord("PERSONNE", row)
  
Wend
textInput.Close
Beep
T_Info.Text = "Import termin"
BackupProgress.Visible =false

End If[/code]

How can I optimize , it’s correct ?

Pour les franais :

Voil je cherche l’instruction qui me permet d’avoir le nombre d’octet lu lors d’un import.
C’est pour avoir une progression du chargement a indiquer dans un thermo (ProgressBar).
J’'ai trouv : f.Length, qui permet d’avoir la taille en octet du fichier.
Mais comment avoir le nombre d’octet lu, ou autres informations sur la lecture ou import du fichier ??
J’ai trouv : textInput.PositionB, mais cela ne semble pas fonctionner !
Il n’y aurait pas une instruction pour cela, je ne l’ai pas trouv.
Analyser le nombre de caractre lu dans la boucle ?
Il va de soit que prendre f.Length est le point de dpart pour la lecture.
Pour l’export ce sera plus simple car je connais le nombre d’enregistrement exporter :wink:

Pour les experts, mon code est-il correct ?
Peut-on l’optimiser ?
Comme je dbute, je m’amuse avec le code. Ce n’est pas pour un projet final.
Je regarde en peu en dtail (et profondeur) ce que l’on peut faire avec XOJO en base de donne.
J’ai fait quelques tests d’import d’un million d’enregistrement et affichage dans une ListBox, cela est assez cool.
Et rapide.
Mon but final et de laisser de cot 4D, mais avant il y a encore du chemin.
(Je commence mme prendre les habitudes XOJO, quand je programme avec 4D c’est bon signe !)

J’ai vu qu’il y avait quelques franais sur le forum, alors pourquoi crire en anglais !
Les experts ne sont pas que anglophones :wink:

Merci tous

You can get the length of a file by first opening it as a binarystream and saving it’s length property.

I think It’s what I do ?
(To get the length on open file, why ‘binary stream’ it’s a text file : TextInputStream

It’s not what I wait like a answer.
Or I can’t You understand what you mean.
Can you more explain ?

Binary stream has a length property, textinputstream does not, so to get the length of the text file you can open it first as a binary stream, save the length property, close it and open it as a text input stream. Now that you know the length you can keep a track of how many bytes you’ve read (using readline I assume) and calculate the percentage complete to update your progress bar.

Also note that progressbar maximum is limited to 65536 which is quite a small file, so calculating percentage complete is a better way.

FolderItem.length isn’t accurate in most cases.

[code] Dim Compteur as Int64
Compteur = 0
Dim f As FolderItem
Dim textInput As TextInputStream
Dim rowFromFile, oneCell As String
Dim i As Integer

Dim bs As BinaryStream //*
Dim Size As Int64 //*

f = GetOpenFolderItem(“text/plain”) //defined as a FileType
If f <> Nil And f.Exists Then

bs = BinaryStream.Open(f) //*
Size = bs.length //*
bs.close //*
BackupProgress.Visible =true

BackupProgress.Maximum = 100 //*

Dim tab As String = ChrB(9)
textInput = TextInputStream.Open(f)
While Not textInput.EOF
  
  rowFromFile = textInput.ReadLine

 
  Compteur = Compteur + LenB(rowFromFile) //*
  BackupProgress.Value = (Compteur / Size) * 100 //*
  BackupProgress.Refresh //* Forces refresh in tight loop

[/code]

This updated portion of code should give you a usable progress bar. I’ve commented changed lines with //*

HTH

Wayne

Change your progress code to read:

compteur = compteur + LenB(rowFromFile)

I think that’ll get what you want.

Thank Greg and Wayne,
I will try this.