Addevent for TextBox

cpp4cisab

New Member
Hi everybody,

I seek help from elite members.

Does Addevent("textbox1",GotFocus,"MySub") hijack gotfocus event?
I mean, if I call some sub in textbox1_Gotfocus, will it execute or not?

In my code, it is not getting executed.
 

berndgoedecke

Active Member
Licensed User
Longtime User
doubleqouts missing and wrong Sub

It's an error in B4P-Help. GotFocus has to be a string also.
Addevent("textbox1","GotFocus","MySub") and then you have to call MySub.

Best regards

berndgoedecke
 

cpp4cisab

New Member
Thanks for reply.

My code uses AddEvent(ctls(i),"GotFocus","Highlight") in App_start to highlight active textbox and similar sub for LostFocus event to make inactive textboxes' BG white.
Now if I add validation sub in LostFocus event of a particular textbox, it does not fire.

(adding or leaving quotes is not making difference in AddEvent, at least in my code.)
 

mjcoon

Well-Known Member
Licensed User
My code uses AddEvent(ctls(i),"GotFocus","Highlight") in App_start to highlight active textbox and similar sub for LostFocus event to make inactive textboxes' BG white.

From the (edited) B4P Help:
Wires a control event to a specific sub.
Syntax: AddEvent (Control Name, Event Name, Sub Name)
...
Note: As in this example, Event Name is not quoted and can't be a variable.
Example:
AddEvent ("Button1", Click, "MySub")

Sub MySub
Form1.Text = Sender.Text
End Sub

Firstly it is not obvious that you need to call AddEvent() at all, if your text box is defined on the form via the Designer you can add the GotFocus and LostFocus events that way too.

So the Help says that the event name should not be quoted, the 1st parameter is the name of a control (what is your "ctls(i)"?) and the 3rd/last parameter is the name of a Sub that you have included in your program (what is "Highlight" and what does it do?).

Perhaps it would be easier if you attached your complete source code, so we can see what objects you are referring to, and which item in your form will initially have the focus.

Mike.
 
Top