+ Reply to Thread
Results 1 to 3 of 3

VBA Sub Procedures

  1. #1
    Registered User
    Join Date
    03-16-2008
    Posts
    3

    VBA Sub Procedures

    I have this homework assignment that confuses the hell out of me. And i need help. I'm so confused please help me

    When you open the Excel file, you will only see two buttons, Start and Exit. Now, click on the Design Mode button, you will see the third button, Select. This is because the buttons have an additional property Visible, in addition to the Enabled property that you used in MP4. In this part, you will create a subprocedure that sets the Enabled and Visible properties of the three buttons, Start, Select, and Exit. You can see that in the file given to you, the Start button is enabled and visible, Select button is disabled and invisible, and Exit button is disabled and visible.
    The voting process is started when the user clicks on the Start button. When voting starts, Start button should get disabled, Select button should get enabled and visible, and Exit button should get enabled. When the voting process ends, the user clicks on the Exit button and then the exact opposite should happen: Start button should get enabled, Select button should get disabled and invisible, and Exit button should get disabled (Like the way it is initially in the file given to you).
    Here is a summary of the desired functionality:

    * Start voting
    o Start button disabled
    o Select button visible
    o Select button enabled
    o Exit button enabled

    blnStart = True

    * Stop voting
    o Start button enabled
    o Select button invisible
    o Select button disabled
    o Exit button disable

    blnStart = False

    Notice how Start voting and Stop voting change the same set of properties but in complete opposite value. Since, we want to either do a set of actions or just the opposite set of actions, we do not need to write two subprocedures. We can write one sub-procedure which takes a Boolean input and does one set of actions when the input is True and does the opposite set of actions when the input is False. In other words, the buttons can be enabled/disabled or made visible/invisible depending on the value of this boolean variable.
    Do the following in your VBA Editor:

    1. Declare a subprocedure called ToggleButtons that takes in one Boolean input, blnStart.
    2. Write 4 lines of code that uses the subprocedure's input to assign the 4 properties: cmdStart.Enabled, cmdSelect.Visible, cmdSelect.Enabled, and cmdExit.Enabled. The input will be True if the user is starting the voting process and False if the user is ending the voting process. Remember that the Enabled and Visible properties are also Boolean values, so you can assign them blnStart or Not blnStart.
    3. Update the subprocedures cmdStart_Click and cmdExit_Click to call the subprocedure ToggleButtons that you just created and pass in an appropriate value for the input.

    Test: If things are working correctly, you should be able to click on the Start button to have the buttons change to the desired status. The Exit button should then be enabled for you to click, and you will be back to the original state. If your buttons disappear while testing the code that you wrote, you can go into Design mode and change the enabled and visible properties through the Properties window. However, finally you should have them as desired by the MP.

  2. #2
    Registered User
    Join Date
    03-16-2008
    Posts
    3
    Here is what i got

    Please Login or Register  to view this content.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You are being asked to create one sub procedure that can be called by the buttons. This is what your project is asking for

    Please Login or Register  to view this content.
    You could make it slightly more efficient with less code

    Please Login or Register  to view this content.
    There's not really any need to set a Boolean to determine what to do because the button status is a Boolean. This code does exactly what you want simply by changing the buttons' status

    Please Login or Register  to view this content.
    Last edited by royUK; 04-05-2008 at 03:15 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1