Results 1 to 4 of 4

Thread: [2005] Disable/Enable MenuItem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Location
    CA, USA
    Posts
    26

    [2005] Disable/Enable MenuItem

    Okay here is my problem. Once someone connects to the server I want a menu to be enabled. If he or she is not connected its disabled. So far I can connect to the server and make it show a message box. Once I click okay it closes, then comes the code

    Code:
    Public Sub ToolsToolStripMenuItem()
            Try
                conn.Open()
                MainFormReference.ToolsToolStripMenuItem.Enabled = True
    
            Catch ex As Exception
                If (conn.Close) Then
    
                End If
            End Try
        End Sub
    Where it says If (conn.Close) it produces and error (the conn.Close is underlined) and says Expression Does not Produce a Value.

    Can anyone help me fix this?
    ----------------------
    http://www.darkcore.co.nr

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Disable/Enable MenuItem

    Close is a method. It closes the connection. As the error message says, it does not return a value. Any expression you use in an If statement must be type Boolean, i.e. it must return either True or False. Close doesn't so it can't be used in an If statement. There's no point closing the connection there anyway. If an exception is thrown it will because the connection failed to open, so there's no need to close it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2006
    Location
    CA, USA
    Posts
    26

    Re: [2005] Disable/Enable MenuItem

    Then what code should I use so I can make it the menu enabled when the user connects to the server?
    ----------------------
    http://www.darkcore.co.nr

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Disable/Enable MenuItem

    You're already doing it. If the Open call succeeds then the following line, which enables the menu item, will be executed. If you want to disable the menu item if the connection fails then set the Enabled property to False in the Catch block.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width