943,589 Members | Top Members by Rank

Ad:
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Mar 29th, 2009
-7

Re: Apply code to 'x' button on form

http://www.vb6.us/files/Image/Hello-...al-screen5.jpg

Look at this image

You see where the two drop down boxes say Command1 and Click?

Change that to say form1, and the second one to say (i think its either Terminate or onClose, will have a lightning bolt symbol next to it)

That will create a code block. In there you can type whatever you want to happen when they try to close the form
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is offline Offline
16,485 posts
since Apr 2005
Mar 29th, 2009
0

Re: Apply code to 'x' button on form

@koolsid

Does this code just disable the 'x' button?

Thats the conclusion im drawing from your image there.
It not only disable's the close button but also removes the 'close' option from the form's shortcut menu

The API is very simple... All you need to do is copy and paste the code in the general declaration of the area....

Edit: Attaching a project sample for you
Attached Files
File Type: zip rabbithaveit.zip (2.1 KB, 26 views)
Last edited by koolsid; Mar 29th, 2009 at 3:04 pm.
Reputation Points: 11
Solved Threads: 6
Light Poster
koolsid is offline Offline
35 posts
since Feb 2005
Mar 29th, 2009
0

Re: Apply code to 'x' button on form

Quote ...
Nah, unfortunately that didnt work hkdani. But thanks for the post
That's funny: it works on my vb6 program. Actually, that's the method that I learned from a Microsoft CD on VB6 programming fundamentals. I've been using that method for years. It's odd that it doesn't work for you.

What I like about the method that Microsoft recommends is it's simplicity. That's why they made Visual Basic, because they knew that programs could be written faster and programmers could be more productive, if they were provided a simple way to perform a task such as the task you describe.

From what I've read and studied from the established authors and programmers, they always recommend the KISS method: Keep it Simple Stupid.

Yes, it's true that you can use API's. And it looks quite impressive. But in the end, in the real world it's all about achieving a desired end within a certain time frame.

If you can't achieve that end with the tools that VB6 provides, then VB6 has the flexibility of being able to call the Windows APIs from the Platform Software Developer Kit (PSDK). But as a general rule, use the tools that VB6 provides and only venture into APIs if VB6 doesn't provide the means to accomplish your end.

When it comes right down to where the rubber meets the road the end user will never see your code. He only sees your program. The programmer should not try to impress someone with his knowledge of Windows APIs, the end user probably doesn't have a clue as to what an API is.

Knowledge tends to puff people up. But a truly great programmer uses his knowledge to meet the needs of his client not to enhance his ego.
Reputation Points: 49
Solved Threads: 44
Posting Pro in Training
hkdani is offline Offline
426 posts
since Nov 2007
Mar 29th, 2009
0

Re: Apply code to 'x' button on form

@Koolsid

I actually want the 'x' enabled. But I want to apply code to it.

@Jbennet

Thanks, that worked. Just one problem. Whether Yes or NO is chosen. The program still closes. Any reason why?
Reputation Points: 10
Solved Threads: 0
Light Poster
rabbithaveit is offline Offline
32 posts
since Mar 2009
Mar 29th, 2009
1

Re: Apply code to 'x' button on form

@Koolsid

I actually want the 'x' enabled. But I want to apply code to it.

@Jbennet

Thanks, that worked. Just one problem. Whether Yes or NO is chosen. The program still closes. Any reason why?
Oh Ok I understand

Is this what you want?

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  2. If UnloadMode = vbFormControlMenu Then
  3. Ret = MsgBox("Do You want to Exit?", vbOKCancel)
  4. '~~> If user decides against it...
  5. If Ret = vbCancel Then Cancel = 1
  6. End If
  7. End Sub
Reputation Points: 11
Solved Threads: 6
Light Poster
koolsid is offline Offline
35 posts
since Feb 2005
Mar 29th, 2009
1

Re: Apply code to 'x' button on form

Check the attachement file..
I hope that it will help you...
Attached Files
File Type: zip X button.zip (5.8 KB, 76 views)
KSS
Reputation Points: 11
Solved Threads: 3
Newbie Poster
KSS is offline Offline
21 posts
since Mar 2009
Mar 29th, 2009
0

Re: Apply code to 'x' button on form

Gentlemen / Women...People

Thank you so very much for your suggestions and help, I really do appreciate it.

I have not yet gotten to try the zip files. But I am going to test them now. Again, I do appreciate it.

-Russell aka Rabbit
Reputation Points: 10
Solved Threads: 0
Light Poster
rabbithaveit is offline Offline
32 posts
since Mar 2009
Mar 29th, 2009
0

Re: Apply code to 'x' button on form

KSS and Sidz

You have both my thanks!

@Sidz, the zip file you gave me actually helped with another situation I had. lol One less thread to start up. Because I want my icons to show. So thank you.

@KSS, the zip you gave was EXACTLY what I was looking for. Thank again.

Now that I think of it...That final snippet you provided Sidz was the same thing in the zip KSS gave. Thanks again.

I do appreciate it.

Thread Solved!

-Russell aka Rabbit
Reputation Points: 10
Solved Threads: 0
Light Poster
rabbithaveit is offline Offline
32 posts
since Mar 2009
Mar 29th, 2009
-7

Re: Apply code to 'x' button on form

No problem. Glad you got it solved.
Moderator
Featured Poster
Reputation Points: 1764
Solved Threads: 574
Moderator
jbennet is offline Offline
16,485 posts
since Apr 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: how to use the keypress function is visual basic 6
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Searching for records contained in access from VB





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC