473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Clarifying Questions

hyperpau
184 Expert 100+
I just have some stupid questions but really want to know to fully understand vba more.


What are the arguments for in some of the events?

For example, the click event has the arguments (Shift As Integer, Cancel as Integer)


Then the DblClick event have (Cancel as Integer)

what are these for? specifically about these events. I am just curious as to why these appears although I do not use these variables in any of my procedures when I call these events.

The only argument I understand is the response in the NotInList event.

(Response As Integer) since I use it in the code as
Response = DataErrContinue


but regarding Shift and Cancel as Integer, what are these for?

where can I use them? does that mean the shift key? what about the Cancel argument?


Hope somebody can help me clear things up.
Sep 19 '07 #1
5 3776
FishVal
2,653 Expert 2GB
Hi, hyperpau.

It depends on particular event.
Usually
Shift - represents Ctrl/Alt/Shift buttons state
Cancel - ByRef variable used to tell to the object that has raised the event whether to perform default action or no.
e.g.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text0_BeforeUpdate(Cancel As Integer)
  2.     If IsNull(Me.Text0) Then Cancel = True
  3. End Sub
  4.  
This will tell Text0 object than update must be cancelled.

I recommend you to use object browser to get help on particular object events.

Regards,
Fish
Sep 19 '07 #2
hyperpau
184 Expert 100+
Wow. thanks.
gives me more interest though.
I am very curious about the Shift.

Does this mean I can call different procedures depending on the key combination pressed with the mouse click?

if yes, please give me an example code.

let's say call a different message box when a button is clicked, then another message box when the button is clicked with the Shift, Ctl or Alt key.

please?.. :) Thanks in advance.


Hi, hyperpau.

It depends on particular event.
Usually
Shift - represents Ctrl/Alt/Shift buttons state
Cancel - ByRef variable used to tell to the object that has raised the event whether to perform default action or no.
e.g.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Text0_BeforeUpdate(Cancel As Integer)
  2. If IsNull(Me.Text0) Then Cancel = True
  3. End Sub
  4.  
This will tell Text0 object than update must be cancelled.

I recommend you to use object browser to get help on particular object events.

Regards,
Fish
Sep 19 '07 #3
FishVal
2,653 Expert 2GB
Wow. thanks.
gives me more interest though.
I am very curious about the Shift.

Does this mean I can call different procedures depending on the key combination pressed with the mouse click?

if yes, please give me an example code.

let's say call a different message box when a button is clicked, then another message box when the button is clicked with the Shift, Ctl or Alt key.

please?.. :) Thanks in advance.
Hmm.

Don't know what object raises Click event passing Shift argument.
The following example is for Form_KeyDown event.
Form object passes keyboard state in integer argument "Shift" having the following format.

Expand|Select|Wrap|Line Numbers
  1. Bit#       Set to 1 when pressed
  2. 0            Shift
  3. 1            Ctrl
  4. 2            Alt
  5.  
additionally Access has constants corresponding to keys
acShiftMask = 1
acCtrlMask=2
acAltMask = 4
So to retrieve particular key state you may use bitwise logical operators AND and OR.

e.g.

if Shift AND acShiftMask = 1 Then 'Shift pressed
if Shift AND acCtrlMask = 0 Then 'Ctrl not pressed
if Shift AND (acCtrlMask OR acAltMask) = 1 Then MsgBox "Press DEL and go drink beer"
Sep 19 '07 #4
hyperpau
184 Expert 100+
Wow. very cool.

but what scenarios can we use that Shift in the Click() event?

Hmm.

Don't know what object raises Click event passing Shift argument.
The following example is for Form_KeyDown event.
Form object passes keyboard state in integer argument "Shift" having the following format.

Expand|Select|Wrap|Line Numbers
  1. Bit# Set to 1 when pressed
  2. 0 Shift
  3. 1 Ctrl
  4. 2 Alt
  5.  
additionally Access has constants corresponding to keys
acShiftMask = 1
acCtrlMask=2
acAltMask = 4
So to retrieve particular key state you may use bitwise logical operators AND and OR.

e.g.

if Shift AND acShiftMask = 1 Then 'Shift pressed
if Shift AND acCtrlMask = 0 Then 'Ctrl not pressed
if Shift AND (acCtrlMask OR acAltMask) = 1 Then MsgBox "Press DEL and go drink beer"
Sep 19 '07 #5
FishVal
2,653 Expert 2GB
Wow. very cool.

but what scenarios can we use that Shift in the Click() event?
Hmm.

There is no Click event which passes keyboard state to event handler.
This requires some play around.

The following code distinguish between Click and Ctrl+Click on Listbox.
MouseUp event handler checks whether Ctrl key is pressed, so far ListBox.Value is not yet set to item clicked. Then on Click event when ListBox.Value is set properly, Click event handler checks whether Ctrl key was pressed when mouse button was released. ;)

The form mentioned contains two controls:
Text2: unbound Textbox
List0: Listbox with RowSourceType = ValueList

Expand|Select|Wrap|Line Numbers
  1. Private blnCtrlPressed As Boolean
  2.  
  3. Private Sub CheckKeyboardState(Shift As Integer)
  4.     If (Shift And acCtrlMask) <> 0 Then
  5.         blnCtrlPressed = True
  6.     Else
  7.         blnCtrlPressed = False
  8.     End If
  9. End Sub
  10.  
  11.  
  12. Private Sub List0_Click()
  13.     With Me
  14.         If blnCtrlPressed Then
  15.             .Text2 = "Ctrl + " & .List0
  16.         Else
  17.             .Text2 = .List0
  18.         End If
  19.     End With
  20.  
  21. End Sub
  22.  
  23. Private Sub List0_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  24.     CheckKeyboardState (Shift)
  25. End Sub
  26.  
Sep 20 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: smith flyers | last post by:
static void Main(string what) { string test="testing 1 2 3"; test.Replace("testing", "test"); } // why this doesn't replace the word "testing" ? when using "try" can i use multiple "block...
0
by: softwareengineer2006 | last post by:
All Interview Questions And Answers 10000 Interview Questions And Answers(C,C++,JAVA,DOTNET,Oracle,SAP) I have listed over 10000 interview questions asked in interview/placement test papers for...
0
by: connectrajesh | last post by:
INTERVIEWINFO.NET http://www.interviewinfo.net FREE WEB SITE AND SERVICE FOR JOB SEEKERS /FRESH GRADUATES NO ADVERTISEMENT
10
by: brooksr | last post by:
I know VB5/VBA very well but have not used VB to create web pages but need to do so. Can someone explain the purposes and differences between VBScript and VB.NET to create web pages? Also...
2
by: freepdfforjobs | last post by:
Full eBook with 4000 C#, JAVA,.NET and SQL Server Interview questions http://www.questpond.com/SampleInterviewQuestionBook.zip Download the JAVA , .NET and SQL Server interview sheet and rate...
4
by: Drew | last post by:
I posted this to the asp.db group, but it doesn't look like there is much activity on there, also I noticed that there are a bunch of posts on here pertaining to database and asp. Sorry for...
8
by: Krypto | last post by:
Hi, I have used Python for a couple of projects last year and I found it extremely useful. I could write two middle size projects in 2-3 months (part time). Right now I am a bit rusty and trying...
0
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
1
by: ramu | last post by:
C# Interview Questions and Answers8 http://allinterviewsbooks.blogspot.com/2008/07/c-interview-questions-and-answers8.html C# Interview Questions and Answers7...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.