|
-
Aug 17th, 2006, 12:57 AM
#1
Thread Starter
Junior Member
[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?
-
Aug 17th, 2006, 01:23 AM
#2
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.
-
Aug 17th, 2006, 01:59 AM
#3
Thread Starter
Junior Member
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?
-
Aug 17th, 2006, 02:19 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|