Convert Function to VB.NET

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Al Reid

    Convert Function to VB.NET

    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?

    --

    Al Reid


  • H. Williams

    #2
    Re: Convert Function to VB.NET

    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.D efault



    "Al Reid" <areidjr@reidDA SHhome.com> wrote in message
    news:e$bwZHoSFH A.1384@TK2MSFTN GP09.phx.gbl...[color=blue]
    >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?
    >
    > --
    >
    > Al Reid
    >
    >[/color]


    Comment

    • Al Reid

      #3
      Re: Convert Function to VB.NET

      "H. Williams" <hwilliams@osla w.com> wrote in message news:%23lDf5KoS FHA.1440@TK2MSF TNGP15.phx.gbl. ..[color=blue]
      >
      > "Al Reid" <areidjr@reidDA SHhome.com> wrote in message
      > news:e$bwZHoSFH A.1384@TK2MSFTN GP09.phx.gbl...[color=green]
      > >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?
      > >
      > > --
      > >
      > > Al Reid
      > >
      > >[/color]
      >
      >
      > 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.D efault
      >
      >[/color]

      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 Reid


      Comment

      • Oenone

        #4
        Re: Convert Function to VB.NET

        Al Reid wrote:[color=blue]
        > But is says that the Optional parameter requires a constant
        > Expression. It seems that Cursors is a class and that No is a
        > property.[/color]

        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,

        --

        (O) e n o n e


        Comment

        • Al Reid

          #5
          Re: Convert Function to VB.NET

          Thank you. Using Nothing as the default solved the problem

          --
          Al Reid

          "It ain't what you don't know that gets you into trouble. It's what you know
          for sure that just ain't so." --- Mark Twain

          "Oenone" <oenone@nowhere .com> wrote in message news:Jzvbe.7209 $TT6.1859@newsf e3-win.ntli.net...[color=blue]
          > Al Reid wrote:[color=green]
          > > But is says that the Optional parameter requires a constant
          > > Expression. It seems that Cursors is a class and that No is a
          > > property.[/color]
          >
          > 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,
          >
          > --
          >
          > (O) e n o n e
          >
          >[/color]


          Comment

          Working...