B
Bill Schanks
I have a vs2005 Windows Form Project that has a form with 3 Progress
Meters on it. I would like to have a class that handles all updates to
this form. There will be multiple subs/functions that need to update
this form. Here is the class that I have now:
But it doesn't work. When first called it does. But the second call to
it does not work. I am getting a System.NullReferenceException.
Public Class clsProgress
Private m_frmProgress As Progress
Private Const m_sPROGRESS_FORM_NAME As String = "Progress"
Public Sub LoadProgress()
Dim f As Form
Dim bLoaded As Boolean
For Each f In My.Application.OpenForms
If UCase(f.Name) = UCase(m_sPROGRESS_FORM_NAME) Then
bLoaded = True
Exit For
End If
Next
If Not bLoaded Then
m_frmProgress = New Progress
m_frmProgress.Show()
End If
End Sub
Public Sub CloseProgress()
m_frmProgress.Close()
End Sub
Public Sub InitDownloadProgress(ByVal lMax As Long)
m_frmProgress.progDownload.Value = 0
m_frmProgress.progDownload.Maximum = lMax
Application.DoEvents()
End Sub
Public Sub IncrementDownloadProgress(ByVal lProgress As Long,
ByVal sUpdateText As String)
m_frmProgress.lblDownload.Text = sUpdateText
With m_frmProgress.progDownload
If .Value < .Maximum Then .Value = lProgress
Application.DoEvents()
End With
End Sub
Public Sub InitFileProgress1(ByVal lMax As Long)
If Not m_frmProgress.progFile1.Visible Then
m_frmProgress.lblFile1.Visible = True
m_frmProgress.progFile1.Visible = True
End If
m_frmProgress.progFile1.Value = 0
m_frmProgress.progFile1.Maximum = lMax
Application.DoEvents()
End Sub
Public Sub IncrementFileProgress1(ByVal lProgress As Long, ByVal
sUpdateText As String)
m_frmProgress.lblFile1.Text = sUpdateText
With m_frmProgress.progFile1
If .Value < .Maximum Then .Value = lProgress
Application.DoEvents()
End With
End Sub
Public Sub InitFileProgress2(ByVal lMax As Long)
If Not m_frmProgress.progFile2.Visible Then
m_frmProgress.lblFile2.Visible = True
m_frmProgress.progFile2.Visible = True
End If
m_frmProgress.progFile2.Value = 0
m_frmProgress.progFile2.Maximum = lMax
Application.DoEvents()
End Sub
Public Sub IncrementFileProgress2(ByVal lProgress As Long, ByVal
sUpdateText As String)
m_frmProgress.lblFile1.Text = sUpdateText
With m_frmProgress.progFile2
If .Value < .Maximum Then .Value = lProgress
Application.DoEvents()
End With
End Sub
End Class
Meters on it. I would like to have a class that handles all updates to
this form. There will be multiple subs/functions that need to update
this form. Here is the class that I have now:
But it doesn't work. When first called it does. But the second call to
it does not work. I am getting a System.NullReferenceException.
Public Class clsProgress
Private m_frmProgress As Progress
Private Const m_sPROGRESS_FORM_NAME As String = "Progress"
Public Sub LoadProgress()
Dim f As Form
Dim bLoaded As Boolean
For Each f In My.Application.OpenForms
If UCase(f.Name) = UCase(m_sPROGRESS_FORM_NAME) Then
bLoaded = True
Exit For
End If
Next
If Not bLoaded Then
m_frmProgress = New Progress
m_frmProgress.Show()
End If
End Sub
Public Sub CloseProgress()
m_frmProgress.Close()
End Sub
Public Sub InitDownloadProgress(ByVal lMax As Long)
m_frmProgress.progDownload.Value = 0
m_frmProgress.progDownload.Maximum = lMax
Application.DoEvents()
End Sub
Public Sub IncrementDownloadProgress(ByVal lProgress As Long,
ByVal sUpdateText As String)
m_frmProgress.lblDownload.Text = sUpdateText
With m_frmProgress.progDownload
If .Value < .Maximum Then .Value = lProgress
Application.DoEvents()
End With
End Sub
Public Sub InitFileProgress1(ByVal lMax As Long)
If Not m_frmProgress.progFile1.Visible Then
m_frmProgress.lblFile1.Visible = True
m_frmProgress.progFile1.Visible = True
End If
m_frmProgress.progFile1.Value = 0
m_frmProgress.progFile1.Maximum = lMax
Application.DoEvents()
End Sub
Public Sub IncrementFileProgress1(ByVal lProgress As Long, ByVal
sUpdateText As String)
m_frmProgress.lblFile1.Text = sUpdateText
With m_frmProgress.progFile1
If .Value < .Maximum Then .Value = lProgress
Application.DoEvents()
End With
End Sub
Public Sub InitFileProgress2(ByVal lMax As Long)
If Not m_frmProgress.progFile2.Visible Then
m_frmProgress.lblFile2.Visible = True
m_frmProgress.progFile2.Visible = True
End If
m_frmProgress.progFile2.Value = 0
m_frmProgress.progFile2.Maximum = lMax
Application.DoEvents()
End Sub
Public Sub IncrementFileProgress2(ByVal lProgress As Long, ByVal
sUpdateText As String)
m_frmProgress.lblFile1.Text = sUpdateText
With m_frmProgress.progFile2
If .Value < .Maximum Then .Value = lProgress
Application.DoEvents()
End With
End Sub
End Class