Anyone Familiar With VisualBasic ?

Discussion in 'Archived Threads 2001-2004' started by Chuck C, Nov 5, 2002.

  1. Chuck C

    Chuck C Cinematographer

    Joined:
    Jan 6, 2001
    Messages:
    2,224
    Likes Received:
    1
    What's the code for making one shape appear and the other disapper? For example, let's say i have two option boxes--one the says circle and one that says oval. When you click circle a circle appears, when you click oval the circle disappears and the oval appears and vise versa.
    click the link to 1104.exe to see what i mean.
    can anyone crack this?!
     
  2. Tim Markley

    Tim Markley Screenwriter

    Joined:
    Jun 12, 1999
    Messages:
    1,279
    Likes Received:
    0
    Chuck - The shape (your circle or oval) object has a Shape property which determines what type of shape it is. Set it to 2 for Oval or 3 for Circle. Let me know if you need anything else.
     
  3. Chuck C

    Chuck C Cinematographer

    Joined:
    Jan 6, 2001
    Messages:
    2,224
    Likes Received:
    1
    I determined that....what I have trouble with is making one disappear as the other appears....they cancel each other out.

    --------------------

    Private Sub optcircle_Click()
    Shape1.Visible = False
    If optcircle.Value = True Then
    Picture2.Visible = True And Picture1.Visible
    Picture1.Circle (1000, 1000), 500

    End If
    End Sub
    -------------------------

    Private Sub optoval_Click()
    Shape1.Visible = False
    If optoval.Value = True Then
    Picture1.Visible = False And Picture2.Visible
    Picture2.Circle (1000, 1000), 1000, , , , 0.5

    End If
    End Sub


    ------------

    the above statements do not work
     
  4. Wayne Bundrick

    Wayne Bundrick Cinematographer

    Joined:
    May 17, 1999
    Messages:
    2,358
    Likes Received:
    0
    Am I missing something, does it have to be more complicated than the following?

    -----

    private sub optCircle_Click()
    shpOval.visible = false
    shpCircle.visible = true
    end sub

    private sub optOval_Click()
    shpCircle.visible = false
    shpOval.visible = true
    end sub

    -----

    That's if you have two different shape controls. As Tim said, you could use just one shape control and change its shape property to oval or circle. That's probably what the example program used, because it starts out as a square until you click on the oval or circle option buttons. (And there's no way to turn it back into a square.)

    I can't give the exact code to do it, because shape controls don't exist in the latest version of Visual Basic. Thank you Microsoft for randomly taking away functionality that you deem to have no value.

    -----

    And what's with this line?
    Picture1.Visible = False And Picture2.Visible

    Why not just say:
    Picture1.Visible = Not Picture2.Visible

    Because bugs like to hide in obscure code.
     
  5. Chuck C

    Chuck C Cinematographer

    Joined:
    Jan 6, 2001
    Messages:
    2,224
    Likes Received:
    1
    Wayne,
    Holy crap, I was thinking way too deep into that one. Thanks for the answer help [​IMG]...thanks to you too, Tim.
     
  6. Tim Markley

    Tim Markley Screenwriter

    Joined:
    Jun 12, 1999
    Messages:
    1,279
    Likes Received:
    0
    Yea, if you are using 2 shapes, then just use the Visible property. Very useful for hiding controls that you don't want seen at certain times.
     
  7. Brian Hepler

    Brian Hepler Stunt Coordinator

    Joined:
    Jan 6, 1999
    Messages:
    63
    Likes Received:
    0
     
  8. Wayne Bundrick

    Wayne Bundrick Cinematographer

    Joined:
    May 17, 1999
    Messages:
    2,358
    Likes Received:
    0
    In an IF statement, the boolean expression has an implied "answer" which will be either true or false, but otherwise it's just like any other math expression. The answer can be assigned to any variable, in this case the visibility property of Picture1.

    AND and other boolean operators are also used for bitwise manipulation: clearing and setting individual bits. When it gets right down to it, that's what logical boolean expressions are doing anyway. After manipulating the bits, the result is either zero (false) or nonzero (true).

    But as I already pointed out, it really obscures what you're trying to do, and bugs like to hide in obscure code. The simplest way to do it is:

    Picture1.Visible = NOT Picture2.Visible
     
  9. Chuck C

    Chuck C Cinematographer

    Joined:
    Jan 6, 2001
    Messages:
    2,224
    Likes Received:
    1
    How bout coding a vbYesNo message box?..."yes" exits the program and "no" takes you back to the original form

    right now i have:
    ------------
    If cmdExit.Value = True Then
    MsgBox "Are You Sure You Want To Exit?", vbYesNo, "Wait"
    If vbYes Then End
    If vbNo Then

    End If
    ---------------
    What's comes after the second Then?!
     
  10. Wayne Bundrick

    Wayne Bundrick Cinematographer

    Joined:
    May 17, 1999
    Messages:
    2,358
    Likes Received:
    0
    Assuming cmdExit is a plain ordinary button:

    Sub cmdExit_Click ()
    If MsgBox("Are you sure you want to exit?", vbYesNo, "Wait") = vbYes Then End
    End Sub
     
  11. Andrew Pratt

    Andrew Pratt Producer

    Joined:
    Dec 8, 1998
    Messages:
    3,806
    Likes Received:
    0
    why use a button for exit? GUI designers frown upon using buttons for Exiting programs. Try this instead

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Dim Response As VbMsgBoxResult

    Response = MsgBox("Are you sure you want to exit?", vbYesNo)
    If Response = vbYes Then
    Cancel = 0
    Else
    Cancel = 1
    End If
    End Sub
     
  12. Wayne Bundrick

    Wayne Bundrick Cinematographer

    Joined:
    May 17, 1999
    Messages:
    2,358
    Likes Received:
    0
    Just about every Control Panel applet has OK/Cancel buttons at the bottom.

    I think that people who don't have time to learn what GUI designers think is the cool GUI trend this year would prefer a large conspicuous button with obvious text that says what it will do over three little hieroglyphic buttons hiding in the corner.
     
  13. Andrew Pratt

    Andrew Pratt Producer

    Joined:
    Dec 8, 1998
    Messages:
    3,806
    Likes Received:
    0
    Maybe so I was only pointing out another option
     
  14. Chuck C

    Chuck C Cinematographer

    Joined:
    Jan 6, 2001
    Messages:
    2,224
    Likes Received:
    1
    thanks again Wayne and Andrew....

    I used both of your codes. Wayne's helped me figure the code for the YesNo message box that appear when clicking the Exit command button, and Andrews gives me a message box when clicking the red X (winXP) in the upper right hand corner.
    Without andrew's code, the red X would exit the program without a message box.


    if you guessed that i'm in an introductory VB class, you were right.
     
  15. Wayne Bundrick

    Wayne Bundrick Cinematographer

    Joined:
    May 17, 1999
    Messages:
    2,358
    Likes Received:
    0
    If you want both the Exit button and the red X button to do the same thing, you could do this:

    Sub cmdExit_Click()
    Unload Me
    End Sub

    Then clicking the Exit button will attempt to unload the form, but triggering the QueryUnload code first. This way there's no redundant code for two message boxes which say the same thing. Plus, it's a good idea for code to have only one exit point.
     

Share This Page