Results 1 to 12 of 12

Thread: Question on Buttons

Hybrid View

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

  2. #2

    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?

  3. #3
    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.

  4. #4
    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