Results 1 to 12 of 12

Thread: Question on Buttons

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    6

    Question on Buttons

    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

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: Question on Buttons

    Quote Originally Posted by Rshields
    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,

    Pino

  3. #3
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Re: Question on Buttons

    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    6

    Re: Question on Buttons

    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.

    Thanks,
    Rob

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: Question on Buttons

    Show us your code.

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    6

    Re: Question on Buttons

    Here is one instance of a button click:

    VB Code:
    1. Private Sub P11A_Click(Index As Integer)
    2. Out 888, 1
    3. Out 888, 3
    4. Out 888, 4
    5. Out 890, 1
    6. P11B.Enabled = False
    7. End Sub

    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.

  7. #7
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Question on Buttons

    I haven't tested this, but I think the concept should work -
    VB Code:
    1. Option Explicit
    2.  
    3. Private bP11_is_Processing As Boolean
    4.  
    5. Private Sub cmdP11_Click(Index As Integer)
    6.   If bP11_is_Processing Then
    7.     Exit Sub '<== Exit Sub
    8.   End If
    9.  
    10.   bP11_is_Processing = True
    11.   Select Case Index
    12.   Case 0
    13.     'Code to do work goes here
    14.   Case 1
    15.     'Code to do work goes here
    16.   Case 2
    17.     'Code to do work goes here
    18.   End Select
    19.  
    20.   bP11_is_Processing = False
    21. End Sub
    If you like you could have a Label that displays 'Busy' whilst it is busy.
    Rob C

  8. #8
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Question on Buttons

    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.

  9. #9
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Question on Buttons

    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:
    1. 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.

  10. #10

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Posts
    6

    Re: Question on Buttons

    Hey, I tried the following:

    VB Code:
    1. For i = 0 to 32
    2. Command(i).Enabled = False
    3. next i

    with i as an integer. It gave me the following error when I try to click the button:

    Runtime error 13: Type mismatch.

    Any ideas?

  11. #11
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536

    Re: Question on Buttons

    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:
    1. Option Explicit
    2. Private Sub Command1_Click(Index As Integer)
    3.   SetEnabled False
    4.   Select Case Index
    5.     Case 0:
    6.       'Do processing for first button here
    7.       MsgBox "First Button"
    8.     Case 1:
    9.       'Do processing for second button here
    10.       MsgBox "Second Button"
    11.     Case 2:
    12.       'etc.
    13.       MsgBox "Third Button"
    14.     Case Else
    15.       MsgBox "Unspecified Button"
    16.   End Select
    17.   SetEnabled True
    18. End Sub
    19. Private Sub Form_Load()
    20.   Dim i As Integer
    21.   Command1(0).Top = 80
    22.   Command1(0).Left = 80
    23.   For i = 1 To 7
    24.     Load Command1(i)
    25.     Command1(i).Top = Command1(i - 1).Top + 600
    26.     Command1(i).Left = 80
    27.     Command1(i).Visible = True
    28.   Next
    29. End Sub
    30. Private Sub SetEnabled(pEnabled)
    31.   Dim c As Control
    32.   For Each c In Controls
    33.     If c.Name = "Command1" Then c.Enabled = pEnabled
    34.   Next
    35. End Sub
    This world is not my home. I'm just passing through.

  12. #12
    Fanatic Member
    Join Date
    Mar 2002
    Location
    AUSTRALIA
    Posts
    603

    Re: Question on Buttons

    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.)
    Attached Images Attached Images  
    Rob C

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