Raising Custom Events on a Custom OCX 
Author Message
 Raising Custom Events on a Custom OCX

      Scenario:

      A custom control consisting of a Textbox with a property called
MinLength that specifies the minimum characters required for input, and a
custom event that will be raised if this minimum length required is not
satisfied.

      When the user types in some characters and exits the control, the
LostFocus event handler of the TextBox (NOT the UserControl's LostFocus
event handler) checks for the length of the text typed in and compares it to
the MinLength value.  If it is less than the MinLength value, the custom
event is raised.

      Source Code Excerpt:

      Event InputViolation

      Private Sub TextBox_LostFocus ()

         If Len(Trim(TextBox.Text)) < MinLength Then

            RaiseEvent InputViolation    ' <-----OFFENDING INSTRUCTION

         End If

      End Sub

      Problem:

      VB6 crashes at the RaiseEvent instruction stating a "memory could not
be read" error.

      Question:

       What's wrong with this code?  Am I missing something to declare or
implement here?  (Note: I would not like to use RaiseError)

      Any comments or suggestions will be appreciated.

      Carlitos



Tue, 22 Jun 2004 23:33:01 GMT  
 Raising Custom Events on a Custom OCX
Hi,

I try the same and it works, except for the minLength property.
How is this property implemented ? Is it a constant, a property  of your
active X or whatever ..

Bests regards

Bernard



Quote:

>       Scenario:

>       A custom control consisting of a Textbox with a property called
> MinLength that specifies the minimum characters required for input, and a
> custom event that will be raised if this minimum length required is not
> satisfied.

>       When the user types in some characters and exits the control, the
> LostFocus event handler of the TextBox (NOT the UserControl's LostFocus
> event handler) checks for the length of the text typed in and compares it
to
> the MinLength value.  If it is less than the MinLength value, the custom
> event is raised.

>       Source Code Excerpt:

>       Event InputViolation

>       Private Sub TextBox_LostFocus ()

>          If Len(Trim(TextBox.Text)) < MinLength Then

>             RaiseEvent InputViolation    ' <-----OFFENDING INSTRUCTION

>          End If

>       End Sub

>       Problem:

>       VB6 crashes at the RaiseEvent instruction stating a "memory could
not
> be read" error.

>       Question:

>        What's wrong with this code?  Am I missing something to declare or
> implement here?  (Note: I would not like to use RaiseError)

>       Any comments or suggestions will be appreciated.

>       Carlitos



Wed, 23 Jun 2004 01:25:53 GMT  
 Raising Custom Events on a Custom OCX
Hi Bernard,

I know the property is not the problem, so it doesn't matter if it use a
property or a variable or whatever.

The problem is when I say "RaiseEvent InputViolation" and it crashes the
whole thing.

Got any other ideas?

Carlitos


Quote:
> Hi,

> I try the same and it works, except for the minLength property.
> How is this property implemented ? Is it a constant, a property  of your
> active X or whatever ..

> Bests regards

> Bernard



> >       Scenario:

> >       A custom control consisting of a Textbox with a property called
> > MinLength that specifies the minimum characters required for input, and
a
> > custom event that will be raised if this minimum length required is not
> > satisfied.

> >       When the user types in some characters and exits the control, the
> > LostFocus event handler of the TextBox (NOT the UserControl's LostFocus
> > event handler) checks for the length of the text typed in and compares
it
> to
> > the MinLength value.  If it is less than the MinLength value, the custom
> > event is raised.

> >       Source Code Excerpt:

> >       Event InputViolation

> >       Private Sub TextBox_LostFocus ()

> >          If Len(Trim(TextBox.Text)) < MinLength Then

> >             RaiseEvent InputViolation    ' <-----OFFENDING INSTRUCTION

> >          End If

> >       End Sub

> >       Problem:

> >       VB6 crashes at the RaiseEvent instruction stating a "memory could
> not
> > be read" error.

> >       Question:

> >        What's wrong with this code?  Am I missing something to declare
or
> > implement here?  (Note: I would not like to use RaiseError)

> >       Any comments or suggestions will be appreciated.

> >       Carlitos



Wed, 23 Jun 2004 04:59:30 GMT  
 Raising Custom Events on a Custom OCX
Deja VU.. there's a guy in General.Discussion having the *exact* same
problem with the *exact* same property/event..
I posted a sample project there that shows a working example of this..

Go there and search for a thread called "Urgent: How do I add an event to a
OCX?"

Hey... wait a minute.. you guys work together.. right?

--
Ken Halter (VB-MVP)
Please respond only to the newsgroups so all can benefit.


Quote:
> Hi Bernard,

> I know the property is not the problem, so it doesn't matter if it use a
> property or a variable or whatever.

> The problem is when I say "RaiseEvent InputViolation" and it crashes the
> whole thing.

> Got any other ideas?

> Carlitos



> > Hi,

> > I try the same and it works, except for the minLength property.
> > How is this property implemented ? Is it a constant, a property  of your
> > active X or whatever ..

> > Bests regards

> > Bernard



> > >       Scenario:

> > >       A custom control consisting of a Textbox with a property called
> > > MinLength that specifies the minimum characters required for input,
and
> a
> > > custom event that will be raised if this minimum length required is
not
> > > satisfied.

> > >       When the user types in some characters and exits the control,
the
> > > LostFocus event handler of the TextBox (NOT the UserControl's
LostFocus
> > > event handler) checks for the length of the text typed in and compares
> it
> > to
> > > the MinLength value.  If it is less than the MinLength value, the
custom
> > > event is raised.

> > >       Source Code Excerpt:

> > >       Event InputViolation

> > >       Private Sub TextBox_LostFocus ()

> > >          If Len(Trim(TextBox.Text)) < MinLength Then

> > >             RaiseEvent InputViolation    ' <-----OFFENDING INSTRUCTION

> > >          End If

> > >       End Sub

> > >       Problem:

> > >       VB6 crashes at the RaiseEvent instruction stating a "memory
could
> > not
> > > be read" error.

> > >       Question:

> > >        What's wrong with this code?  Am I missing something to declare
> or
> > > implement here?  (Note: I would not like to use RaiseError)

> > >       Any comments or suggestions will be appreciated.

> > >       Carlitos



Wed, 23 Jun 2004 05:27:41 GMT  
 Raising Custom Events on a Custom OCX
And what about the question in controls.creation ???????
:)
Carol.



Quote:
> Deja VU.. there's a guy in General.Discussion having the *exact* same
> problem with the *exact* same property/event..
> I posted a sample project there that shows a working example of this..

> Go there and search for a thread called "Urgent: How do I add an event to
a
> OCX?"

> Hey... wait a minute.. you guys work together.. right?

> --
> Ken Halter (VB-MVP)
> Please respond only to the newsgroups so all can benefit.



> > Hi Bernard,

> > I know the property is not the problem, so it doesn't matter if it use a
> > property or a variable or whatever.

> > The problem is when I say "RaiseEvent InputViolation" and it crashes the
> > whole thing.

> > Got any other ideas?

> > Carlitos



> > > Hi,

> > > I try the same and it works, except for the minLength property.
> > > How is this property implemented ? Is it a constant, a property  of
your
> > > active X or whatever ..

> > > Bests regards

> > > Bernard



> > > >       Scenario:

> > > >       A custom control consisting of a Textbox with a property
called
> > > > MinLength that specifies the minimum characters required for input,
> and
> > a
> > > > custom event that will be raised if this minimum length required is
> not
> > > > satisfied.

> > > >       When the user types in some characters and exits the control,
> the
> > > > LostFocus event handler of the TextBox (NOT the UserControl's
> LostFocus
> > > > event handler) checks for the length of the text typed in and
compares
> > it
> > > to
> > > > the MinLength value.  If it is less than the MinLength value, the
> custom
> > > > event is raised.

> > > >       Source Code Excerpt:

> > > >       Event InputViolation

> > > >       Private Sub TextBox_LostFocus ()

> > > >          If Len(Trim(TextBox.Text)) < MinLength Then

> > > >             RaiseEvent InputViolation    ' <-----OFFENDING
INSTRUCTION

> > > >          End If

> > > >       End Sub

> > > >       Problem:

> > > >       VB6 crashes at the RaiseEvent instruction stating a "memory
> could
> > > not
> > > > be read" error.

> > > >       Question:

> > > >        What's wrong with this code?  Am I missing something to
declare
> > or
> > > > implement here?  (Note: I would not like to use RaiseError)

> > > >       Any comments or suggestions will be appreciated.

> > > >       Carlitos



Wed, 23 Jun 2004 06:21:43 GMT  
 Raising Custom Events on a Custom OCX
Yeah!... I know what to tell people when they post the same question in
multiple groups.. one at a time.. (Stop Multiposting!!!).. but, what do you
tell several people starting several different threads about the exact same
question, using a different subject line no less.. boy, that's got to be
Multiposting cubed.. or something<g>

--
Ken Halter (VB-MVP)
Please respond only to the newsgroups so all can benefit.


Quote:
> And what about the question in controls.creation ???????
> :)
> Carol.



> > Deja VU.. there's a guy in General.Discussion having the *exact* same
> > problem with the *exact* same property/event..
> > I posted a sample project there that shows a working example of this..

> > Go there and search for a thread called "Urgent: How do I add an event
to
> a
> > OCX?"

> > Hey... wait a minute.. you guys work together.. right?

> > --
> > Ken Halter (VB-MVP)
> > Please respond only to the newsgroups so all can benefit.



> > > Hi Bernard,

> > > I know the property is not the problem, so it doesn't matter if it use
a
> > > property or a variable or whatever.

> > > The problem is when I say "RaiseEvent InputViolation" and it crashes
the
> > > whole thing.

> > > Got any other ideas?

> > > Carlitos



> > > > Hi,

> > > > I try the same and it works, except for the minLength property.
> > > > How is this property implemented ? Is it a constant, a property  of
> your
> > > > active X or whatever ..

> > > > Bests regards

> > > > Bernard




> > > > >       Scenario:

> > > > >       A custom control consisting of a Textbox with a property
> called
> > > > > MinLength that specifies the minimum characters required for
input,
> > and
> > > a
> > > > > custom event that will be raised if this minimum length required
is
> > not
> > > > > satisfied.

> > > > >       When the user types in some characters and exits the
control,
> > the
> > > > > LostFocus event handler of the TextBox (NOT the UserControl's
> > LostFocus
> > > > > event handler) checks for the length of the text typed in and
> compares
> > > it
> > > > to
> > > > > the MinLength value.  If it is less than the MinLength value, the
> > custom
> > > > > event is raised.

> > > > >       Source Code Excerpt:

> > > > >       Event InputViolation

> > > > >       Private Sub TextBox_LostFocus ()

> > > > >          If Len(Trim(TextBox.Text)) < MinLength Then

> > > > >             RaiseEvent InputViolation    ' <-----OFFENDING
> INSTRUCTION

> > > > >          End If

> > > > >       End Sub

> > > > >       Problem:

> > > > >       VB6 crashes at the RaiseEvent instruction stating a "memory
> > could
> > > > not
> > > > > be read" error.

> > > > >       Question:

> > > > >        What's wrong with this code?  Am I missing something to
> declare
> > > or
> > > > > implement here?  (Note: I would not like to use RaiseError)

> > > > >       Any comments or suggestions will be appreciated.

> > > > >       Carlitos



Wed, 23 Jun 2004 06:41:55 GMT  
 Raising Custom Events on a Custom OCX

"Stop multiposting cubed" ?
Hmmm. Think this will do the job. :)

ATB

Carol

P.S. Not All Terrain Bike but All The Best



Quote:
> Yeah!... I know what to tell people when they post the same question in
> multiple groups.. one at a time.. (Stop Multiposting!!!).. but, what do
you
> tell several people starting several different threads about the exact
same
> question, using a different subject line no less.. boy, that's got to be
> Multiposting cubed.. or something<g>

> --
> Ken Halter (VB-MVP)
> Please respond only to the newsgroups so all can benefit.



> > And what about the question in controls.creation ???????
> > :)
> > Carol.



> > > Deja VU.. there's a guy in General.Discussion having the *exact* same
> > > problem with the *exact* same property/event..
> > > I posted a sample project there that shows a working example of this..

> > > Go there and search for a thread called "Urgent: How do I add an event
> to
> > a
> > > OCX?"

> > > Hey... wait a minute.. you guys work together.. right?

> > > --
> > > Ken Halter (VB-MVP)
> > > Please respond only to the newsgroups so all can benefit.



> > > > Hi Bernard,

> > > > I know the property is not the problem, so it doesn't matter if it
use
> a
> > > > property or a variable or whatever.

> > > > The problem is when I say "RaiseEvent InputViolation" and it crashes
> the
> > > > whole thing.

> > > > Got any other ideas?

> > > > Carlitos



> > > > > Hi,

> > > > > I try the same and it works, except for the minLength property.
> > > > > How is this property implemented ? Is it a constant, a property
of
> > your
> > > > > active X or whatever ..

> > > > > Bests regards

> > > > > Bernard




> > > > > >       Scenario:

> > > > > >       A custom control consisting of a Textbox with a property
> > called
> > > > > > MinLength that specifies the minimum characters required for
> input,
> > > and
> > > > a
> > > > > > custom event that will be raised if this minimum length required
> is
> > > not
> > > > > > satisfied.

> > > > > >       When the user types in some characters and exits the
> control,
> > > the
> > > > > > LostFocus event handler of the TextBox (NOT the UserControl's
> > > LostFocus
> > > > > > event handler) checks for the length of the text typed in and
> > compares
> > > > it
> > > > > to
> > > > > > the MinLength value.  If it is less than the MinLength value,
the
> > > custom
> > > > > > event is raised.

> > > > > >       Source Code Excerpt:

> > > > > >       Event InputViolation

> > > > > >       Private Sub TextBox_LostFocus ()

> > > > > >          If Len(Trim(TextBox.Text)) < MinLength Then

> > > > > >             RaiseEvent InputViolation    ' <-----OFFENDING
> > INSTRUCTION

> > > > > >          End If

> > > > > >       End Sub

> > > > > >       Problem:

> > > > > >       VB6 crashes at the RaiseEvent instruction stating a
"memory
> > > could
> > > > > not
> > > > > > be read" error.

> > > > > >       Question:

> > > > > >        What's wrong with this code?  Am I missing something to
> > declare
> > > > or
> > > > > > implement here?  (Note: I would not like to use RaiseError)

> > > > > >       Any comments or suggestions will be appreciated.

> > > > > >       Carlitos



Wed, 23 Jun 2004 07:07:52 GMT  
 Raising Custom Events on a Custom OCX
Sorry guys!  Yes, we work together.  I didn't know she had posted a message
already.

The one duplicated in controls and controls.creation was me because I often
post a message an no one answers it, and wanted to grab attention.

Carol,  the event doesn't even get raised.  It blows up at the instruction
(at the UserControl code).

Some other ideas?

Thanks.


Quote:

> "Stop multiposting cubed" ?
> Hmmm. Think this will do the job. :)

> ATB

> Carol

> P.S. Not All Terrain Bike but All The Best



> > Yeah!... I know what to tell people when they post the same question in
> > multiple groups.. one at a time.. (Stop Multiposting!!!).. but, what do
> you
> > tell several people starting several different threads about the exact
> same
> > question, using a different subject line no less.. boy, that's got to be
> > Multiposting cubed.. or something<g>

> > --
> > Ken Halter (VB-MVP)
> > Please respond only to the newsgroups so all can benefit.



> > > And what about the question in controls.creation ???????
> > > :)
> > > Carol.



> > > > Deja VU.. there's a guy in General.Discussion having the *exact*
same
> > > > problem with the *exact* same property/event..
> > > > I posted a sample project there that shows a working example of
this..

> > > > Go there and search for a thread called "Urgent: How do I add an
event
> > to
> > > a
> > > > OCX?"

> > > > Hey... wait a minute.. you guys work together.. right?

> > > > --
> > > > Ken Halter (VB-MVP)
> > > > Please respond only to the newsgroups so all can benefit.



> > > > > Hi Bernard,

> > > > > I know the property is not the problem, so it doesn't matter if it
> use
> > a
> > > > > property or a variable or whatever.

> > > > > The problem is when I say "RaiseEvent InputViolation" and it
crashes
> > the
> > > > > whole thing.

> > > > > Got any other ideas?

> > > > > Carlitos



> > > > > > Hi,

> > > > > > I try the same and it works, except for the minLength property.
> > > > > > How is this property implemented ? Is it a constant, a property
> of
> > > your
> > > > > > active X or whatever ..

> > > > > > Bests regards

> > > > > > Bernard




> > > > > > >       Scenario:

> > > > > > >       A custom control consisting of a Textbox with a property
> > > called
> > > > > > > MinLength that specifies the minimum characters required for
> > input,
> > > > and
> > > > > a
> > > > > > > custom event that will be raised if this minimum length
required
> > is
> > > > not
> > > > > > > satisfied.

> > > > > > >       When the user types in some characters and exits the
> > control,
> > > > the
> > > > > > > LostFocus event handler of the TextBox (NOT the UserControl's
> > > > LostFocus
> > > > > > > event handler) checks for the length of the text typed in and
> > > compares
> > > > > it
> > > > > > to
> > > > > > > the MinLength value.  If it is less than the MinLength value,
> the
> > > > custom
> > > > > > > event is raised.

> > > > > > >       Source Code Excerpt:

> > > > > > >       Event InputViolation

> > > > > > >       Private Sub TextBox_LostFocus ()

> > > > > > >          If Len(Trim(TextBox.Text)) < MinLength Then

> > > > > > >             RaiseEvent InputViolation    ' <-----OFFENDING
> > > INSTRUCTION

> > > > > > >          End If

> > > > > > >       End Sub

> > > > > > >       Problem:

> > > > > > >       VB6 crashes at the RaiseEvent instruction stating a
> "memory
> > > > could
> > > > > > not
> > > > > > > be read" error.

> > > > > > >       Question:

> > > > > > >        What's wrong with this code?  Am I missing something to
> > > declare
> > > > > or
> > > > > > > implement here?  (Note: I would not like to use RaiseError)

> > > > > > >       Any comments or suggestions will be appreciated.

> > > > > > >       Carlitos



Fri, 25 Jun 2004 20:26:32 GMT  
 Raising Custom Events on a Custom OCX
Carlitos,

The problem is that you are leaving pointers on the stack by raising an
event from within an event. The first events pointers are never popped from
the stack, since the event procedure never finishes.

To solve the problem, add a Timer control to your UserControl (or you can
use an API callback timer). Set the Timer for 1 millisecond.

Now change your code to look like this:

Private Sub TextBox_LostFocus ()

    If Len(Trim(TextBox.Text)) < MinLength Then
        Timer1.Enabled = True
    End If

End Sub

Private Sub Timer1_Timer()
        RaiseEvent InputViolation
End Sub

Now the TextBox_LostFocus event will finish and exit before the Timer fires
the InputValidation event and you should have no more problems.

HTH,
Rocky Clark (Kath-Rock Software)


Quote:

>       Scenario:

>       A custom control consisting of a Textbox with a property called
> MinLength that specifies the minimum characters required for input, and a
> custom event that will be raised if this minimum length required is not
> satisfied.

>       When the user types in some characters and exits the control, the
> LostFocus event handler of the TextBox (NOT the UserControl's LostFocus
> event handler) checks for the length of the text typed in and compares it
to
> the MinLength value.  If it is less than the MinLength value, the custom
> event is raised.

>       Source Code Excerpt:

>       Event InputViolation

>       Private Sub TextBox_LostFocus ()

>          If Len(Trim(TextBox.Text)) < MinLength Then

>             RaiseEvent InputViolation    ' <-----OFFENDING INSTRUCTION

>          End If

>       End Sub

>       Problem:

>       VB6 crashes at the RaiseEvent instruction stating a "memory could
not
> be read" error.

>       Question:

>        What's wrong with this code?  Am I missing something to declare or
> implement here?  (Note: I would not like to use RaiseError)

>       Any comments or suggestions will be appreciated.

>       Carlitos



Sat, 26 Jun 2004 01:59:07 GMT  
 Raising Custom Events on a Custom OCX
Hello Clark,

Mmmm, I don't think that's the problem.  I have tried my code on a clean
project (without the rest of the code I have implemented in the control) and
it works fine.  So, I am infering that there is something else in the rest
of my control's code interferring with the raiseevent process.  Thanks
anyway.

Carlitos


Quote:
> Carlitos,

> The problem is that you are leaving pointers on the stack by raising an
> event from within an event. The first events pointers are never popped
from
> the stack, since the event procedure never finishes.

> To solve the problem, add a Timer control to your UserControl (or you can
> use an API callback timer). Set the Timer for 1 millisecond.

> Now change your code to look like this:

> Private Sub TextBox_LostFocus ()

>     If Len(Trim(TextBox.Text)) < MinLength Then
>         Timer1.Enabled = True
>     End If

> End Sub

> Private Sub Timer1_Timer()
>         RaiseEvent InputViolation
> End Sub

> Now the TextBox_LostFocus event will finish and exit before the Timer
fires
> the InputValidation event and you should have no more problems.

> HTH,
> Rocky Clark (Kath-Rock Software)



> >       Scenario:

> >       A custom control consisting of a Textbox with a property called
> > MinLength that specifies the minimum characters required for input, and
a
> > custom event that will be raised if this minimum length required is not
> > satisfied.

> >       When the user types in some characters and exits the control, the
> > LostFocus event handler of the TextBox (NOT the UserControl's LostFocus
> > event handler) checks for the length of the text typed in and compares
it
> to
> > the MinLength value.  If it is less than the MinLength value, the custom
> > event is raised.

> >       Source Code Excerpt:

> >       Event InputViolation

> >       Private Sub TextBox_LostFocus ()

> >          If Len(Trim(TextBox.Text)) < MinLength Then

> >             RaiseEvent InputViolation    ' <-----OFFENDING INSTRUCTION

> >          End If

> >       End Sub

> >       Problem:

> >       VB6 crashes at the RaiseEvent instruction stating a "memory could
> not
> > be read" error.

> >       Question:

> >        What's wrong with this code?  Am I missing something to declare
or
> > implement here?  (Note: I would not like to use RaiseError)

> >       Any comments or suggestions will be appreciated.

> >       Carlitos



Sat, 26 Jun 2004 02:36:09 GMT  
 Raising Custom Events on a Custom OCX
Its not the problem, I can call events just fine from a Winsock event in a
custom HTTP download control.

Max Bolingbroke


Quote:
> Carlitos,

> The problem is that you are leaving pointers on the stack by raising an
> event from within an event. The first events pointers are never popped
from
> the stack, since the event procedure never finishes.

> To solve the problem, add a Timer control to your UserControl (or you can
> use an API callback timer). Set the Timer for 1 millisecond.

> Now change your code to look like this:

> Private Sub TextBox_LostFocus ()

>     If Len(Trim(TextBox.Text)) < MinLength Then
>         Timer1.Enabled = True
>     End If

> End Sub

> Private Sub Timer1_Timer()
>         RaiseEvent InputViolation
> End Sub

> Now the TextBox_LostFocus event will finish and exit before the Timer
fires
> the InputValidation event and you should have no more problems.

> HTH,
> Rocky Clark (Kath-Rock Software)



> >       Scenario:

> >       A custom control consisting of a Textbox with a property called
> > MinLength that specifies the minimum characters required for input, and
a
> > custom event that will be raised if this minimum length required is not
> > satisfied.

> >       When the user types in some characters and exits the control, the
> > LostFocus event handler of the TextBox (NOT the UserControl's LostFocus
> > event handler) checks for the length of the text typed in and compares
it
> to
> > the MinLength value.  If it is less than the MinLength value, the custom
> > event is raised.

> >       Source Code Excerpt:

> >       Event InputViolation

> >       Private Sub TextBox_LostFocus ()

> >          If Len(Trim(TextBox.Text)) < MinLength Then

> >             RaiseEvent InputViolation    ' <-----OFFENDING INSTRUCTION

> >          End If

> >       End Sub

> >       Problem:

> >       VB6 crashes at the RaiseEvent instruction stating a "memory could
> not
> > be read" error.

> >       Question:

> >        What's wrong with this code?  Am I missing something to declare
or
> > implement here?  (Note: I would not like to use RaiseError)

> >       Any comments or suggestions will be appreciated.

> >       Carlitos



Sat, 26 Jun 2004 03:19:51 GMT  
 Raising Custom Events on a Custom OCX
Unless you send the full code for the control we cant really help in that
case :(

Max Bolingbroke


Quote:
> Hello Clark,

> Mmmm, I don't think that's the problem.  I have tried my code on a clean
> project (without the rest of the code I have implemented in the control)
and
> it works fine.  So, I am infering that there is something else in the rest
> of my control's code interferring with the raiseevent process.  Thanks
> anyway.

> Carlitos



> > Carlitos,

> > The problem is that you are leaving pointers on the stack by raising an
> > event from within an event. The first events pointers are never popped
> from
> > the stack, since the event procedure never finishes.

> > To solve the problem, add a Timer control to your UserControl (or you
can
> > use an API callback timer). Set the Timer for 1 millisecond.

> > Now change your code to look like this:

> > Private Sub TextBox_LostFocus ()

> >     If Len(Trim(TextBox.Text)) < MinLength Then
> >         Timer1.Enabled = True
> >     End If

> > End Sub

> > Private Sub Timer1_Timer()
> >         RaiseEvent InputViolation
> > End Sub

> > Now the TextBox_LostFocus event will finish and exit before the Timer
> fires
> > the InputValidation event and you should have no more problems.

> > HTH,
> > Rocky Clark (Kath-Rock Software)



> > >       Scenario:

> > >       A custom control consisting of a Textbox with a property called
> > > MinLength that specifies the minimum characters required for input,
and
> a
> > > custom event that will be raised if this minimum length required is
not
> > > satisfied.

> > >       When the user types in some characters and exits the control,
the
> > > LostFocus event handler of the TextBox (NOT the UserControl's
LostFocus
> > > event handler) checks for the length of the text typed in and compares
> it
> > to
> > > the MinLength value.  If it is less than the MinLength value, the
custom
> > > event is raised.

> > >       Source Code Excerpt:

> > >       Event InputViolation

> > >       Private Sub TextBox_LostFocus ()

> > >          If Len(Trim(TextBox.Text)) < MinLength Then

> > >             RaiseEvent InputViolation    ' <-----OFFENDING INSTRUCTION

> > >          End If

> > >       End Sub

> > >       Problem:

> > >       VB6 crashes at the RaiseEvent instruction stating a "memory
could
> > not
> > > be read" error.

> > >       Question:

> > >        What's wrong with this code?  Am I missing something to declare
> or
> > > implement here?  (Note: I would not like to use RaiseError)

> > >       Any comments or suggestions will be appreciated.

> > >       Carlitos



Sat, 26 Jun 2004 03:20:35 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Raising Custom Events in an OCX Control

2. HELP!!! raising events from a custom control

3. Raising Custom Active X Controls Events when using Data Repeater Control

4. Recurring-event Custom Meeting Forms Don't save custom fields

5. create custom icon,custom combobox in custom toolbar

6. create custom icon,custom combobox(to insert values)in custom toolbar

7. OCX COM does not fire custom events in Winform

8. Make your class fire an Event ( custom class event, RaiseEvent )

9. Custom Addin calling another custom Addin

10. Invoking custom help file from a custom menu

11. Setting values to Custom Fields on Custom Forms

12. Need Help: Trouble adding a custom menu pick to a custom popup menu in VBA

 

 
Powered by phpBB® Forum Software