Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 620
  • Last Modified:

Usage of Function

can someone please tell me why below these code are not working ?

Private Sub Text1_KeyPress(KeyAscii As Integer)
NumValidation
End Sub

Public Function NumValidation()
Select Case KeyAscii:
     Case vbKey0 To vbKey9
     Case vbKeyBack
     Case vbKeyDelete
     Case Else:
        KeyAscii = 0
  End Select
End Function


Thanks
0
ANGmoh
Asked:
ANGmoh
1 Solution
 
ayufansCommented:
have you tried typing :  

Call numvalidation

to actuaally call the function ?

0
 
bin_huwairibCommented:
ANGmoh,

you must pass the KeyAscii variable to your NumValidation function, your code must look like this:
----------------------------------------------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
call NumValidation(KeyAscii)
End Sub

Public Function NumValidation(KeyAscii As Integer)
Select Case KeyAscii:
    Case vbKey0 To vbKey9
    Case vbKeyBack
    Case vbKeyDelete
    Case Else:
       KeyAscii = 0
 End Select
End Function


Regards,
Ben Huwairib
0
 
ChimoCommented:
Private Sub Text1_KeyPress(KeyAscii As Integer)
  Call NumValidation(KeyAscii)
  'or
  'NumValidation KeyAscii
End Sub

Public Function NumValidation(byref KeyAscii as Integer)
  '... your code
End Function

If you want NumValidation to return something you have to do something like

Public Function NumValidation(byref KeyAscii as Integer)
  '...
  NumValidation = a certain value
End function

If NumValidation do not need to return anything, then you should declare it like that:

Public Sub NumValidation(byref KeyAscii as Integer)
  '...
End Sub

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now