Re: KeyPress event sub breaks a form

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi,

I've been able to duplicate my problem in VB6, but with a twist. In VB6, the
event procedure must be defined similar to:

Private Sub txtScan_KeyPress(ByRef AsciiKey As Integer)

If you use ByVal, the code completion feature (what I called Intellisense
earlier) fails in the form. When you enter the name of the form followed by
a period, you no longer see a list of events, methods, and properties.
However, in VB6 when you then build the project, you get an error message
that explains the problem. The problem is that the event procedure is
defined wrong. In VB6 it must be ByRef. The previous postings in this
newsgroup recommending ByRef were correct for VB6. However, they were
incorrect for embedded VB. Also, when code completion fails, the form is
broken.

In embedded VB you can build the project when an event procedure is defined
wrong. However, the form is still "broken" and the application will crash
when it attempts to open the form. Also, the event definition is different
in embedded VB. It must be:

Private Sub txtScan_KeyPress(ByVal AsciiKey As Integer)

How do I know? OK, I'm assuming, but unless I use ByVal, code completion
fails on the form and the app crashes. I conclude that you must use ByVal
for this event procedure in embedded VB.

I also conclude that if code completion stops working, the form is broken
and the app will crash, whether it builds without errors or not. This is
useful to know. When I make any changes to a form, I should check that code
completion still works.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"<ctacke/>" <ctacke_AT_OpenNETCF_com> wrote in message
news:Od6WBCNNGHA.984@xxxxxxxxxxxxxxxxxxxxxxx
The recommendation to use ByRef is in the event you want to cancel the
key. For instance if you want only certain key codes to actually go tot he
form, you can set all other codes to zero. This is how VB 6 works. For
that to happen, it must be passed as a reference.

-Chris


"Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:OL%23tcRMNGHA.536@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

After a lot of experimentation I find that the following "breaks the
form"
(meaning Intellisense fails):

Private Sub txtScan_KeyPress(ByRef AsciiKey As Integer)

This also breaks the form:

Private Sub txtScan_KeyPress(ByVal AsciiKey)

But this seems to work:

Private Sub txtScan_KeyPress(ByVal AsciiKey As Integer)

The later was what I used in my previous version of the app. When I
recoded
I took note of previous posts in this newsgroup indicating that ByRef
should
be used instead of ByVal. I may have overcome my problem (more testing
needed), but I have no idea why this happens. I'm also puzzled by
recommendations to use ByRef.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net

"Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx> wrote in
message
news:eIeBCGLNGHA.3924@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

I have an embedded vb 3.0 app with several forms. One form accepts
barcodes in a textbox control. I use a KeyPress event to process the
barcode scans. This worked fine when the textbox and KeyPress event subs
were on the startup form. However, I want to move this functionality to
another form.

When I create a new form with everything I need except the KeyPress sub,
all is well. Intellisense in the embedded vb IDE works. By that I mean I
can enter the form name and a period and see the list of controls and
events available. As soon as I add the KeyPress event, Intellisense no
longer works. It's as if the IDE no longer recognizes the form. If I
build
and attempt to run the app, navigating to the new form causes the app to
crash.

I've tried several times to create the new form. In all cases the form
"breaks" when I add the textbox KeyPress event sub. If I change the sub
name from txtScan_KeyPress to txtScanKeyPress, Intellisense works. As
soon
as I restore the underscore, it is recognized as an event procedure, but
the form breaks. I've been able to duplicate this in other embedded vb
apps by adding a textbox control to a child form with a KeyPress event
sub.

Any ideas what is happening and how to fix it?

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net









.



Relevant Pages

  • RE: Check boxes selected enters several responses
    ... You might try typing an apostrophe before the DoCmd in the Event procedure ... to track all staff working on a single record in a given day. ... Private Sub List4_AfterUpdate ... reviewing the record and identifying the persons who entered data: ...
    (microsoft.public.access.forms)
  • Re: AfterUpdate Event (Combo Box)
    ... Private Sub Category_AfterUpdate ... defined function, or [Event Procedure] ... Both Combo boxes are unbound and in the product combo box in the subform I ...
    (microsoft.public.access.modulesdaovba)
  • Problem resolution for calling the Copy method of the OWC11.Spreadsheet object on a Windows 2003 ser
    ... We created a VB6 ... own process space under the network service account, ... Private Sub Class_Initialize ... click the Security tab and clear the checkbox for ...
    (microsoft.public.office.developer.web.components)
  • Re: control source to update text box
    ... source and the event procedure is still in the events tab. ... the Private Sub Date_Processed_AfterUpdateline, ... of the reference # text box. ... Also check that the control source for the textbox that receives ...
    (microsoft.public.access.formscoding)
  • RE: Error communicating with the OLE server or ActiveX Control
    ... user-defined function, or. ... It doesn't seem to matter what code I have in the OnClick Event Procedure. ... Private Sub CancelQueryCmdButton_Click ... MsgBox because it's so simple and I thought I couldn't get that wrong, ...
    (microsoft.public.access.formscoding)