Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Keypress nest

I received help here on how to check input in a text box and only allow
certain keys to be pressed.

It works, brilliant, now I want to use this as a seperate proceedure and
call it from several text boxes.

How to I send back the correct value from the check to "keypress"

I have tried this
__________________________________________________ ____________________
Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Public Function chkinp(keyascii) As MSForms.ReturnInteger
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
End Function
__________________________________________________ ____________________

But this does not work, I am missing the exact description of how to
send back the value to the keypress check

Many thanks for any help.

Garry Jones
Sweden
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Keypress nest

Untested, but I would suggest:

Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
KeyAscii = chkinp(keyascii)
End Sub
__________________________________________________ ____________________

Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
KeyAscii = chkinp(keyascii)
End Sub
__________________________________________________ ____________________

Public Function chkinp(keyascii) As MSForms.ReturnInteger
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
chkinp = keyascii
End Function

--
Regards,
Tom Ogilvy



"Garry Jones" wrote in message
...
I received help here on how to check input in a text box and only allow
certain keys to be pressed.

It works, brilliant, now I want to use this as a seperate proceedure and
call it from several text boxes.

How to I send back the correct value from the check to "keypress"

I have tried this
__________________________________________________ ____________________
Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Public Function chkinp(keyascii) As MSForms.ReturnInteger
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
End Function
__________________________________________________ ____________________

But this does not work, I am missing the exact description of how to
send back the value to the keypress check

Many thanks for any help.

Garry Jones
Sweden



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Keypress nest

Ok, had a chance to test it.

Change the function to:

Public Function chkinp(KeyAscii) As Long
Select Case KeyAscii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
KeyAscii = 0
End Select
chkinp = KeyAscii
End Function

Works fine, but you probably want to use Harald's class approach.

--
Regards,
Tom Ogilvy



"Tom Ogilvy" wrote in message
...
Untested, but I would suggest:

Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
KeyAscii = chkinp(keyascii)
End Sub
__________________________________________________ ____________________

Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
KeyAscii = chkinp(keyascii)
End Sub
__________________________________________________ ____________________

Public Function chkinp(keyascii) As MSForms.ReturnInteger
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
chkinp = keyascii
End Function

--
Regards,
Tom Ogilvy



"Garry Jones" wrote in message
...
I received help here on how to check input in a text box and only allow
certain keys to be pressed.

It works, brilliant, now I want to use this as a seperate proceedure and
call it from several text boxes.

How to I send back the correct value from the check to "keypress"

I have tried this
__________________________________________________ ____________________
Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Public Function chkinp(keyascii) As MSForms.ReturnInteger
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
End Function
__________________________________________________ ____________________

But this does not work, I am missing the exact description of how to
send back the value to the keypress check

Many thanks for any help.

Garry Jones
Sweden





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Keypress nest

Declare the keyascii parameter in chkinp to the same as the keyascii
parameter in the KeyPress Code

so...
Public Sub chkinp(ByVal keyascii As MSForms.ReturnInteger)

ReturnIntereger is actually a class that has a default Integer property
called Value, and since it is an object, the data inside it will get
returned even though you are using ByVal.

Alan

"Garry Jones" wrote in message
...
I received help here on how to check input in a text box and only allow
certain keys to be pressed.

It works, brilliant, now I want to use this as a seperate proceedure and
call it from several text boxes.

How to I send back the correct value from the check to "keypress"

I have tried this
__________________________________________________ ____________________
Private Sub TextBox1_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Private Sub TextBox2_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
chkinp (keyascii)
End Sub
__________________________________________________ ____________________

Public Function chkinp(keyascii) As MSForms.ReturnInteger
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
End Function
__________________________________________________ ____________________

But this does not work, I am missing the exact description of how to
send back the value to the keypress check

Many thanks for any help.

Garry Jones
Sweden



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default Keypress nest

Hi again Garry

This is what classes are for.
Inser a new class module (insert menu). Name the module NumTxt in the
property window. Paste this code into the module:

''' class module text:
Public WithEvents TxtBox As MSForms.TextBox

Private Sub TxtBox_KeyPress(ByVal keyascii As MSForms.ReturnInteger)
Select Case keyascii
Case 8 To 10, 13, 27, 44 'Control characters
Case 48 To 57 'numbers
Case Else 'Discard anything else
keyascii = 0
End Select
End Sub

'''end class text

Now in your userform code:

''' Userform code:

Option Explicit

Dim Num1 As New NumTxt
Dim Num2 As New NumTxt

Private Sub UserForm_Initialize()
Set Num1.TxtBox = Me.TextBox1
Set Num2.TxtBox = Me.TextBox2
End Sub

'' end userform code

and that's it .
--
HTH. Best wishes Harald
Followup to newsgroup only please

"Garry Jones" skrev i melding
...
I received help here on how to check input in a text box and only allow
certain keys to be pressed.

It works, brilliant, now I want to use this as a seperate proceedure and
call it from several text boxes.

How to I send back the correct value from the check to "keypress"





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Nest IF....maybe? IF/AND?? Leigh Excel Discussion (Misc queries) 6 December 13th 07 11:03 PM
NEST A IF WITHIN A IF Karine Excel Worksheet Functions 4 November 27th 07 10:11 PM
Which cell was the activecell before a keypress excelent Excel Worksheet Functions 2 May 26th 06 01:45 PM
keypress Garry Jones Excel Programming 2 October 17th 03 09:47 AM
KeyPress Event Conrado Capistrano Excel Programming 4 September 25th 03 05:27 AM


All times are GMT +1. The time now is 03:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"