What's new

Anyone Familiar With VisualBasic ? (1 Viewer)

Chuck C

Senior HTF Member
Joined
Jan 6, 2001
Messages
2,224
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?!
 

Tim Markley

Screenwriter
Joined
Jun 12, 1999
Messages
1,279
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.
 

Chuck C

Senior HTF Member
Joined
Jan 6, 2001
Messages
2,224
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
 

Wayne Bundrick

Senior HTF Member
Joined
May 17, 1999
Messages
2,358
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.
 

Chuck C

Senior HTF Member
Joined
Jan 6, 2001
Messages
2,224
Wayne,
Holy crap, I was thinking way too deep into that one. Thanks for the answer help ;)...thanks to you too, Tim.
 

Tim Markley

Screenwriter
Joined
Jun 12, 1999
Messages
1,279
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.
 

Brian Hepler

Stunt Coordinator
Joined
Jan 6, 1999
Messages
63
Picture1.Visible = False And Picture2.Visible
Hello... interesting syntax. Isn't the AND keyword only used in boolean expressions? You know, "if x = 5 AND y=4" stuff?
If I read that code correctly, you are basically saying "If the Optcircle object is visible, then False" which doesn't do a whole lot. :)
 

Wayne Bundrick

Senior HTF Member
Joined
May 17, 1999
Messages
2,358
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
 

Chuck C

Senior HTF Member
Joined
Jan 6, 2001
Messages
2,224
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?!
 

Wayne Bundrick

Senior HTF Member
Joined
May 17, 1999
Messages
2,358
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
 

Andrew Pratt

Senior HTF Member
Joined
Dec 8, 1998
Messages
3,806
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
 

Wayne Bundrick

Senior HTF Member
Joined
May 17, 1999
Messages
2,358
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.
 

Chuck C

Senior HTF Member
Joined
Jan 6, 2001
Messages
2,224
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.
 

Wayne Bundrick

Senior HTF Member
Joined
May 17, 1999
Messages
2,358
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.
 

Users who are viewing this thread

Sign up for our newsletter

and receive essential news, curated deals, and much more







You will only receive emails from us. We will never sell or distribute your email address to third party companies at any time.

Forum statistics

Threads
357,071
Messages
5,130,070
Members
144,283
Latest member
Nielmb
Recent bookmarks
0
Top