473,326 Members | 2,023 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Code for Button Click Event

I have code that I want to run so that if the result is true, it changes the
current button's ".DialogResult" property to "DialogResult.OK". Problem is,
when I run this code on the ".Click" event for the current button and then
run this code, if the ".DialogResult" property is change, it does not take
affect until the button is pressed again.

I do I workaround this?
Nov 20 '05 #1
11 10976
"Sarah" <sa********@powertechcanada.com> schrieb
I have code that I want to run so that if the result is true, it
changes the current button's ".DialogResult" property to
"DialogResult.OK". Problem is, when I run this code on the ".Click"
event for the current button and then run this code, if the
".DialogResult" property is change, it does not take affect until the
button is pressed again.

I do I workaround this?


Why don't you execute the code on the first click?
--
Armin

Nov 20 '05 #2

Why don't you execute the code on the first click?


I am executing the code on the buttons "click" event. When the code
evaluates to true, it changes the current buttons control ".DialogResult"
property to ".DialogResult.OK". The problem is, when I change this setting
in this buttons click event, the change does not take place right away -
i.e. since the button was already pressed, changing the property of it after
it is pressed is not having the desired result -- which is to change the
".DialogResult" property was this click event. (The .DialogResult.OK
property change only works for the next time the button is pressed_).

Any help would be appreciated to find out how to run code to change the
..DialogResult property so that the change would change the behavior of the
button right away.

Thanks.
Nov 20 '05 #3
"Sarah" <sa********@powertechcanada.com> schrieb

Why don't you execute the code on the first click?


I am executing the code on the buttons "click" event. When the
code evaluates to true, it changes the current buttons control
".DialogResult" property to ".DialogResult.OK". The problem is, when
I change this setting in this buttons click event, the change does
not take place right away - i.e. since the button was already
pressed, changing the property of it after it is pressed is not
having the desired result -- which is to change the ".DialogResult"
property was this click event. (The .DialogResult.OK property change
only works for the next time the button is pressed_).

Any help would be appreciated to find out how to run code to change
the .DialogResult property so that the change would change the
behavior of the button right away.


Whenever I change the dialogresult property it does change right away.
--
Armin

Nov 20 '05 #4

Whenever I change the dialogresult property it does change right away.

This is my scenerio:

- I launch a dialog box (form 2) from form 1 using "Dialog_AddName_Results =
CustomerName.ShowDialog()"
- On the dialog box, the "Add" button "DialogResult" property is set to
"None" by default
- On the "Add" button click event, some code evaluates to true or false
- If the above code evaluates to true, it sets "DialogResult" to OK (1)

The thing is, the dialog box does not close up right away - as when the
"Add" button was first pressed, the "DialogResult" was set to "None"

Hope that gets you to the point where I am. Is there an event that I can run
before the click event of the button that will run when the button is
clicked?
Nov 20 '05 #5
Why don't you just set the Form.DialogResult property in your button, then
close the form?
(Read that in the SDK.... but you may just "Hide" the form, closing it may
free the resources)

"Sarah" <sa********@powertechcanada.com> wrote in message
news:xn*********************@news2.telusplanet.net ...

Whenever I change the dialogresult property it does change right away.

This is my scenerio:

- I launch a dialog box (form 2) from form 1 using "Dialog_AddName_Results

= CustomerName.ShowDialog()"
- On the dialog box, the "Add" button "DialogResult" property is set to
"None" by default
- On the "Add" button click event, some code evaluates to true or false
- If the above code evaluates to true, it sets "DialogResult" to OK (1)

The thing is, the dialog box does not close up right away - as when the
"Add" button was first pressed, the "DialogResult" was set to "None"

Hope that gets you to the point where I am. Is there an event that I can run before the click event of the button that will run when the button is
clicked?

Nov 20 '05 #6
Dont set the DialogResult property on the button, set it on the form, then
as I said, close or hide the form.

"Sarah" <sa********@powertechcanada.com> wrote in message
news:xn*********************@news2.telusplanet.net ...

Whenever I change the dialogresult property it does change right away.

This is my scenerio:

- I launch a dialog box (form 2) from form 1 using "Dialog_AddName_Results

= CustomerName.ShowDialog()"
- On the dialog box, the "Add" button "DialogResult" property is set to
"None" by default
- On the "Add" button click event, some code evaluates to true or false
- If the above code evaluates to true, it sets "DialogResult" to OK (1)

The thing is, the dialog box does not close up right away - as when the
"Add" button was first pressed, the "DialogResult" was set to "None"

Hope that gets you to the point where I am. Is there an event that I can run before the click event of the button that will run when the button is
clicked?

Nov 20 '05 #7
"Sarah" <sa********@powertechcanada.com> schrieb

Whenever I change the dialogresult property it does change right
away.

This is my scenerio:

- I launch a dialog box (form 2) from form 1 using
"Dialog_AddName_Results = CustomerName.ShowDialog()"
- On the dialog box, the "Add" button "DialogResult" property is set
to "None" by default
- On the "Add" button click event, some code evaluates to true or
false - If the above code evaluates to true, it sets "DialogResult"
to OK (1)

The thing is, the dialog box does not close up right away - as when
the "Add" button was first pressed, the "DialogResult" was set to
"None"

Hope that gets you to the point where I am. Is there an event that I
can run before the click event of the button that will run when the
button is clicked?


I still don't understand. Why don't you simply put

If <evaluationIsTrue> Then
Me.DialogResult = Dialogresult.Ok
Me.Close
End If

in the button's click event? Now you don't have to click twice.
--
Armin

Nov 20 '05 #8
Then, the calling form does not get the information via :

"Dialog_AddName_Results = CustomerName.ShowDialog()"


Nov 20 '05 #9
Yes it does, Armin is right. The result you get from ShowDialog is the
result that's currently in the Form's DialogResult property, so, in your
button click event, do this:

Me.DialogResult = DialogResult.OK
Me.Close

The returned value will be DialogResult.OK, and the form will close.

--
HTH,
-- Tom Spink, Über Geek

Please respond to the newsgroup,
so all can benefit

"Maybe it's a game called 'Punish the User'"
"Sarah" <sa********@powertechcanada.com> wrote in message
news:oo*********************@news2.telusplanet.net ...
Then, the calling form does not get the information via :

"Dialog_AddName_Results = CustomerName.ShowDialog()"

Nov 20 '05 #10
"Sarah" <sa********@powertechcanada.com> schrieb
Then, the calling form does not get the information via :

"Dialog_AddName_Results = CustomerName.ShowDialog()"

Here it does get the result.

Code in Form2, Button_Click:

Me.DialogResult = DialogResult.OK
Me.Close()

Code in Form1:
Dim result As DialogResult
Dim f As New Form2
result = f.ShowDialog
MsgBox(result.ToString)

The msgbox shows "OK"
--
Armin

Nov 20 '05 #11
Hello,

"Sarah" <sa********@powertechcanada.com> schrieb:
Then, the calling form does not get the information via :

"Dialog_AddName_Results = CustomerName.ShowDialog()"


Why not? Did you try it? For me, it works as expected.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Mathew Hill | last post by:
I am a beginner to the more technical aspects of Microsoft Access (2000) and was wondering if any one can help. I have 3 buttons on a form which add, delete and search for a record. However, when I...
6
by: Sally | last post by:
I need to be able to click in a subform and run code but at the same time I need to be able to scroll the records without running the code. I tried coding the Enter event of the subform control but...
1
by: Stephen | last post by:
Hey Everyone, I have a problem with a web application due to the use of both client-side and server side script on the on-click event of a button. The client side script runs first as expected...
1
by: Stephen | last post by:
Hey All, I have a problem with a web application due to the use of both client-side and server side script on the on-click event of a button. The client side script runs first as expected however...
3
by: John | last post by:
Hi On my webform, in design mode when I double click on the button component, it creates a click sub for me. But when I add code to the click event and run the web form the code does not seem to...
1
by: bennett | last post by:
At http://www.brainjammer.com/testing/validator_test.aspx I have a text field where you can enter text, and a button where if you click the button, it sets the value of a label below it, to...
4
by: Craig831 | last post by:
First off, I apologize if this gets long. I'm simply trying to give you all enough information to help me out. I'm writing (almost finished, actually), my first VB.Net application. It's a forms...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
21
by: Ben | last post by:
Hello I have frames set up in an asp.net application and need one frame to refresh another. Seeing as events need to be registered at the time the page is sent from the server, I was wondering...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.