Convert Function to VB.NET

  • Thread starter Thread starter Al Reid
  • Start date Start date
A

Al Reid

I have a simple function that I use in many of my applications. It allows one to update the "Status" panel of a status bar and
optionally set the MousePointer. This is useful if the status is being changed to "Processing" and you want to show the Wait
cursor.

Public Sub UpdateStatusBar(ByVal Status As String, Optional ByVal Pointer As Long = -1)

sbrMain.Panels("Status") = Status

If Pointer <> -1 Then
Me.MousePointer = Pointer
End If

Me.Refresh

End Sub


This doesn't seem to convert properly using the Upgrade Wizard and I can't seem to find a proper conversion. I tried:

Public Sub UpdateStatusBar(ByVal Status As String, Optional ByVal Pointer As Cursor = Cursors.No)

But is says that the Optional parameter requires a constant Expression. It seems that Cursors is a class and that No is a property.

Any suggestions?
 
The windows forms has a status bar control you should check out:
System.Windows.Forms.StatusBar

You can change the cursor as follows:
Cursor.Current = System.Windows.Forms.Cursors.Default
 
H. Williams said:
The windows forms has a status bar control you should check out:
System.Windows.Forms.StatusBar

You can change the cursor as follows:
Cursor.Current = System.Windows.Forms.Cursors.Default

I know how to change the cursor. My question is how to correct the Function so that I don't need to rewrite all of the code that
calls this.
Can this be fixed or do I have to scrap it and start over?

Surely there must be a way to pass a mouse pointer to a function w/optional parameters.
 
Al said:
But is says that the Optional parameter requires a constant
Expression. It seems that Cursors is a class and that No is a
property.

The problem here is that Cursor.No is an object, and you can't use an object
as the default value for an optional parameter.

Here are two suggestions to work around this:

1. Use Nothing as the default value:

\\\
Public Sub UpdateStatusBar(ByVal Status As String, Optional ByVal Pointer As
Cursor = Nothing)
sbrMain.Panels("Status") = Status
If Not Pointer Is Nothing Then
Me.MousePointer = Pointer
End If
Me.Refresh
End Sub
///


2. Use overloaded procedures to obtain the same effect:

\\\
Public Overloads Sub UpdateStatusBar(ByVal Status As String)
sbrMain.Panels("Status") = Status
Me.Refresh
End Sub

Public Overloads Sub UpdateStatusBar(ByVal Status As String, ByVal Pointer
As Cursor)
'Delegate to other overload instance to do the statusbar work
UpdateStatusBar(Status)
'Now set the pointer
Me.MousePointer = Pointer
End Sub
///


Either of these should get you going without having to change lots of code.

Hope that helps,
 
Back
Top