M
mddawson - ExcelForums.com
I have a VBA program that I just created to process large amounts of
ECG data that works fine except for one little UI bug. Due to the
size of the data files which can have anywhere from 180,000+ to
600,000+ data points, I included a progress bar so that the user
could see how far along the program is when it is reading the source
data file and then down-converting (reducing the high frequency data
to low frequency data). The problem is that after a few refreshes,
the screen stops updating even though the program is still running;
thus from the user’s point of view the program appears to have
stalled despite the fact that it is still working.
This is not the first time I have had issues with the screen not
refreshing properly or Excel VBA code acting as if it is not present.
The way the program is coded, the progress bar form should be
repainted for every five percent increase in the processing of the
complete data set. At first the progress bar works fine, but about 60
to 75 percent into reading data from the source file screen refreshes
just stop. When the data is read, the progress bar should reset and
inform the user that it is converting the data set, but the progress
bar form remains frozen until the form is deactivated after data
processing is completed.
Here is a sample of the code from one of the progress bar forms:
Private Sub
UpdateECGProgressBar(progressCompleted As Double)
' Update progress bar for every five percent completed.
If progressCompleted * 100 >= progress Then
progress = progress + 5
lblProgressBar.Width = progressCompleted * 236
frmProcessECGData.Repaint
End If
End Sub
Private Sub AcquireECGData()
' Get BPM and ECG Data from text file created by BSL® Pro.
Dim filename As String
Dim fileHeader As String
Dim dataline As String
Dim fileNumber As Integer
Dim index As Long
Dim timeBase As Double
Dim dTime As Double
ReDim ecgSamples(1) As ECGDataType 'reset ECG data object
progress = 0
timeBase = 0#
dTime = 1 / ecgInputRate
filename = FindFilename(ecgSourceFile)
fileNumber = FreeFile
If filename <> "False" Then
'set default output filenames
ecgAvgFilename = Left(filename, Len(filename) -
4) & " - avg (ECG).txt"
ecgMaxFilename = Left(filename, Len(filename) -
4) & " - max (ECG).txt"
'open source file and strip header line
Open ecgSourceFile For Input As #fileNumber
Line Input #fileNumber, fileHeader
index = 1
While Not EOF(fileNumber)
'acquire ECG data from source file
ReDim Preserve ecgSamples(index) As ECGDataType
With ecgSamples(index)
Line Input #fileNumber, dataline
.BPM = CDbl(Left(dataline, InStr(dataline,
vbTab) - 1))
.mV = CDbl(Right(dataline, Len(dataline) -
InStrRev(dataline, vbTab)))
.sampleTime = timeBase + (index - 1) * dTime
End With
'update progress bar
Call UpdateECGProgressBar(index / nECGSamples)
index = index + 1
Wend
Close #fileNumber
End If
End Sub
Any ideas as to why Excel is choosing to ignore the
UpdateECGProgressBar code after a certain point? By the way, there
have been times when the program has worked as expected so it should
not be an issue with the code itself so much as it is an issue with
VBA Excel executing code that is clearly there.
ECG data that works fine except for one little UI bug. Due to the
size of the data files which can have anywhere from 180,000+ to
600,000+ data points, I included a progress bar so that the user
could see how far along the program is when it is reading the source
data file and then down-converting (reducing the high frequency data
to low frequency data). The problem is that after a few refreshes,
the screen stops updating even though the program is still running;
thus from the user’s point of view the program appears to have
stalled despite the fact that it is still working.
This is not the first time I have had issues with the screen not
refreshing properly or Excel VBA code acting as if it is not present.
The way the program is coded, the progress bar form should be
repainted for every five percent increase in the processing of the
complete data set. At first the progress bar works fine, but about 60
to 75 percent into reading data from the source file screen refreshes
just stop. When the data is read, the progress bar should reset and
inform the user that it is converting the data set, but the progress
bar form remains frozen until the form is deactivated after data
processing is completed.
Here is a sample of the code from one of the progress bar forms:
Private Sub
UpdateECGProgressBar(progressCompleted As Double)
' Update progress bar for every five percent completed.
If progressCompleted * 100 >= progress Then
progress = progress + 5
lblProgressBar.Width = progressCompleted * 236
frmProcessECGData.Repaint
End If
End Sub
Private Sub AcquireECGData()
' Get BPM and ECG Data from text file created by BSL® Pro.
Dim filename As String
Dim fileHeader As String
Dim dataline As String
Dim fileNumber As Integer
Dim index As Long
Dim timeBase As Double
Dim dTime As Double
ReDim ecgSamples(1) As ECGDataType 'reset ECG data object
progress = 0
timeBase = 0#
dTime = 1 / ecgInputRate
filename = FindFilename(ecgSourceFile)
fileNumber = FreeFile
If filename <> "False" Then
'set default output filenames
ecgAvgFilename = Left(filename, Len(filename) -
4) & " - avg (ECG).txt"
ecgMaxFilename = Left(filename, Len(filename) -
4) & " - max (ECG).txt"
'open source file and strip header line
Open ecgSourceFile For Input As #fileNumber
Line Input #fileNumber, fileHeader
index = 1
While Not EOF(fileNumber)
'acquire ECG data from source file
ReDim Preserve ecgSamples(index) As ECGDataType
With ecgSamples(index)
Line Input #fileNumber, dataline
.BPM = CDbl(Left(dataline, InStr(dataline,
vbTab) - 1))
.mV = CDbl(Right(dataline, Len(dataline) -
InStrRev(dataline, vbTab)))
.sampleTime = timeBase + (index - 1) * dTime
End With
'update progress bar
Call UpdateECGProgressBar(index / nECGSamples)
index = index + 1
Wend
Close #fileNumber
End If
End Sub
Any ideas as to why Excel is choosing to ignore the
UpdateECGProgressBar code after a certain point? By the way, there
have been times when the program has worked as expected so it should
not be an issue with the code itself so much as it is an issue with
VBA Excel executing code that is clearly there.