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:
[imgnothumb]http://bytes.com/attachments/attachment/6014d1328002982/intellisense-msgbox-example-1.jpg[/imgnothumb]
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:
[imgnothumb]http://bytes.com/attachments/attachment/6015d1328002982/intellisense-msgbox-example-2.jpg[/imgnothumb]
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:
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:
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:
[imgnothumb]http://bytes.com/attachments/attachment/6016d1328004329/intellisense-custommessagebo x.jpg[/imgnothumb]
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.
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:
[imgnothumb]http://bytes.com/attachments/attachment/6014d1328002982/intellisense-msgbox-example-1.jpg[/imgnothumb]
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:
[imgnothumb]http://bytes.com/attachments/attachment/6015d1328002982/intellisense-msgbox-example-2.jpg[/imgnothumb]
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:
Code:
Public Enum cmDisplayImage
cmNoImage = 0
cmCritical = 16
cmExclamation = 48
cmInformation = 64
End Enum
Then when I write my function, I specify the parameter type to be of cmDisplayImage as shown below:
Code:
Public Function CustomMessageBox(strCaption As String, Optional cmImage As cmDisplayImage = cmNoImage) As Integer
When I use it, it looks like this:
[imgnothumb]http://bytes.com/attachments/attachment/6016d1328004329/intellisense-custommessagebo x.jpg[/imgnothumb]
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.
Comment