Visual Basic: Friday, July 7th, 2000 <----- Due July 14th .... Take home quiz #1 .... Here are four possible versions of the Rock, Paper, Scissors problem we tried out in lab class this morning. Recall that there were three different images that had DragMode enabled. I have named them imgRock, imgPaper, and imgScissors. I gave the imgScissors object the Tag property of "Scissors", so it can be identified by the trash barrel DragDrop() event, i.e. so we can check the Source object's Tag property to see if its equal to "Scissors". Source.Tag = "Scissors" is a condition that is either True or False. ----------------------- 1. Which solution of the four do you like the best? Why? 2. Which solution of the four do you like the least? Why? ' Use the Edit toolbar to quickly Comment or ' Uncomment and entire block (or selection) of code. ' View menu, Toolbars command, Edit to display Edit toolbar. ' The Comment Block button is the 9th button, Uncomment Block ' button is the 10th button. Solution #1 ----------------------------------------------------------------------------- 'Private Sub imgTrash_DragDrop(Source As Control, X As Single, Y As Single) ' If Source.Tag = "Scissors" Then ' If imgRock.Visible = True Or imgPaper.Visible = True Then ' MsgBox "Sorry, scissors must be thrown away last!" ' Exit Sub ' End If ' End If ' Source.Visible = False 'End Sub Solution #2 ----------------------------------------------------------------------------- 'Private Sub imgTrash_DragDrop(Source As Control, X As Single, Y As Single) ' If Source.Tag = "Scissors" And _ ' (imgRock.Visible Or imgPaper.Visible) Then ' MsgBox "Sorry, scissors has to be last item thrown." ' Else ' Source.Visible = False ' End If 'End Sub 4. What would happen if you took the parentheses out of the above If Then statement Or expression? Would the code be more or less understandable? Would the code still be correct without the ()s? Solution #3 ----------------------------------------------------------------------------- Private Sub imgTrash_DragDrop(Source As Control, X As Single, Y As Single) If Source.Tag <> "Scissors" Then Source.Visible = False ElseIf imgPaper.Visible Or imgRock.Visible Then MsgBox "Sorry. Scissors must be last item." Else imgScissors.Visible = False End If End Sub Solution #4 ----------------------------------------------------------------------------- Private Sub imgTrash_DragDrop(Source As Control, x As Single, y As Single) Source.Visible = False If Source.Tag = "Scissors" Then If imgRock.Visible Or imgPaper.Visible Then Source.Visible = True MsgBox "Scissors is thrown away last of all." End If End If End Sub 4. How would the readability of the Visual Basic event DragDrop event procedures be effected if the names used were Image1, Image2, Image3 and Image4 instead of imgRock, imgPaper, imgScissors, and imgTrash? 5. Is there an advantage to seeing if you can do something a different way and then developing that way and testing it out? 6. What do the waggle dancing bees have to do with trying to develop different possible approaches to solving the same problem? See the Ghostbusters and Waggle Dancing Bees handouts you received in one of the June lab classes along with this handout. 7. The above examples illustrate Or, And, <>, nested If statements, ElseIf clauses, Tags, the Source parameter to DragDrop events, and the creativity of programming. Discuss how Dr. Raymond Stantz (played by Dan Akroyd in Ghostbusters) aspect of problem solving would benefit from the above exercise of theme and variations? Hint: Mobilize and mobilization. See Ghostbusters handout. Reread the waggle dancing bees handout. Integrate something of what you have learned from studing those two handouts into your answer to this question. To answer this question, you should reflect on the entire take-home quiz set of questions. This take home quiz is due on Wednesday, July 12th. Do NOT turn in this handout. Instead turn in a separate sheet or sheets of paper with your answers and discussion of the issues.