Call button click event

Y

Young

I've got a form with the following controls:

txt1, txt2, txt3 and btn1, btn2 and btn3.

When the user double clicked on the text box (txt1 to txt3), I will to click the corresponding buttons (btn1, btn2 or btn3).

I can do the following in the text box double click event:

select case sender.name
case txt1.name: btn1.perform_click
case txt2.name: btn2.perform_click
case txt3.name: btn3.perform_click
end select

This works only if I know how many text boxes are in the form. If I load the text boxes and buttons at run time, may not know how many text boxes I have so I cannot use the Select Case statement to check for which text box is double clicked.

I've try the following:

Dim sv_str_BtnId As String
Dim sv_ctl_Controls() as Button
sv_str_BtnId = "btn" & Replace(sender.name, "txt", "") - this will return btn1 to btnX depending on whch text box is double clickedon.

' Now I try to find the controls.
sv_ctl_Controls = Me.Controls.Find(sv_str_BtnId, False)

If UBound(sv_ctl_Controls) <> -1 Then
sv_ctl_Controls(0).PerformClick()
End If

This does not work at all - the button is not clicked.

Can someone please help?
 
A

Armin Zingler

Young said:
I've got a form with the following controls:

txt1, txt2, txt3 and btn1, btn2 and btn3.

When the user double clicked on the text box (txt1 to txt3), I will
to click the corresponding buttons (btn1, btn2 or btn3).

I can do the following in the text box double click event:

select case sender.name
case txt1.name: btn1.perform_click
case txt2.name: btn2.perform_click
case txt3.name: btn3.perform_click
end select

This works only if I know how many text boxes are in the form. If I
load the text boxes and buttons at run time, may not know how many
text boxes I have so I cannot use the Select Case statement to check
for which text box is double clicked.

I've try the following:

Dim sv_str_BtnId As String
Dim sv_ctl_Controls() as Button
sv_str_BtnId = "btn" & Replace(sender.name, "txt", "") - this will
return btn1 to btnX depending on whch text box is double clickedon.

' Now I try to find the controls.
sv_ctl_Controls = Me.Controls.Find(sv_str_BtnId, False)

If UBound(sv_ctl_Controls) <> -1 Then
sv_ctl_Controls(0).PerformClick()
End If

This does not work at all - the button is not clicked.

Can someone please help?


In addition to Peter: (I've dropped two inappropriate groups from my reply)

My 2c:

I never understood why anybody wants to "perform a click". That's done by
the user only. Performing a click by code is a detour. What you really want
to do is: Double-clicking a Textbox performs the same action as clicking a
button.

(BTW, a plain-text message read and written using a fixed point font like
Courier New is common practice)

textbox doubleclick button click
\ /
+-------+-------+
|
V
Action

So, the (p-)code is:

sub textbox doubleclick handler
call action
end sub

sub button click handler
call action
end sub

sub action
whatever
end sub


Consequently, you don't have to find a button in your Textbox' DoubleClick
event handler.


In addition, I've never cared about the name of a control (it's name
property) at runtime. I do not say you mustn't, too, but I can easily
identify a control by comparing the reference. This is safer because the
compiler isn't able to find typos in string literals, and it's much faster.
Therefore, I suggest using:

if sender is txt1 then
elseif sender is txt2 then
elseif sender is txt3 then
'...
end if


(BTW 2, names like "sv_str_BtnId" are hard to read)
(BTW 3, "sv_ctl_Controls.Length <>0" can be used instead of
"UBound(sv_ctl_Controls)<>-1")



Armin
 
A

Armin Zingler

Young said:
I've got a form with the following controls:

txt1, txt2, txt3 and btn1, btn2 and btn3.

When the user double clicked on the text box (txt1 to txt3), I will
to click the corresponding buttons (btn1, btn2 or btn3).

I can do the following in the text box double click event:

select case sender.name
case txt1.name: btn1.perform_click
case txt2.name: btn2.perform_click
case txt3.name: btn3.perform_click
end select

This works only if I know how many text boxes are in the form. If I
load the text boxes and buttons at run time, may not know how many
text boxes I have so I cannot use the Select Case statement to check
for which text box is double clicked.

I've try the following:

Dim sv_str_BtnId As String
Dim sv_ctl_Controls() as Button
sv_str_BtnId = "btn" & Replace(sender.name, "txt", "") - this will
return btn1 to btnX depending on whch text box is double clickedon.

' Now I try to find the controls.
sv_ctl_Controls = Me.Controls.Find(sv_str_BtnId, False)

If UBound(sv_ctl_Controls) <> -1 Then
sv_ctl_Controls(0).PerformClick()
End If

This does not work at all - the button is not clicked.

Can someone please help?


In addition to Peter: (I've dropped two inappropriate groups from my reply)

My 2c:

I never understood why anybody wants to "perform a click". That's done by
the user only. Performing a click by code is a detour. What you really want
to do is: Double-clicking a Textbox performs the same action as clicking a
button.

(BTW, a plain-text message read and written using a fixed point font like
Courier New is common practice)

textbox doubleclick button click
\ /
+-------+-------+
|
V
Action

So, the (p-)code is:

sub textbox doubleclick handler
call action
end sub

sub button click handler
call action
end sub

sub action
whatever
end sub


Consequently, you don't have to find a button in your Textbox' DoubleClick
event handler.


In addition, I've never cared about the name of a control (it's name
property) at runtime. I do not say you mustn't, too, but I can easily
identify a control by comparing the reference. This is safer because the
compiler isn't able to find typos in string literals, and it's much faster.
Therefore, I suggest using:

if sender is txt1 then
elseif sender is txt2 then
elseif sender is txt3 then
'...
end if


(BTW 2, names like "sv_str_BtnId" are hard to read)
(BTW 3, "sv_ctl_Controls.Length <>0" can be used instead of
"UBound(sv_ctl_Controls)<>-1")



Armin
 
A

Armin Zingler

Mike said:
. . . pardon?


?

His message is displayed as HTML. If he display my message with a dynamic
font also, my small "graphic" isn't displayed correctly.

(I see now it's called "fixed-width font" in the US docs; if that was your
point)


Armin
 
A

Armin Zingler

Mike said:
. . . pardon?


?

His message is displayed as HTML. If he display my message with a dynamic
font also, my small "graphic" isn't displayed correctly.

(I see now it's called "fixed-width font" in the US docs; if that was your
point)


Armin
 
M

Mike Williams

BTW, a plain-text message read and written using
a fixed point font like Courier New is common practice

[Mike wrote;] . . . pardon?
? His message is displayed as HTML. If he display my message
with a dynamic font also, my small "graphic" isn't displayed
correctly. (I see now it's called "fixed-width font" in the US
docs; if that was your point)

No. My point was that your statement, "a plain text message using a fixed
point font like Courier New" seems to be self contradictory, at least as far
as the author of the message is concerned. To my own mind a plain text
message is exactly that, a plain text message, and it therefore contains no
font information at all, in the same way that a standard .txt file contains
no font information. Unless newsgroups deal with such things differently
(which I suspect they do not) then as far as a plain text message is
concerned it is up to the app that displays the message at the receiving end
to determine the font that is used to display the plain text, and the choice
of font at the viewing end is therefore something over which the author of
the plain text message has no control. Perhaps you meant to say, "a HTML
message with the font set to a fixed width font"?

Mike
 
M

Mike Williams

BTW, a plain-text message read and written using
a fixed point font like Courier New is common practice

[Mike wrote;] . . . pardon?
? His message is displayed as HTML. If he display my message
with a dynamic font also, my small "graphic" isn't displayed
correctly. (I see now it's called "fixed-width font" in the US
docs; if that was your point)

No. My point was that your statement, "a plain text message using a fixed
point font like Courier New" seems to be self contradictory, at least as far
as the author of the message is concerned. To my own mind a plain text
message is exactly that, a plain text message, and it therefore contains no
font information at all, in the same way that a standard .txt file contains
no font information. Unless newsgroups deal with such things differently
(which I suspect they do not) then as far as a plain text message is
concerned it is up to the app that displays the message at the receiving end
to determine the font that is used to display the plain text, and the choice
of font at the viewing end is therefore something over which the author of
the plain text message has no control. Perhaps you meant to say, "a HTML
message with the font set to a fixed width font"?

Mike
 
A

Armin Zingler

Mike said:
BTW, a plain-text message read and written using
a fixed point font like Courier New is common practice

[Mike wrote;] . . . pardon?
? His message is displayed as HTML. If he display my message
with a dynamic font also, my small "graphic" isn't displayed
correctly. (I see now it's called "fixed-width font" in the US
docs; if that was your point)

No. My point was that your statement, "a plain text message using a
fixed point font like Courier New" seems to be self contradictory,

I did not write this! I wrote "*read and written* using a fixed point font".
You are creating a wrong context by improperly leaving out parts of the
sentence.


Armin
 
A

Armin Zingler

Mike said:
BTW, a plain-text message read and written using
a fixed point font like Courier New is common practice

[Mike wrote;] . . . pardon?
? His message is displayed as HTML. If he display my message
with a dynamic font also, my small "graphic" isn't displayed
correctly. (I see now it's called "fixed-width font" in the US
docs; if that was your point)

No. My point was that your statement, "a plain text message using a
fixed point font like Courier New" seems to be self contradictory,

I did not write this! I wrote "*read and written* using a fixed point font".
You are creating a wrong context by improperly leaving out parts of the
sentence.


Armin
 
C

Cor Ligthert[MVP]

Armin,

What did you write to Herfried lately?

You did it 95% perfect, not as perfect as Mike W of course but if you both
want to discuss this OT thing, I think he can do this better in a German
newsgroup.

:)

Cor
 
C

Cor Ligthert[MVP]

Armin,

What did you write to Herfried lately?

You did it 95% perfect, not as perfect as Mike W of course but if you both
want to discuss this OT thing, I think he can do this better in a German
newsgroup.

:)

Cor
 
A

Armin Zingler

Cor said:
Armin,

What did you write to Herfried lately?

You did it 95% perfect, not as perfect as Mike W of course but if you
both want to discuss this OT thing, I think he can do this better in
a German newsgroup.

:)

.. . . pardon?



Armin
 
A

Armin Zingler

Cor said:
Armin,

What did you write to Herfried lately?

You did it 95% perfect, not as perfect as Mike W of course but if you
both want to discuss this OT thing, I think he can do this better in
a German newsgroup.

:)

.. . . pardon?



Armin
 
C

Cor Ligthert[MVP]

Was written wrong, my intention was:

You both can maybe better discuss if you were using correct English in a
German newsgroup.

It is always easy for a native English speaker to discuss with persons like
us if something is right written in English or not.

But as we use our own native language it becomes suddenly a bit easier, you
write well English so why would Mike not try it once in German.

Seems to me a fair deal

Cor
 
C

Cor Ligthert[MVP]

Was written wrong, my intention was:

You both can maybe better discuss if you were using correct English in a
German newsgroup.

It is always easy for a native English speaker to discuss with persons like
us if something is right written in English or not.

But as we use our own native language it becomes suddenly a bit easier, you
write well English so why would Mike not try it once in German.

Seems to me a fair deal

Cor
 
A

Armin Zingler

Cor said:
Was written wrong, my intention was:

You both can maybe better discuss if you were using correct English
in a German newsgroup.

It is always easy for a native English speaker to discuss with
persons like us if something is right written in English or not.

But as we use our own native language it becomes suddenly a bit
easier, you write well English so why would Mike not try it once in
German.
Seems to me a fair deal

I understand your words but I don't see what it should tell me. Anyway, it's
OT.


Armin
 
A

Armin Zingler

Cor said:
Was written wrong, my intention was:

You both can maybe better discuss if you were using correct English
in a German newsgroup.

It is always easy for a native English speaker to discuss with
persons like us if something is right written in English or not.

But as we use our own native language it becomes suddenly a bit
easier, you write well English so why would Mike not try it once in
German.
Seems to me a fair deal

I understand your words but I don't see what it should tell me. Anyway, it's
OT.


Armin
 
M

Mike Williams

I did not write this! I wrote "*read and written* using a
fixed point font". You are creating a wrong context by
improperly leaving out parts of the sentence.

No I'm not. I'm not creating a wrong context at all. You are the one who is
wrong. You were chastising the OP for failing to use a fixed width font in
his message. You said, "a plain-text message read and written using a fixed
point font like Courier New is common practice". But it isn't possible for
the OP to write a "plain text" message using a "fixed point" font, so you
were wrong to chastise him for failing to do so. If the OP sends a "plain
text" message then it is up to YOU (not the OP) to decide what font you wish
to read it in! The OP has no control over that whatsoever. So if you are
chastising him then you are chastising him for your own failure! The OP
could have written a HTML message using a fixed width font (and then it
would appear at your end as fixed width unless you specifically chose not to
display the message that format, which would certainly not be the OP's
fault!). But that is NOT what you said. What you said was WRONG. Why don't
you just admit it and stop wriggling about in your attemp to defend the
indefensible!

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top