[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?
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.
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?
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.