ok, here it is. i hope the comments are enough.
Notice the last lines :
'saveFileStream.Flush()
saveFileStream.Close()
'saveFile.Close()
if i uncomment them i get errors
thanx for the effort
'****** Loop in all the items in the listbox (files selected) and transform
them one by one *****
For Each inputFile In inputFilesArrayList
' after we select a file we proceed
'Create a file stream for reading from the file selected
Dim openFileStream As New FileStream(inputFile, FileMode.Open,
FileAccess.Read, FileShare.Read)
'Open a file associated with the opening stream and assign text encoding
Dim openFile As New StreamReader(openFileStream, System.Text.Encoding.ASCII)
'Create a file stream for writing to a file
'!!!!! NOTE: We keep the same path and we add a DLY extension !!!
Dim saveFileStream As New FileStream(inputFile + "DLY", FileMode.Create,
FileAccess.Write, FileShare.Write)
'open a file associated with the save Stream to write
Dim saveFile As New StreamWriter(saveFileStream, System.Text.Encoding.ASCII)
'***************************************************************************
*******
Try 'Put writing loop in a try-catch block
'---- load file contents in arraylist -------
Do
inputFileLine = openFile.ReadLine()
If Not inputFileLine Is Nothing Then
inputFileContentsArrayList.Add(inputFileLine)
End If
Loop Until inputFileLine Is Nothing
'---------------------------------------------
'------------- STEP 1 ------------------------
' -- READ data from arraylist
For Each LineStr In inputFileContentsArrayList
'Check each line length IF different than 233
If (LineStr.Length = 234 Or LineStr.Length = 233) Then
'extract Station ID , year , month , element code
tempLine.stationID = LineStr.Substring(0, 7)
tempLine.year = LineStr.Substring(7, 4)
tempLine.month = LineStr.Substring(11, 2)
tempLine.element = LineStr.Substring(13, 3)
'Loop in order to get data for the 31 days of the month on the same line
For i As Integer = 0 To 30
tempLine.value(i) = LineStr.Substring(16 + (i * 7), 7)
Next
'************************************************
'loop 31 times for every line in the array
For i As Integer = 0 To 30
saveFile.Write(tempLine.stationID)
saveFile.Write(delimiter + tempLine.year)
saveFile.Write(delimiter + tempLine.month)
saveFile.Write(delimiter + CStr(i + 1)) 'i+1 represents day
saveFile.Write(delimiter + tempLine.element)
saveFile.Write(delimiter + valid)
saveFile.Write(delimiter + tempLine.value(i))
saveFile.Write(vbCrLf)
Next
'************************************************
'IF file format is NOT correct, advise user and exit loop
Else
MsgBox("Le fichier n'as pas le propre format de 234 characters par ligne." +
vbCrLf + "SVP essayer de nouveau.")
Exit For
End If
Next
'*********************************************
Catch ex As Exception
MsgBox(ex.ToString)
Finally
'close preview file
openFileStream.Close()
openFile.Close()
'close save file
'saveFileStream.Flush()
saveFileStream.Close()
'saveFile.Close()
'empty file contents array
inputFileContentsArrayList.Clear()
'increase progress bar
pbrTransform.Value += 1
End Try
'***************************************************************************
*******
Next
'*************************** Main Loop for all files
***************************