Steev

Here is some code:

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If Not Char.IsNumber(e.KeyChar) And Not Char.IsControl(e.KeyChar) Then

e.Handled = True

The problem is that there is an error message saying e.KeyChar is not a member of System.EventArgs"

I have made a public declaration at the top of the form ("Imports System.Data" and also "Imports System.EventArgs") but I still get the error message.

Any ideas how I can cure this

Regards,

Steve




Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

Dave299

Well the message is correct - KeyChar is not a member of System.EventArgs.

Actually the message wouldn't include the e, but I presume that is just a typo.

Try highlighting the e in the e.KeyChar and press Shift-F2. It should highlight the e in the event declaration. If it does and that is defined as KeyPressEventArgs then something very strange is going on.





Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

JohnWein

I referenced (not imported) only

System

System.Drawing

System.Windows.Forms

And this is my total code:

Code Block

Public Class Form1

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If Not Char.IsNumber(e.KeyChar) And Not Char.IsControl(e.KeyChar) Then e.Handled = True

End Sub

End Class

It compiles and runs without error.

I would look elsewhere for the source of your error.




Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

Steev

Dave & John,

Thanks for the help, I'll check it out and let you know what happens

Regards,

Steve






Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

Steev

Dave - what you wrote does happen.

John - what do you mean by "referencing" I tried various things but nothing worked so perhaps I misunderstand the concept

Any more ideas and suggestions anyone

Regards,

Steve






Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

JohnWein

Reference means the Dlls that are referenced on the References Page of the Project Properties. When you use the code I posted what error are you getting





Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

Steev

Hi John,

All I did was remove the "Imports" from "Imports System.Data" etc but it made no difference. I still get the error message "KeyChar is not a member of systemEventArgs". (I'm very much a beginner so I don't have the knowledge to do too much!!).

It's odd because before reloading VB Express it used to work fine. I'll have another look at the referncing thing where you suggested and get back to you. Thanks for your help thus far. What about other settings - are there any I need to switch on eg option explicit, option compare

Regards,

Steve






Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

JohnWein

There were no imports statements in the code I posted. What is the error you get when you run the code I posted





Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

Dave299

If the references to System.Drawing or System.Windows.Forms were missing you would get a whole load of errors, not just the one you are seeing.

When you say you get an error I presume this is in the code editor and you get a squiggly line under the e.KeyChar. I also presume if you type e. then Intellisense includes KeyChar in the list of options.

If both of the presumptions are correct then what you are seeing definitely shouldn't be happening.

Why did you have to reinstall VB Express - have you been trying any other versions





Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

clint 2

I may be way off here but may I make a suggestion

delete your textbox, then add a new textbox

then in your new textbox keypress event insert the code you have been given

and see if it now works

clint






Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

Steev

Hi John,

Apologies, I didn't explain myself clearly in my previous post. At the top of the code (before the "public" part, I usually write the imports statements eg Imports system etc - using your advice I removed the "imports" word and left it as system (in addition to System.drawing and system.windows.forms) - because that is how I first interpreted your post. But after looking at your next post I went to the top of the desktop page, opened properties, add reference, .net - and selecterd your recommended choices - system, system.drawing, system.windows.forms.

Unfortunately it made no difference and I still get the same error messages.

Dave and John: the error messages are: ""KeyChar" is not a memeber of System.EventArgs and also "Handled is not a member of system.EventArgs. I get these mesages whenever I hover the mouse over the e.KeyChar or e.Handles in my code (as posted in my first post)

Dave - No I haven't installed other versions. I did recently have to reload everything onto my laptop - XP (including SP2 and security hotfixes), and all programmes. I reloaded VB express about 2 weeks ago and this is the first opportunity since then to do some programming.

I don't know what is so different from before when everything worked! The only thing I can think of is that there is a setting somewhere that needs to be changed/altered either in VB express or in XP.

clint2 - Thanks for the suggestion, I've tried that but no success!! Maybe I could try reloading Vb again and see what happens.

Any other thoughts/ideas/suggestions/advice/help is gratefully received.

Regards,

Steve






Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

JohnWein

Copy and post all the code you now have in Form1 and the StackTrace of the error.





Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

Steev

Hi John,

"Copy and paste all the code you now have in Form1"

Do you mean all the code in this particular event handler (TextChanged) or do you mean literally everything in Form1 (that's a lot of code!) - and do I paste it back onto Form1

`

"..............and the StackTrace of the error"

What is that

Regards,

Steve






Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

JohnWein

How did it get to be a lot of code I posted 5 lines of code. You should be testing a program with a single form containing a textbox, 3 references and 5 lines of code. When you test this program do you get an error or don't you





Re: Visual Basic Express Edition e.KeyChar - my VB express doesn't recognise it

Steev

Hi John,

I get the same error messages as before - "Keychar is not a member of system.EventArgs" and this is when I hover the mouse over the e.KeyChar part of the code (or "handled not a memeber of system.eventargs" when hovering over the e.handles)

When you said cut and paste the code I first thought you meant my original form not my test form - I'm a beginner at Vb and don't know if maybe all the code needs to be "reapplied", no offence meant.

Steve