p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Access 2003 VBA Programmer's Reference (http://p2p.wrox.com/forumdisplay.php?f=133)
-   -   Using the Asc function (http://p2p.wrox.com/showthread.php?t=54022)

langsha February 13th, 2007 08:45 PM

Using the Asc function
 
Hi,

I'm new to this site and am hoping someone can help. I'm trying to find the ascii value of text entered into a text box. I've written the following code on the Key press event of a text box, but every time I type something in, I get a "Invalid procedure call or argument" error. Do I need to have a specific reference turned on or is there an issue with my code?

Thanks in advance for your help!

    Private Sub txt_String_KeyPress(KeyAscii As Integer)

         Dim Asc_Value As String

         Asc_Value = Asc(Me.txt_String.Text)
         MsgBox Asc(Asc_Value)


    End Sub



--LANGSHA--

kumarj February 20th, 2007 04:42 AM

Try to split the string and use asc() function


haarishr March 29th, 2008 02:54 AM

Option Explicit
Public ascval As String
-------------------------------------------------------
Private Sub txt_String_KeyPress_KeyPress(KeyAscii As Integer)
ascval = ascval & KeyAscii
End Sub
---------------------------------------------------------------
Private Sub txt_String_KeyPress_KeyUp(KeyCode As Integer, Shift As Integer)
txt_String_KeyPress = ascval
End Sub

AVPimbleSr November 25th, 2008 12:13 PM

KeyAscii is the Ascii value for the key you pressed while in your textbox named txt_String. The KeyPress event tracks each time you press a key, hence the name.

You are receiving the error "Invalid procedure call or argument" because you are providing an invalid argument to the Asc() function. The Asc() function takes a single text character. You can only get the Ascii value of a single character.

That being said, what are you trying to accomplish?

Allan






Quote:

quote:Originally posted by langsha
 Hi,

I'm new to this site and am hoping someone can help. I'm trying to find the ascii value of text entered into a text box. I've written the following code on the Key press event of a text box, but every time I type something in, I get a "Invalid procedure call or argument" error. Do I need to have a specific reference turned on or is there an issue with my code?

Thanks in advance for your help!

    Private Sub txt_String_KeyPress(KeyAscii As Integer)

         Dim Asc_Value As String

         Asc_Value = Asc(Me.txt_String.Text)
         MsgBox Asc(Asc_Value)


    End Sub



--LANGSHA--


All times are GMT -4. The time now is 08:22 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.