?
Solved

Usage of Function

Posted on 2003-03-21
3
Medium Priority
?
614 Views
Last Modified: 2008-03-10
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
Comment
Question by:ANGmoh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 1

Expert Comment

by:ayufans
ID: 8185006
have you tried typing :  

Call numvalidation

to actuaally call the function ?

0
 
LVL 5

Accepted Solution

by:
bin_huwairib earned 60 total points
ID: 8185070
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
 

Expert Comment

by:Chimo
ID: 8185075
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month15 days, 3 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question