I have a UI with 32 buttons, each write different things out to the parallel port. because they are all writing different things out I obviously don't want the user pressing a second button while the first one is still writing bits to the port. This brings me to my question, how can I disable the other buttons till the button that was pressed finished its commands?
I have a UI with 32 buttons, each write different things out to the parallel port. because they are all writing different things out I obviously don't want the user pressing a second button while the first one is still writing bits to the port. This brings me to my question, how can I disable the other buttons till the button that was pressed finished its commands?
Thanks for the help.
Best Regards
Welcome to vbforums Glad to have you as part of the community!
Ok to your question, what i would do is have a Boolean (True or False Variable) which you set to true at the start of the operation and false at the end. This way you just check if the variable is true on each command button if it is just exit sub.
Quick question are you using a control array? it would make your life easier,
Or if you are using a control array just loop through the controls and set the enabled property to false when a button is clicked and then set them back to true at the end of the event:
For i = 0 to 32
cmdButton(i).enabled=True (or false)
next i
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
I am still very much a novice to VB. I honestly don't really know where to start on this issue, so I would be open to the idea of using a control array if it would be easier. I looked into the boolean function idea earlier, but I couldn't seem to get it working correctly, hence why i am here, haha.
P11A and P11B are the names of two CommandButtons on my UI. When I try to start the VB program with the "P11B.Enabled = False" line in I get the following error message:
"Compile Error: Method or data member not found."
Something else I found that doesn't make any sense to me is when I type the first part (P11A.) it gives me only a few autocomplete options for what can follow the ".", the are: Count, Item, LBound, Ubound.
I tried adding this line:
"P11A.Item.Enabled = False"
But it gives me the following error:
"Compile Error: Argument not Optional."
Hopefully this makes more sense to one of you than it does to me. Thanks again for the help.
Have you considered using a combo box to list your 32 options? You could either do processing on the combo click event or, better, have a single button that causes the process currently selected in the combo to be executed.
I'd recommend using Button.Enabled = False while you're writing to the port then setting it back to True when you've finished. What method are you using to determine when all the data has been written? I'm not entirely certain, but there may be some hardware buffering in the PC which will not be under your control. This probably won't be as much of an issue with a parallel port as it would be with a serial, but it's worth considering anyway.
Last edited by trisuglow; Apr 12th, 2005 at 09:19 AM.
This world is not my home. I'm just passing through.
In reply to Rshields' Post #6, the problem you're having is that you are not referencing your button controls as an array. You have an array of buttons, so you must reference them like this.
VB Code:
P11B(0).Enabled = True
The Count, Item, etc. properties you are getting refer to the array, not the individual buttons that are in the array.
This world is not my home. I'm just passing through.
I think the problem is that you are using "Command" instead of "Command1".
Here is my suggestion for you (assuming you don't want to go with my combobox idea).
Start a new project and put a button on the form. Go to the properties for this button and set the Index Property to 0 (zero). Paste in the following code and adapt it for what you want.
VB Code:
Option Explicit
Private Sub Command1_Click(Index As Integer)
SetEnabled False
Select Case Index
Case 0:
'Do processing for first button here
MsgBox "First Button"
Case 1:
'Do processing for second button here
MsgBox "Second Button"
Case 2:
'etc.
MsgBox "Third Button"
Case Else
MsgBox "Unspecified Button"
End Select
SetEnabled True
End Sub
Private Sub Form_Load()
Dim i As Integer
Command1(0).Top = 80
Command1(0).Left = 80
For i = 1 To 7
Load Command1(i)
Command1(i).Top = Command1(i - 1).Top + 600
Command1(i).Left = 80
Command1(i).Visible = True
Next
End Sub
Private Sub SetEnabled(pEnabled)
Dim c As Control
For Each c In Controls
If c.Name = "Command1" Then c.Enabled = pEnabled
Next
End Sub
This world is not my home. I'm just passing through.
Do you have Option Explict on ?
Have you tried running with Full Compile.
If there is only one bit of advice that could be given to those new to VB (and even to some who have been using vb for years), it should be to require declaration of variables.
MS was 'very bad' not to have made that the default.
You can get to this setting via Tools / Options menu
(You may have to go to all your existing Forms, etc and place this at the top 'Option Explicit'. On future projects it will be done for you.)