S
steve
Hello,
I have been working on this piece of code that's supposed to read from a
file - transform - preview and finally save the transformed data.
I can read the file and with RichtextBox.LoadFile( ) i can display it on
the first box.
Then, in a for loop i read line by line , extract the information and (the
idea is) to put the transformed data in another RichText Box so that the
user can decide wether to save them in a file or not.
However i noticed that with files of around 1Meg and more , the process
slows down and freezes ! There is no exception raised, or i don't see it in
my Try block ... , the MaxSize for the textbox cannot be increased futher,
and I have tried everything except calling the CG explicitly but i don't see
the point in this piece of code.
Please help. I have spend hours on this and can't figure out what could be
wrong.
TIA
*******************************************************************
Try 'Put writing loop in a try-catch block
'*********************************************
'Main Loop over all lines of Global ArrayList
'------------- STEP 1 ------------------------
' -- READ data from global array into structure
For Each LineStr In globalArrayListIN
'Check each line length IF different than 233
If (LineStr.Length = 234 Or LineStr.Length = 233) Then
'increase progress bar
pbrTransform.Value += 1
'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
'------------- STEP 2 ------------------------
'-- ADD lines to the Transformed preview pane
rtbTransformed.AppendText(tempLine.stationID)
rtbTransformed.AppendText(delimiter + tempLine.year)
rtbTransformed.AppendText(delimiter + tempLine.month)
rtbTransformed.AppendText(delimiter + tempLine.element)
For i As Integer = 0 To 3
rtbTransformed.AppendText(delimiter + tempLine.value(i))
Next
rtbTransformed.AppendText(vbCrLf)
'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
pbrTransform.Value = 0 'clear progress bar
End Try
I have been working on this piece of code that's supposed to read from a
file - transform - preview and finally save the transformed data.
I can read the file and with RichtextBox.LoadFile( ) i can display it on
the first box.
Then, in a for loop i read line by line , extract the information and (the
idea is) to put the transformed data in another RichText Box so that the
user can decide wether to save them in a file or not.
However i noticed that with files of around 1Meg and more , the process
slows down and freezes ! There is no exception raised, or i don't see it in
my Try block ... , the MaxSize for the textbox cannot be increased futher,
and I have tried everything except calling the CG explicitly but i don't see
the point in this piece of code.
Please help. I have spend hours on this and can't figure out what could be
wrong.
TIA
*******************************************************************
Try 'Put writing loop in a try-catch block
'*********************************************
'Main Loop over all lines of Global ArrayList
'------------- STEP 1 ------------------------
' -- READ data from global array into structure
For Each LineStr In globalArrayListIN
'Check each line length IF different than 233
If (LineStr.Length = 234 Or LineStr.Length = 233) Then
'increase progress bar
pbrTransform.Value += 1
'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
'------------- STEP 2 ------------------------
'-- ADD lines to the Transformed preview pane
rtbTransformed.AppendText(tempLine.stationID)
rtbTransformed.AppendText(delimiter + tempLine.year)
rtbTransformed.AppendText(delimiter + tempLine.month)
rtbTransformed.AppendText(delimiter + tempLine.element)
For i As Integer = 0 To 3
rtbTransformed.AppendText(delimiter + tempLine.value(i))
Next
rtbTransformed.AppendText(vbCrLf)
'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
pbrTransform.Value = 0 'clear progress bar
End Try
