473,473 Members | 2,232 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Expand intellisense to your custom function

TheSmileyCoder
2,322 Recognized Expert Moderator Top Contributor
Now I am quite sure that any of you who have programmed in the VBA editor is absolutely in love with the intellisense, and how it can help you write code faster and how it can help you remember what values are acceptable for the function.

For those not familiar with what Intellisense is:
Intellisense is the feature that detects what you are typing and suggests AutoCompletion, as well as lists the number and type of arguments and whether they are optional and have a default value.

I think the example most of us are probably familiar with is the msgbox. If you for example start to type msgbox in your code, or in the immediate pane you will see the following:


The example shows that you are currently working on the Promt parameter of the msgbox function. If you are familier with reading the display, you will see that Promt is not optional but the remaining parameters are (Since they are enclosed in square brackets []. You will also see that the next parameter is of type vbMsgBoxStyle and it has a default value vbOkOnly.

If you type a "," you will proceed to working/writing the next paramater Buttons. Neatly enough the VBA editor will show a dropdown of the acceptable values, as shown below:


If you start typing the editor will highlight the first acceptable option that matches what you have allready typed.


Creating your own intellisense:
Now if you write a simple function you will still see most of the information that you see in the first of the above msgbox examples. But if you also want to provide the coder (or yourself) with the list of acceptable values, you can even do that too.

First we need to create an Enumeration which we do in a seperate module:
Expand|Select|Wrap|Line Numbers
  1. Public Enum cmDisplayImage
  2.     cmNoImage = 0
  3.     cmCritical = 16
  4.     cmExclamation = 48
  5.     cmInformation = 64
  6. End Enum
Info: The example provided is me working on a custom messagebox, therefore I have prefixed both the enumeration and the constants with cm for Custom Messagebox.

Then when I write my function, I specify the parameter type to be of cmDisplayImage as shown below:
Expand|Select|Wrap|Line Numbers
  1. Public Function CustomMessageBox(strCaption As String, Optional cmImage As cmDisplayImage = cmNoImage) As Integer
I have specified that the second parameter should be of type cmDisplayImage and it has a default value saying no image.

When I use it, it looks like this:


If you have any questions please don't hesitate to ask. If you have question about the actual text of this article please post/reply here. If you have questions about implementing it yourself, I suggest you start a new seperate Question and link to this article.
Attached Images
File Type: jpg Intellisense msgbox Example 1.jpg (9.2 KB, 1708 views)
File Type: jpg Intellisense msgbox Example 2.jpg (17.5 KB, 1658 views)
File Type: jpg Intellisense CustomMessageBox.jpg (13.0 KB, 1618 views)
Jan 31 '12 #1
2 6327
jimatqsi
1,271 Recognized Expert Top Contributor
Thank you. I really need to put public enumerations to work for me.
Apr 27 '14 #2
Seth Schrock
2,965 Recognized Expert Specialist
Wow, this is extremely helpful. I didn't know that you could do that. So if you declare a parameter as the name of an enum, what data type is that?

And thank-you Jim for posting to it so that I would notice the article.
Apr 29 '14 #3

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

Similar topics

2
by: Nick Kafenzakis | last post by:
Hi, I am thinking about creating some custom server controls in Visual Studio .NET 2003 using VB.NET. One thing I am wondering about is how I can get the control to show up in the IDE....for...
19
by: Deniz Bahar | last post by:
Hi, I would like to call one of my functions the exact name as an existing C library function (for example K&R2 exercises asks me to make an atof function). If I don't include the header with...
16
by: Nikolay Petrov | last post by:
How can I return multiple values from a custom function? TIA
0
by: ad | last post by:
I used the new TableAdapter feature of VS2005. I want to create a complex calculated column when I desgin a DataTable in a typed dataset. The defined function like convert, len, isnull... in not...
17
by: sanniep | last post by:
Hello Experts, I would like to make a custom function Second() for Access in VB. This function should return the second value from a field like the function First gives the first value. This...
2
by: cefrancke | last post by:
Is there a way to capture all relevant info about the mouse, without using Mouse Up/Down etc. procedures? I'm trying to make a custom function and send it the mouse info on the click event. ...
1
by: ArunDhaJ | last post by:
Hi, Can we write custom function to filter rows from DataTable Select method? Actually my need is to format the row value from (901) 789 1234<BR>(901) 789 1235<BR>(901) 789 1221 to...
1
by: sachinkale123 | last post by:
Hi I working on a application which is recording open and close connections time. Now I want to call my custom function which will write data in to database as soon as connection is closed. I...
5
dsatino
by: dsatino | last post by:
I have an Access query whose results are filtered by a custom VBA function. This works perfectly as long as the function returns a result. If the function doesn't return a result, neither does the...
0
TheSmileyCoder
by: TheSmileyCoder | last post by:
Often times people ask for help with something, that requires the use of a custom written function. The experts (or others) of this site take the time to write just such a function, only to spend...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.