Wednesday 15 September 2010

vb.net - Checking user keypresses creates a warning -


I am trying to keep user input as clean as possible in my application. In a way I'm trying to do this, do not allow the wrong data type in the field (alpha characters are not allowed when expecting numeric values)

I found the following code And implemented:

  private subtxtSocial_KeyPress (ByVal handles this as object, byVal e System.Windows.Forms.KeyPressEventArgs) txtSocial.KeyPress Driven UserKeyPress handles four = e.KeyChar Dim isKey Boolean = e.KeyChar.IsDigit (UserKeyPress) is dim asCont boolean If in the form = e.KeyChar.IsControl (UserKeyPress) if not isKey and notCont then e.Handled = true end then  

code desired however works as visual studio This throws a warning:

Shared members, continuous members, access to members or nested types through a member; Eligibility expression will not be evaluated.

I am not against warnings, but if I have there that is what I know to ignore warning and want to move forward, or there is a better way for my goals To complete?

After

instead of e.KeyChar.IsDigit , use char .isdigit . This is the case for IsControl . When accessing a static (shared) method like IsDigit, you can use a specific example instead of doing it directly through the class: Example ( e.KeyChar in this case) Will also be ignored, and this is what the warning is.


No comments:

Post a Comment