PDA

View Full Version : VBA Sub Procedures; Homework



ladeda16
04-04-2008, 11:06 PM
I have this homework assignment that confuses the hell out of me. And i need help. I'm so confused please help me

ladeda16
04-04-2008, 11:21 PM
I think i got it now.

tstav
04-04-2008, 11:39 PM
Private Sub cmdStart_Click()
Call ToggleButtons(True)
End Sub
Private Sub cmdExit_Click()
Call ToggleButtons(False)
End Sub
Sub ToggleButtons(ByVal blnStart As Boolean)
cmdStart.Enabled = IIf(blnStart, False, True)
cmdSelect.Visible = IIf(blnStart, True, False)
cmdSelect.Enabled = IIf(blnStart, True, False)
cmdExit.Enabled = IIf(blnStart, True, False)
End Sub

mikerickson
04-05-2008, 12:41 AM
The buttons can "tell" themselves what to change to.

Sub ToggleButtons()
cmdStart.Enabled = Not (cmdStart.Enabled)
cmdSelect.Visible = Not (cmdStart.Enabled)
cmdSelect.Enabled = Not (cmdStart.Enabled)
cmdExit.Enabled = Not (cmdStart.Enabled)
End Sub

tstav
04-05-2008, 12:59 AM
ladeda's teacher will be thrilled, Mike!
I hope he doesn't flunk ladeda's work though, because he explicitly asked for a boolean argument in the ToggleButtons sub. He, he!
Ingenious, Mike.

mikerickson
04-05-2008, 01:18 AM
If an argument is required, how about two. This will either toggle or Enable the specified button:

Sub ToggleButtons(optional EnableStartButton as Boolean, optional EnableSelectExit as Boolean)
cmdStart.Enabled = (cmdStart.Enabled Imp EnableStartButton) Xor EnableSelectExit
cmdSelect.Visible = Not(cmdStart.Enabled)
cmdSelect.Enabled = Not(cmdStart.Enabled)
cmdExit.Enabled = Not(cmdStart.Enabled)
End Sub

tstav
04-05-2008, 01:25 AM
And since the assignment is hinting on the use of blnStart and Not blnStart
Private Sub cmdStart_Click()
Call ToggleButtons(True)
End Sub

Private Sub cmdExit_Click()
Call ToggleButtons(False)
End Sub

Sub ToggleButtons(ByVal blnStart As Boolean)
cmdStart.Enabled = Not blnStart
cmdSelect.Visible = blnStart
cmdSelect.Enabled = blnStart
cmdExit.Enabled = blnStart
End Sub

tstav
04-05-2008, 01:36 AM
If an argument is required, how about two. This will either toggle or Enable the specified button:

Sub ToggleButtons(optional EnableStartButton as Boolean, optional EnableSelectExit as Boolean)
cmdStart.Enabled = (cmdStart.Enabled Imp EnableStartButton) Xor EnableSelectExit
cmdSelect.Visible = Not(cmdStart.Enabled)
cmdSelect.Enabled = Not(cmdStart.Enabled)
cmdExit.Enabled = Not(cmdStart.Enabled)
End Sub

Yeah, right! I bet that'll rid ladeda of any confusion.

mdmackillop
04-05-2008, 02:51 AM
Too much of solutions being provided here. Please refer to our Homework guidance. (http://www.vbaexpress.com/forum/faq.php?faq=psting_faq_item#faq_hom_faq_item)

tstav
04-05-2008, 04:06 AM
Got it Malcolm. Thank you for ringing the bell...

ladeda16
04-05-2008, 09:05 AM
Hey guys, thanks for your time for helping, and i wasn't aware we could ask course work homework questions, i was wondering if someone could explain the process of how sub procedures work, if you can please AIM me at ladeda063610. I really need some help. Please contact me if you can.

ladeda16
04-05-2008, 09:12 AM
Private Sub cmdStart_Click()
Call ToggleButtons(True)
End Sub
Private Sub cmdExit_Click()
Call ToggleButtons(False)
End Sub
Sub ToggleButtons(ByVal blnStart As Boolean)
cmdStart.Enabled = IIf(blnStart, False, True)
cmdSelect.Visible = IIf(blnStart, True, False)
cmdSelect.Enabled = IIf(blnStart, True, False)
cmdExit.Enabled = IIf(blnStart, True, False)
End Sub


question?

Can you tell me what call togglebuttons(False) mean?

mdmackillop
04-06-2008, 01:47 AM
Ladeda,
You have deleted the content of your earlier posts, making this thread meaningless and wasting the time of all who have responded.
The purpose of this forum is to make the solution to questions available to alll who visit, not to assist you with your homework assignments.

Repetion of this type of editing will incur an immediate ban from the site.

Regards
MD