Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Curious use of ByVal keyword in VBA event

I have a WithEvents combo object in a class and I'm using its KeyPress
events. Here is the line VBA inserted into my code:

Private Sub m_oCombo_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

The KeyAscii variable is actually being passed by reference, of
course, otherwise I wouldn't be able to suppress certain characters.
So why the ByVal keyword? It confused me for a while this morning. Is
it this something to do with ByVal being overloaded e.g. for use in
the Declare keyword?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Curious use of ByVal keyword in VBA event

The MSForms.ReturnInteger is an object type variable, and all objects are
passed by passing the address of the object. The 'ByVal' and 'ByRef'
qualifiers indicate whether the address of the object is passed ByVal or
ByRef. In the KeyPress procedure, the address of KeyAscii is passed ByVal.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com






"onedaywhen" wrote in message
m...
I have a WithEvents combo object in a class and I'm using its KeyPress
events. Here is the line VBA inserted into my code:

Private Sub m_oCombo_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)

The KeyAscii variable is actually being passed by reference, of
course, otherwise I wouldn't be able to suppress certain characters.
So why the ByVal keyword? It confused me for a while this morning. Is
it this something to do with ByVal being overloaded e.g. for use in
the Declare keyword?



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
REPSOT?? Sub Worksheet_Change(ByVal Target As Range) Ed Davis[_2_] Excel Discussion (Misc queries) 14 October 13th 09 03:20 PM
Control Toolbox and Private Sub Worksheet_Change(ByVal Target As R [email protected] Excel Discussion (Misc queries) 1 August 17th 07 09:38 AM
Control Toolbox and Private Sub Worksheet_Change(ByVal Target Toppers Excel Discussion (Misc queries) 0 August 17th 07 01:52 AM
ByVal Target Range Great Code but need Help Mark Excel Discussion (Misc queries) 31 July 27th 07 03:11 PM
Is ByVal always better if ByRef isn't necessary Jeff[_17_] Excel Programming 5 July 25th 03 09:25 AM


All times are GMT +1. The time now is 01:29 AM.

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

About Us

"It's about Microsoft Excel"