Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of Keypress, Keyascii and the ESC key

Status
Not open for further replies.

thetmd

Technical User
Nov 24, 2008
2
IT
Hi there, i'm a newbe of the site, have tryed to look for something similar to my questions but haven't had any luck, so here it is:

1) what kind of code i should write to interrupt a do-loop by pressing the ESC key?

2) may someone teach me why in the sub (of a text box)
Private Sub txtboxPOSTPONI_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii = 32 Then KeyAscii = 95
End Sub
if i press the space key (ascii 32) it's converted automatically in the text box in underscore (ascii 95)?. I mean the value is passed to the procedure 'BYVAL', so i presume it shouldn't change the character in the textbox, Hope to have explained the wuestions well :p

Thanks
Pierpaolo

 
...so i presume it shouldn't change the character in the textbox"

ByVal means VALUE as opposed to ByRef which is a reference. So why did you expect the textbox NOT to change?

On question 1, why do you need to interrupt a loop? ie what is the functional requirement?

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Oh, i've understood, reading a book about VB6, that byval, since is only the value and not the reference to the memory, isn't able to tecnically change the memory value, i think i've to undertsood it better :p, may you make me a lesson about the difference between BYVAL and BYREF?

The second: i've a do-loop that may long as the user want, so i can't program it to last, for istance, 10 or 20 cycles. I've thought that i keypress would help me.

Pier
 

thetmd, try this.
Place a command button on the Form and paste this code:
Code:
Option Explicit

Private Sub Command1_Click()
Dim intX As Integer

intX = 5
Call MyFunct(intX)
MsgBox intX

End Sub

Private Function MyFunct([blue]ByRef[/blue] intMyInteger As Integer) As Integer

intMyInteger = intMyInteger * 5
MyFunct = intMyInteger

End Function
Run it, then change blue [blue][tt]ByRef[/tt][/blue] to [tt]ByVal[/tt] and see what happens.

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top